preparing mltiple style files

This commit is contained in:
Torsten 2023-01-27 17:17:05 +02:00
parent 6a9e2182aa
commit 1270c59492
5 changed files with 23 additions and 12 deletions

View File

@ -55,7 +55,7 @@ module Merged
size: (magick_image.size/1024).to_i
self.insert(image) # assigns next id
full_filename = image.id.to_s + "." + ending
magick_image.write(Rails.root.join("app/assets/images/cms/", full_filename))
magick_image.write(Rails.root.join(Image.asset_root, full_filename))
image
end
@ -70,7 +70,7 @@ module Merged
def full_filename
full_filename = self.id.to_s + "." + self.type
Rails.root.join(asset_root, full_filename)
Rails.root.join(Image.asset_root, full_filename)
end
def self.transform
@ -98,13 +98,12 @@ module Merged
self.size = (magick_image.size/1024).to_i
end
private
def asset_root
"app/assets/images/" + image_root
def self.asset_root
"app/assets/images/" + Merged.images_dir
end
def image_root
"cms"
Merged.images_dir
end
end

View File

@ -1,6 +1,5 @@
module Merged
class OptionDefinition < ActiveBase
set_root_path Engine.root + "config"
class OptionDefinition < SharedBase
fields :name , :default , :description , :values , :type

View File

@ -0,0 +1,15 @@
module Merged
# shared data across engine and app
# takes a little footwork, as seen below
class SharedBase < ActiveYaml::Base
def self.raw_data
paths = [ Merged::Engine.root.join("config")]
loaded_files = paths.collect do |path|
actual_filename = filename || name.tableize
full = File.join(path, "#{actual_filename}.#{extension}")
load_path(full)
end
loaded_files.sum
end
end
end

View File

@ -1,7 +1,5 @@
module Merged
class Style < ActiveBase
set_root_path Engine.root + "config"
class Style < SharedBase
fields :options

View File

@ -5,7 +5,7 @@ module Merged
# and the fact that they persist in ActiveYaml
class ViewBase < ActiveBase
set_root_path Rails.root #ouside engines not necessary
set_root_path Merged.data_dir
include ActiveHash::Associations
belongs_to :image , class_name: "Merged::Image"