diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 6a5fa44..2bcc196 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -2,6 +2,7 @@ require "redcarpet" module Merged module MergedHelper + include OptionsHelper @@renderer = nil def renderer diff --git a/app/helpers/merged/sections_helper.rb b/app/helpers/merged/sections_helper.rb index bba2eaa..3ded82d 100644 --- a/app/helpers/merged/sections_helper.rb +++ b/app/helpers/merged/sections_helper.rb @@ -1,6 +1,7 @@ module Merged module SectionsHelper - + include ViewHelper #for previews + def section_form(options) url = section_url( @section.id) form_tag( url , {method: :patch}) do diff --git a/app/models/merged/card.rb b/app/models/merged/card.rb index 7426c2b..0846050 100644 --- a/app/models/merged/card.rb +++ b/app/models/merged/card.rb @@ -54,6 +54,11 @@ module Merged def save section.save end + def save_soon + super + data = Option.all.collect {|obj| obj.attributes} + File.write( Option.full_path , data.to_yaml) + end def set_index(index) @index = index diff --git a/app/models/merged/card_style.rb b/app/models/merged/card_style.rb index b1d077d..92f1e2d 100644 --- a/app/models/merged/card_style.rb +++ b/app/models/merged/card_style.rb @@ -21,7 +21,7 @@ module Merged def options option_defs = [] @content["options"].each do |name| - option = Option.options[name] + option = Option.find_by_name(name) raise "no option for #{name}:#{name.class}" if option.blank? option_defs << option end if @content["options"] diff --git a/app/models/merged/option.rb b/app/models/merged/option.rb index 9abdf13..894aa96 100644 --- a/app/models/merged/option.rb +++ b/app/models/merged/option.rb @@ -1,20 +1,11 @@ module Merged class Option < ActiveYaml::Base - - @@options = {} + set_root_path Engine.root + "config" fields :name , :default , :description , :values , :type - def initialize_old(options) - @name = options["name"] - @default = options["default"] - @description = options["description"] - @values = options["values"] - @type = options["type"] - end - def type - return @type unless @type.blank? + return attributes[:type] unless attributes[:type].blank? if has_values? "select" else @@ -23,24 +14,17 @@ module Merged end def has_values? - return false if @values.nil? - ! @values.empty? + return false if attributes[:values].nil? + ! attributes[:values].empty? end def values return [] unless has_values? - @values.split(" ") + attributes[:values].split(" ") end - def self.options - @@options - end - - def self.load(yaml) - yaml.each do |content| - option = Option.new(content) - @@options[option.name] = option - end + def self.load() + self.all end end diff --git a/config/initializers/active_file.rb b/config/initializers/active_file.rb index 4ad1d39..e69de29 100644 --- a/config/initializers/active_file.rb +++ b/config/initializers/active_file.rb @@ -1 +0,0 @@ -ActiveFile::Base.set_root_path "config" diff --git a/config/merged/options.yml b/config/merged/options.yml index 1175219..80e29d8 100644 --- a/config/merged/options.yml +++ b/config/merged/options.yml @@ -1,90 +1,89 @@ --- -- name: fixed - description: - Paralax effect where background stays fixed - during scrolling - values: on off - default: off -- name: columns - description: - Number of columns in a layout that supports cards - values: 2 3 4 - default: 3 -- name: background - description: - 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 - description: - 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 - description: - 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 - description: - Align text of children. Normal Word meaning - values: left center right - default: left -- name: order - description: - 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 - description: - Most sections have standard margin of 20. - This option makes it possible to remove that - values: 0 20 - default: 20 -- name: button_text - description: - Text for an optional button. Must also set button_link - values: - default: -- name: subheader - description: - Smaller header between Header and text - values: - default: -- name: text - description: - Second text. Just a second paragraph - values: - default: -- name: button_link - description: - Link for an option button. Must also set button_text. - Link must be a page name, ie only internal links allowed. - values: - default: -- name: compulsory - description: - Form fields may be compulsory or not. By default they are. - values: yes no - default: no -- name: form_type - description: - Form fields may have a type for special handling. The default is text +- :name: fixed + :description: Paralax effect where background stays fixed during scrolling + :values: on off + :default: false + :id: 1 +- :name: columns + :description: Number of columns in a layout that supports cards + :values: 2 3 4 + :default: 3 + :id: 2 +- :name: background + :description: 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 + :id: 3 +- :name: color + :description: 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 + :id: 4 +- :name: shade_color + :description: 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 + :id: 5 +- :name: align + :description: Align text of children. Normal Word meaning + :values: left center right + :default: left + :id: 6 +- :name: order + :description: 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 + :id: 7 +- :name: margin + :description: Most sections have standard margin of 20. This option makes it possible + to remove that + :values: 0 20 + :default: 20 + :id: 8 +- :name: button_text + :description: Text for an optional button. Must also set button_link + :values: + :default: + :id: 9 +- :name: subheader + :description: Smaller header between Header and text + :values: + :default: + :id: 10 +- :name: text + :description: Second text. Just a second paragraph + :values: + :default: + :id: 11 +- :name: button_link + :description: Link for an option button. Must also set button_text. Link must be + a page name, ie only internal links allowed. + :values: + :default: + :id: 12 +- :name: compulsory + :description: Form fields may be compulsory or not. By default they are. + :values: yes no + :default: false + :id: 13 +- :name: form_type + :description: Form fields may have a type for special handling. The default is text but message would be a longer text, and email checked to be a name. - values: text message email phone date - default: text -- name: ok_message - description: - Message shown to the user when a form was submitted - values: - default: -- name: handler - description: - Form handler - values: FormHandler - default: FormHandler + :values: text message email phone date + :default: text + :id: 14 +- :name: ok_message + :description: Message shown to the user when a form was submitted + :values: + :default: + :id: 15 +- :name: handler + :description: Form handler + :values: FormHandler + :default: FormHandler + :id: 16 diff --git a/lib/merged.rb b/lib/merged.rb index 79f7b88..baba471 100644 --- a/lib/merged.rb +++ b/lib/merged.rb @@ -4,10 +4,11 @@ require "merged/engine" module Merged def self.load_data - ["card_style" , "section_style" , "option"].each do |kind| + ["card_style" , "section_style"].each do |kind| # loading egine definitions first, can be overriden load_from kind , Engine.root.join("config/merged/#{kind}.yaml") end + Option.load Page.load_pages Image.load_images end diff --git a/spec/features/merged/changes_spec.rb b/spec/features/merged/changes_spec.rb index 0712ff6..c625c96 100644 --- a/spec/features/merged/changes_spec.rb +++ b/spec/features/merged/changes_spec.rb @@ -3,9 +3,9 @@ require 'rails_helper' RSpec.feature "Changes", type: :feature do describe "GET /changes" do it "returns http success" do - visit "/merged/changes" - expect(page).to have_title("Merged") - expect(page).to have_text("Pages") + visit "/merged/changes/index" + expect(page).to have_title("Deletions") + expect(page).to have_text("Additions") end end end diff --git a/spec/models/merged/card_style_spec.rb b/spec/models/merged/card_style_spec.rb index 8015e13..97bcd63 100644 --- a/spec/models/merged/card_style_spec.rb +++ b/spec/models/merged/card_style_spec.rb @@ -6,7 +6,7 @@ module Merged it "has Style.cards" do expect(CardStyle.cards.class).to be Hash - expect(CardStyle.cards.length).to be 4 + expect(CardStyle.cards.length).to be 5 end end diff --git a/spec/models/merged/option_spec.rb b/spec/models/merged/option_spec.rb index b69b7bf..70e4f88 100644 --- a/spec/models/merged/option_spec.rb +++ b/spec/models/merged/option_spec.rb @@ -2,16 +2,19 @@ require 'rails_helper' module Merged RSpec.describe Option, type: :model do - let(:first) {Option.options.values.first} + let(:first) {Option.first} - it "has Option.options" do - expect(Option.options.class).to be Hash + it "has Option.first" do + expect(Option.first.class).to be Option end it "there are options" do - expect(Option.options.length).to be 16 + expect(Option.all.length).to be 16 end it "has option objects" do expect(first.class).to be Option end + it "has values" do + expect(first.values.class).to be Array + end end end diff --git a/spec/models/merged/section_style_spec.rb b/spec/models/merged/section_style_spec.rb index 8bf58e7..3d3c130 100644 --- a/spec/models/merged/section_style_spec.rb +++ b/spec/models/merged/section_style_spec.rb @@ -6,7 +6,7 @@ module Merged it "has Style.sections" do expect(SectionStyle.sections.class).to be Hash - expect(SectionStyle.sections.length).to be 6 + expect(SectionStyle.sections.length).to be 7 end it "Finds section by template" do spacer = SectionStyle.sections["section_spacer"]