add sections content editing in locomotive engine

Julien Girard committed May 07, 2018
commit f47227bca2a09887c09630f912883636dc5121ab
Showing 4 changed files with 14 additions and 6 deletions
locomotive/steam/liquid/drops/site.rb b/lib/locomotive/steam/liquid/drops/site.rb +1 -1
@@ @@ -5,7 +5,7 @@ module Locomotive
class Site < I18nBase
delegate :name, :handle, :domains, :seo_title, :meta_keywords,
- :meta_description, :asset_host, :sections, to: :@_source
+ :meta_description, :asset_host, :sections_content, to: :@_source
def index
@index ||= repository.root.to_liquid
locomotive/steam/liquid/tags/section.rb b/lib/locomotive/steam/liquid/tags/section.rb +8 -3
@@ @@ -1,15 +1,20 @@
+ require 'pry'
module Locomotive
module Steam
module Liquid
module Tags
class Section < ::Liquid::Include
+ def parse(tokens)
+ ActiveSupport::Notifications.instrument('steam.parse.section', name: @template_name)
+ end
+
def render(context)
# @options doesn't include the page key if cache is on
@options[:page] = context.registers[:page]
# 1. get the name/slug of the section
- @template_name = evaluate_snippet_name(context)
+ @template_name = evaluate_section_name(context)
# 2. get the section
section = find_section(context)
@@ @@ -17,7 +22,7 @@ module Locomotive
# 3. because it's considered as a static section, go get the content from
# the current site. If it doesn't exist, use the default attribute of
# the section
- section_content = context['site']&.sections&.fetch(@template_name, nil) #context["site"].sections[@template_name]
+ section_content = context['site']&.sections_content&.fetch(@template_name, nil) #context["site"].sections[@template_name]
if section_content.blank?
section_content = section.definition[:default] || {}
@@ @@ -47,7 +52,7 @@ module Locomotive
end
# Repeat snippet
- def evaluate_snippet_name(context = nil)
+ def evaluate_section_name(context = nil)
context.try(:evaluate, @template_name) ||
(!@template_name.is_a?(String) && @template_name.send(:state).first) ||
@template_name
locomotive/steam/repositories/site_repository.rb b/lib/locomotive/steam/repositories/site_repository.rb +1 -1
@@ @@ -7,7 +7,7 @@ module Locomotive
# Entity mapping
mapping :sites, entity: Site do
- localized_attributes :seo_title, :meta_description, :meta_keywords, :sections
+ localized_attributes :seo_title, :meta_description, :meta_keywords, :sections_content
end
def by_domain(domain)
spec/unit/liquid/tags/section_spec.rb +4 -1
@@ @@ -7,7 +7,10 @@ describe Locomotive::Steam::Liquid::Tags::Section do
let(:source) { "Locomotive {% section header %}" }
let(:context) { ::Liquid::Context.new({}, {}, { services: services }) }
- before { allow(finder).to receive(:find).and_return(section) }
+ before do
+ allow(finder).to receive(:find).and_return(section)
+
+ end
describe 'rendering' do