changed card and section style to active_yaml (because of entanglement :-)
This commit is contained in:
parent
d936fc05ab
commit
04e189f913
@ -10,11 +10,13 @@ module Merged
|
||||
def select_image
|
||||
@images = Image.all
|
||||
end
|
||||
|
||||
def select_template
|
||||
@sections = SectionStyle.sections
|
||||
@sections = SectionStyle.all
|
||||
end
|
||||
|
||||
def select_card_template
|
||||
@cards = CardStyle.cards
|
||||
@cards = CardStyle.all
|
||||
end
|
||||
|
||||
def new
|
||||
|
@ -2,8 +2,8 @@ module Merged
|
||||
class StylesController < MergedController
|
||||
|
||||
def index
|
||||
@sections = SectionStyle.sections
|
||||
@cards = CardStyle.cards
|
||||
@section_styles = SectionStyle.all
|
||||
@cards_styles = CardStyle.all
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -65,15 +65,16 @@ module Merged
|
||||
end
|
||||
|
||||
def template_style
|
||||
CardStyle.cards[ section.card_template ]
|
||||
CardStyle.find_by_template( section.card_template)
|
||||
end
|
||||
|
||||
def allowed_fields
|
||||
template_style.fields
|
||||
end
|
||||
|
||||
def self.build_data(card_template)
|
||||
data = { "id" => SecureRandom.hex(10) }
|
||||
CardStyle.cards[ card_template ].fields.each do |key|
|
||||
CardStyle.find_by_template( card_template ).fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end
|
||||
data
|
||||
|
@ -1,42 +1,22 @@
|
||||
module Merged
|
||||
class CardStyle
|
||||
@@cards = {}
|
||||
class CardStyle < ActiveYaml::Base
|
||||
set_root_path Engine.root + "config"
|
||||
|
||||
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
|
||||
fields :template , :text , :header, :fields
|
||||
|
||||
def card_preview
|
||||
"merged/card_preview/" + template
|
||||
end
|
||||
|
||||
def options
|
||||
def options_definitions
|
||||
option_defs = []
|
||||
@content["options"].each do |name|
|
||||
options.each do |name|
|
||||
option = Option.find_by_name(name)
|
||||
raise "no option for #{name}:#{name.class}" if option.blank?
|
||||
option_defs << option
|
||||
end if @content["options"]
|
||||
end if 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
|
||||
|
@ -23,9 +23,5 @@ module Merged
|
||||
attributes[:values].split(" ")
|
||||
end
|
||||
|
||||
def self.load()
|
||||
self.all
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Merged
|
||||
end
|
||||
|
||||
def option_definitions
|
||||
template_style.options
|
||||
template_style.options_definitions
|
||||
end
|
||||
|
||||
def option(name)
|
||||
|
@ -37,7 +37,7 @@ module Merged
|
||||
new_style = template_style
|
||||
if(new_style.has_cards?)
|
||||
unless card_template
|
||||
@content["card_template"] = CardStyle.cards.keys.first
|
||||
@content["card_template"] = CardStyle.first.name
|
||||
@content["cards"] = []
|
||||
raise "Should not have cards" unless cards.empty?
|
||||
end
|
||||
@ -49,7 +49,7 @@ module Merged
|
||||
end
|
||||
|
||||
def template_style
|
||||
SectionStyle.sections[ template ]
|
||||
SectionStyle.find_by_template( template )
|
||||
end
|
||||
|
||||
def allowed_fields
|
||||
@ -153,7 +153,7 @@ module Merged
|
||||
end unless style.fields.blank?
|
||||
if(style.has_cards?)
|
||||
data["cards"] = []
|
||||
data["card_template"] = CardStyle.cards.keys.first
|
||||
data["card_template"] = CardStyle.first.name
|
||||
end
|
||||
data
|
||||
end
|
||||
|
@ -1,25 +1,25 @@
|
||||
module Merged
|
||||
class SectionStyle < CardStyle
|
||||
class SectionStyle < ActiveYaml::Base
|
||||
set_root_path Engine.root + "config"
|
||||
|
||||
@@sections = {}
|
||||
fields :template , :text , :header, :fields , :cards
|
||||
|
||||
def has_cards?
|
||||
@content["cards"] == true
|
||||
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
|
||||
def options_definitions
|
||||
option_defs = []
|
||||
options.each do |name|
|
||||
option = Option.find_by_name(name)
|
||||
raise "no option for #{name}:#{name.class}" if option.blank?
|
||||
option_defs << option
|
||||
end if options
|
||||
option_defs
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
.grid.grid-cols-4.gap-2.m-8
|
||||
- @cards.each do |name ,style|
|
||||
- @cards.each do |style|
|
||||
.relative.block.border.border-gray-100
|
||||
= link_to( section_set_card_template_path( card_template: style.template )) do
|
||||
=image_tag(style.card_preview , class: "h-56 w-full object-contain lg:h-72")
|
||||
|
@ -9,7 +9,7 @@
|
||||
Select Template for Section #{@section.index + 1}
|
||||
|
||||
.grid.grid-cols-4.gap-2.m-8
|
||||
- @sections.each do |name , style|
|
||||
- @sections.each do |style|
|
||||
.relative.block.border.border-gray-100
|
||||
= link_to( section_set_template_path( template: style.template )) do
|
||||
=image_tag(style.section_preview , class: "h-56 w-full object-contain lg:h-72")
|
||||
|
@ -2,7 +2,7 @@
|
||||
%h1.text-4xl.font-bold
|
||||
Section styles
|
||||
.grid.grid-cols-3.gap-4.m-8
|
||||
-@sections.each do |name , style|
|
||||
-@section_styles.each do | style|
|
||||
%article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm
|
||||
=image_tag(style.section_preview , class: "h-56 w-full object-contain lg:h-72")
|
||||
%p.mt-2.text-sm.text-gray-500
|
||||
@ -31,7 +31,7 @@
|
||||
%h1.text-4xl.font-bold
|
||||
Card styles
|
||||
.grid.grid-cols-3.gap-4.m-8
|
||||
-@cards.each do |name , style|
|
||||
-@cards_styles.each do |style|
|
||||
%article.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm
|
||||
=image_tag(style.card_preview , class: "h-56 w-full object-contain lg:h-72")
|
||||
%p.mt-2.text-sm.text-gray-500
|
||||
|
@ -4,11 +4,10 @@ require "merged/engine"
|
||||
module Merged
|
||||
|
||||
def self.load_data
|
||||
["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
|
||||
# pre-load data
|
||||
Option.all
|
||||
CardStyle.all
|
||||
SectionStyle.all
|
||||
Page.load_pages
|
||||
Image.load_images
|
||||
end
|
||||
|
@ -2,12 +2,16 @@ require 'rails_helper'
|
||||
|
||||
module Merged
|
||||
RSpec.describe CardStyle, type: :model do
|
||||
let(:first_card) {Style.cards.first}
|
||||
let(:first_card) {CardStyle.all.first}
|
||||
|
||||
it "has Style.cards" do
|
||||
expect(CardStyle.cards.class).to be Hash
|
||||
expect(CardStyle.cards.length).to be 5
|
||||
it "has .all" do
|
||||
expect(CardStyle.all.length).to be 5
|
||||
end
|
||||
|
||||
it "has fields" do
|
||||
expect(first_card.fields.class).to be Array
|
||||
expect(first_card.fields.length).to be 2
|
||||
expect(first_card.fields.first).to eq "header"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,18 +2,17 @@ require 'rails_helper'
|
||||
|
||||
module Merged
|
||||
RSpec.describe SectionStyle, type: :model do
|
||||
let(:first_section) {SectionStyle.sections.first}
|
||||
let(:first_section) {SectionStyle.all.first}
|
||||
|
||||
it "has Style.sections" do
|
||||
expect(SectionStyle.sections.class).to be Hash
|
||||
expect(SectionStyle.sections.length).to be 7
|
||||
expect(SectionStyle.all.length).to be 7
|
||||
end
|
||||
it "Finds section by template" do
|
||||
spacer = SectionStyle.sections["section_spacer"]
|
||||
spacer = SectionStyle.find_by_template("section_spacer")
|
||||
expect(spacer).not_to eq nil
|
||||
end
|
||||
it "Spacer has no fields" do
|
||||
spacer = SectionStyle.sections["section_spacer"]
|
||||
spacer = SectionStyle.find_by_template("section_spacer")
|
||||
expect(spacer.fields).to be nil
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user