diff --git a/app/models/merged/image.rb b/app/models/merged/image.rb index 6db6aab..f055e68 100644 --- a/app/models/merged/image.rb +++ b/app/models/merged/image.rb @@ -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 diff --git a/app/models/merged/option_definition.rb b/app/models/merged/option_definition.rb index 90ab6ac..a4239bd 100644 --- a/app/models/merged/option_definition.rb +++ b/app/models/merged/option_definition.rb @@ -1,6 +1,5 @@ module Merged - class OptionDefinition < ActiveBase - set_root_path Engine.root + "config" + class OptionDefinition < SharedBase fields :name , :default , :description , :values , :type diff --git a/app/models/merged/shared_base.rb b/app/models/merged/shared_base.rb new file mode 100644 index 0000000..8841b23 --- /dev/null +++ b/app/models/merged/shared_base.rb @@ -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 diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb index 36d948c..482b8e4 100644 --- a/app/models/merged/style.rb +++ b/app/models/merged/style.rb @@ -1,7 +1,5 @@ module Merged - class Style < ActiveBase - - set_root_path Engine.root + "config" + class Style < SharedBase fields :options diff --git a/app/models/merged/view_base.rb b/app/models/merged/view_base.rb index dccac53..b659daa 100644 --- a/app/models/merged/view_base.rb +++ b/app/models/merged/view_base.rb @@ -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"