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