diff --git a/app/models/merged/card_style.rb b/app/models/merged/card_style.rb new file mode 100644 index 0000000..b1d077d --- /dev/null +++ b/app/models/merged/card_style.rb @@ -0,0 +1,42 @@ +module Merged + class CardStyle + @@cards = {} + + attr_reader :content + + def initialize content + @content = content + end + + [:template , :text , :header, :fields ].each do |meth| + define_method(meth) do + @content[meth.to_s] + end + end + + def card_preview + "merged/card_preview/" + template + end + + def options + option_defs = [] + @content["options"].each do |name| + option = Option.options[name] + raise "no option for #{name}:#{name.class}" if option.blank? + option_defs << option + end if @content["options"] + option_defs + end + + def self.cards + @@cards + end + + def self.load( yaml ) + yaml.each do |content| + card = CardStyle.new(content) + @@cards[card.template] = card + end + end + end +end diff --git a/app/models/merged/option.rb b/app/models/merged/option.rb index d2f97f4..754ace5 100644 --- a/app/models/merged/option.rb +++ b/app/models/merged/option.rb @@ -8,9 +8,11 @@ module Merged @default = options["default"] @description = options["description"] @values = options["values"] + @type = options["type"] end def type + return @type unless @type.blank? if has_values? "select" else @@ -27,5 +29,13 @@ module Merged return [] unless has_values? @values.split(" ") end + + def self.load(yaml) + yaml.each do |content| + option = Option.new(content) + @@options[option.name] = option + end + end + end end diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index ff57ec1..5d014ba 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -111,8 +111,8 @@ module Merged end def save - file_name = Rails.root.join(Page.cms_root , name + ".yaml") - File.write( file_name , @content.to_yaml) + File.write( filename , @content.to_yaml) + update_size end def self.find(name) diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index 989e7b1..3972d5c 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -35,7 +35,7 @@ module Merged def set_template(new_template) @content["template"] = new_template new_style = template_style - if(new_style.cards?) + if(new_style.has_cards?) unless card_template @content["card_template"] = Style.cards.keys.first @content["cards"] = [] @@ -56,7 +56,7 @@ module Merged template_style.fields end - def cards? + def has_cards? ! card_template.blank? end @@ -151,7 +151,7 @@ module Merged style.fields.each do |key| data[key] = key.upcase end unless style.fields.blank? - if(style.cards?) + if(style.has_cards?) data["cards"] = [] data["card_template"] = Style.cards.keys.first end diff --git a/app/models/merged/section_style.rb b/app/models/merged/section_style.rb new file mode 100644 index 0000000..ec0e71b --- /dev/null +++ b/app/models/merged/section_style.rb @@ -0,0 +1,26 @@ +module Merged + class SectionStyle < CardStyle + + @@sections = {} + + def has_cards? + @content["cards"] == true + end + + def section_preview + "merged/section_preview/" + template + end + + def self.sections + @@sections + end + + def self.load(yaml) + yaml.each do |content| + section = SectionStyle.new(content) + @@sections[section.template] = section + end + end + + end +end diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb deleted file mode 100644 index ea1eb1c..0000000 --- a/app/models/merged/style.rb +++ /dev/null @@ -1,75 +0,0 @@ -module Merged - class Style - include ActiveModel::API - - @@options ={} - @@sections = {} - @@cards = {} - - attr_reader :content - - def initialize content - @content = content - end - - [:template , :text , :header, :fields ].each do |meth| - define_method(meth) do - @content[meth.to_s] - end - end - - def cards? - @content["cards"] == true - end - def section_preview - "merged/section_preview/" + template - end - def card_preview - "merged/card_preview/" + template - end - - def options - option_defs = [] - @content["options"].each do |name| - option = Style.options[name] - raise "no option for #{name}:#{name.class}" if option.blank? - option_defs << option - end if @content["options"] - option_defs - end - - def self.cards - self.load - @@cards - end - - def self.options - self.load - @@options - end - - def self.sections - self.load - @@sections - end - - def self.load - if @@sections.length == 0 or Rails.env.development? - all = YAML.load_file(Engine.root.join("config/styles.yaml")) - all["sections"].each do |content| - section = Style.new(content) - @@sections[section.template] = section - end - all["cards"].each do |content| - card = Style.new(content) - @@cards[card.template] = card - end - all["options"].each do |content| - option = Option.new(content) - @@options[option.name] = option - end - end - end - - end -end diff --git a/config/merged/card_style.yaml b/config/merged/card_style.yaml new file mode 100644 index 0000000..0343a14 --- /dev/null +++ b/config/merged/card_style.yaml @@ -0,0 +1,41 @@ +--- +- template: card_full_image + header: Full background + text: With text in bottom right corner, offset with solid color + fields: + - header + - text + options: + - background + - color + - align +- template: card_gap_square + header: Narrow card with up down section + text: Smaller image, large margins, possible subheader + Order turns it upside down, image bottom + fields: + - header + - text + options: + - background + - color + - order + - align + - subheader +- template: card_normal_square + header: Standard card with square image + text: Image, header, text, normal stuff + fields: + - header + - text + options: + - background + - color + - align + - subheader +- template: card_normal_round + header: Standard card with square image + text: Image, header, text, normal stuff + fields: + - header + - text diff --git a/config/merged/options.yaml b/config/merged/options.yaml new file mode 100644 index 0000000..e485193 --- /dev/null +++ b/config/merged/options.yaml @@ -0,0 +1,69 @@ +--- +- name: fixed + desciption: + Paralax effect where background stays fixed + during scrolling + values: on off + default: off +- name: columns + desciption: + Number of columns in a layout that supports cards + values: 2 3 4 + default: 3 +- name: background + desciption: + Background colors. Light colors stay with black text. + Solid colors invert to white text. + values: white none light_blue light_gray light_orange solid_blue solid_red solid_indigo + default: none +- name: color + desciption: + Text colors. Don't use with solid background colors. + Same colors as background available. Default none, meas as parent. + values: none white black light_blue light_gray solid_black solid_blue solid_red solid_indigo + default: none +- name: shade_color + desciption: + Color of transparent shaded area. + The number means transparency. + values: none black_25 white_25 light_red_25 light_blue_25 solid_blue_25 solid_red_25 + default: none +- name: align + desciption: + Align text of children. Normal Word meaning + values: left center right + default: left +- name: order + desciption: + For two column layout determine order of sub-cards + Values of left and right usually refer to where the image is + For cards it can also mean up and down + values: left right + default: left +- name: margin + desciption: + Most sections have standard margin of 20. + This option makes it possible to remove that + values: 0 20 + default: 20 +- name: button_text + desciption: + Text for an optional button. Must also set button_link + values: + default: +- name: subheader + desciption: + Smaller header between Header and text + values: + default: +- name: text + desciption: + Second text. Just a second paragraph + values: + default: +- name: button_link + desciption: + Link for an option button. Must also set button_text. + Link must be a page name, ie only internal links allowed. + values: + default: diff --git a/config/merged/section_style.yaml b/config/merged/section_style.yaml new file mode 100644 index 0000000..0b543fc --- /dev/null +++ b/config/merged/section_style.yaml @@ -0,0 +1,75 @@ +--- +- template: section_cards + header: Two or more column layout with header + text: A header with text and two column layout. Columns have a little gap, so + background color comes through. 2,3 or 4 columns. Cards freely choosable + cards: true + fields: + - header + - text + options: + - background + - columns + - color +- template: section_full_up + header: Centered Header with text + text: Full width header with centered headline and optional text + fields: + - header + - text + options: + - background + - color + - margin + - subheader + - button_link + - button_text +- template: section_half_image + header: Split section with image left or right + text: Image on one side, header and text on the other. + Order depends on order option. Optional button. + fields: + - header + - text + options: + - order + - background + - color + - subheader + - text + - align + - button_link + - button_text +- template: section_full_image + header: Full image header with adjustable text + text: Large picture background with Header and text on top. + Adjustable alignment (left, center, right). + Text may be slightly shaded for readability, + text color can be changed too. + fields: + - header + - text + options: + - fixed + - color + - align + - shade_color +- template: section_large_image + header: Two third image header with adjustable text + text: Large picture background with Header and text offset. + Adjustable alignment (left, center, right). + Text section may have background color. + Text color can be changed too + fields: + - header + - text + options: + - subheader + - margin + - order + - color + - background +- template: section_spacer + header: Spacer + text: Just for extra padding + fields: diff --git a/lib/merged/engine.rb b/lib/merged/engine.rb index 81efeb6..5d7a9af 100644 --- a/lib/merged/engine.rb +++ b/lib/merged/engine.rb @@ -9,8 +9,7 @@ module Merged initializer "after_initialize" do |app| ActiveSupport::Reloader.to_prepare do - Merged::Page.load_pages() - Image.load_images() + Merged.load_data end end diff --git a/spec/models/merged/card_style_spec.rb b/spec/models/merged/card_style_spec.rb new file mode 100644 index 0000000..8015e13 --- /dev/null +++ b/spec/models/merged/card_style_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +module Merged + RSpec.describe CardStyle, type: :model do + let(:first_card) {Style.cards.first} + + it "has Style.cards" do + expect(CardStyle.cards.class).to be Hash + expect(CardStyle.cards.length).to be 4 + end + + end +end diff --git a/spec/models/merged/section_style_spec.rb b/spec/models/merged/section_style_spec.rb new file mode 100644 index 0000000..8bf58e7 --- /dev/null +++ b/spec/models/merged/section_style_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +module Merged + RSpec.describe SectionStyle, type: :model do + let(:first_section) {SectionStyle.sections.first} + + it "has Style.sections" do + expect(SectionStyle.sections.class).to be Hash + expect(SectionStyle.sections.length).to be 6 + end + it "Finds section by template" do + spacer = SectionStyle.sections["section_spacer"] + expect(spacer).not_to eq nil + end + it "Spacer has no fields" do + spacer = SectionStyle.sections["section_spacer"] + expect(spacer.fields).to be nil + end + + end +end diff --git a/spec/models/merged/style_spec.rb b/spec/models/merged/style_spec.rb deleted file mode 100644 index b578ce7..0000000 --- a/spec/models/merged/style_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'rails_helper' - -module Merged - RSpec.describe Style, type: :model do - let(:first_section) {Style.sections.first} - let(:first_card) {Style.cards.first} - - it "has Style.sections" do - expect(Style.sections.class).to be Hash - expect(Style.sections.length).to be 6 - end - it "has Style.cards" do - expect(Style.cards.class).to be Hash - expect(Style.cards.length).to be 1 - end - it "Finds section by template" do - spacer = Style.sections["section_spacer"] - expect(spacer).not_to eq nil - end - it "Spacer has no fields" do - spacer = Style.sections["section_spacer"] - expect(spacer.fields).to be nil - end - it "2 col has fields" do - spacer = Style.sections["section_cards"] - expect(spacer.fields.class).to be Array - expect(spacer.fields.length).to be 2 - end - - end -end