multi source style loading

This commit is contained in:
Torsten 2023-01-27 19:08:57 +02:00
parent 1270c59492
commit df67ed16b5
26 changed files with 37 additions and 33 deletions

View File

@ -15,7 +15,7 @@ module Merged
else
git = Git.open(Rails.root)
git.add("merged")
git.add( Image.root )
git.add( Image.asset_root )
begin
git.config('user.email', current_member.email)
git.commit(params[:message])
@ -30,8 +30,8 @@ module Merged
def reset
git = Git.open(Rails.root)
begin
git.checkout_file("HEAD" , "merged")
git.checkout_file("HEAD" , "app/assets/images/cms")
git.checkout_file("HEAD" , Merged.data_dir)
git.checkout_file("HEAD" , Merged::Image.asset_root)
ChangeSet.current.zero
message = "Changes reset"
rescue

View File

@ -2,8 +2,8 @@ module Merged
module ChangesHelper
def cms_part? name
return true if name.include?( Image.root )
return true if name.include?("merged/")
return true if name.include?( Merged.images_dir )
return true if name.include?(Merged.data_dir)
false
end

View File

@ -65,7 +65,7 @@ module Merged
end
def asset_name
image_root + "/" + self.id.to_s + "." + self.type
Merged.images_dir + "/" + self.id.to_s + "." + self.type
end
def full_filename
@ -87,10 +87,6 @@ module Merged
end
end
def self.root
"app/assets/images/cms"
end
def init_file_size
magick_image = MiniMagick::Image.open(full_filename)
self.width = magick_image.width
@ -102,9 +98,5 @@ module Merged
"app/assets/images/" + Merged.images_dir
end
def image_root
Merged.images_dir
end
end
end

View File

@ -3,11 +3,13 @@ module Merged
# takes a little footwork, as seen below
class SharedBase < ActiveYaml::Base
def self.raw_data
paths = [ Merged::Engine.root.join("config")]
paths = [ Merged::Engine.root.join("config") , Rails.root.join(Merged.data_dir) ]
loaded_files = paths.collect do |path|
actual_filename = filename || name.tableize
full = File.join(path, "#{actual_filename}.#{extension}")
load_path(full)
got = load_path(full)
raise "#{full} contained #{got.class}, not Array" unless got.class == Array
got
end
loaded_files.sum
end

View File

@ -1 +1 @@
---[]
--- []

View File

@ -1,7 +1,9 @@
require "merged"
# directory inside /app/assets/images where the images are kept
Merged.images_dir = "cms"
# directory inside /app/assets/images where YOUR images are kept
# if you change this and add own styles, you will still need a merged directory
# for the previews (card_preview and section_preview)
Merged.images_dir = "merged"
# directory where data and styles are kept
# Notice that the data is ALWAYS inside a merged directory,

View File

@ -7,21 +7,8 @@ module Merged
# Directory inside the app/assets/images
mattr_accessor :images_dir
@@images_dir = "cms"
# directory in root to store data
mattr_accessor :data_dir
@@data_dir = "."
def self.load_data
# pre-load data
[OptionDefinition, CardStyle, SectionStyle , PageStyle,
Card , Section , Page , Image].each {|clazz| clazz.all }
end
def self.load_from( kind , path )
return unless File.exists?(path)
clazz = "Merged::#{kind.camelcase}".constantize
clazz.load(YAML.load_file( path ))
end
end

View File

@ -20,7 +20,7 @@ module Merged
initializer "after_initialize" do |app|
ActiveSupport::Reloader.to_prepare do
Merged.load_data
Merged::Engine.load_data
end
end
@ -32,5 +32,17 @@ module Merged
config.assets.precompile << kid
end
end
def self.load_data
# pre-load data
[OptionDefinition, CardStyle, SectionStyle , PageStyle,
Card , Section , Page , Image].each {|clazz| clazz.all }
end
def self.load_from( kind , path )
return unless File.exists?(path)
clazz = "Merged::#{kind.camelcase}".constantize
clazz.load(YAML.load_file( path ))
end
end
end

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 260 KiB

View File

Before

Width:  |  Height:  |  Size: 211 KiB

After

Width:  |  Height:  |  Size: 211 KiB

View File

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 129 KiB

View File

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 246 KiB

View File

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 137 KiB

View File

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 137 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 372 KiB

After

Width:  |  Height:  |  Size: 372 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 135 KiB

View File

@ -0,0 +1,9 @@
require "merged"
# directory inside /app/assets/images where the images are kept
Merged.images_dir = "merged"
# directory where data and styles are kept
# Notice that the data is ALWAYS inside a merged directory,
# so in the default case Rails.root/merged/*.yml
Merged.data_dir = "."