locomotivecms_steam 1.4.1 → 1.5.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +31 -25
- data/Rakefile +2 -2
- data/config/locales/pt-BR.yml +43 -13
- data/lib/locomotive/steam.rb +9 -4
- data/lib/locomotive/steam/adapters/filesystem.rb +2 -7
- data/lib/locomotive/steam/adapters/filesystem/sanitizer.rb +0 -2
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +11 -0
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +37 -0
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +18 -0
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +4 -3
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +4 -3
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +40 -0
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb +0 -1
- data/lib/locomotive/steam/adapters/memory.rb +1 -1
- data/lib/locomotive/steam/entities/content_entry.rb +15 -3
- data/lib/locomotive/steam/entities/content_type.rb +2 -1
- data/lib/locomotive/steam/entities/page.rb +21 -19
- data/lib/locomotive/steam/entities/section.rb +24 -0
- data/lib/locomotive/steam/entities/site.rb +3 -1
- data/lib/locomotive/steam/liquid.rb +2 -0
- data/lib/locomotive/steam/liquid/drops/page.rb +4 -2
- data/lib/locomotive/steam/liquid/drops/params.rb +51 -0
- data/lib/locomotive/steam/liquid/drops/section.rb +56 -0
- data/lib/locomotive/steam/liquid/drops/section_block.rb +47 -0
- data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +97 -0
- data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +65 -0
- data/lib/locomotive/steam/liquid/drops/site.rb +2 -1
- data/lib/locomotive/steam/liquid/errors.rb +2 -0
- data/lib/locomotive/steam/liquid/filters/base.rb +3 -3
- data/lib/locomotive/steam/liquid/filters/date.rb +1 -1
- data/lib/locomotive/steam/liquid/filters/html.rb +7 -2
- data/lib/locomotive/steam/liquid/filters/json.rb +3 -1
- data/lib/locomotive/steam/liquid/tags/action.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +63 -0
- data/lib/locomotive/steam/liquid/tags/concerns/i18n_page.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/concerns/section.rb +117 -0
- data/lib/locomotive/steam/liquid/tags/global_section.rb +32 -0
- data/lib/locomotive/steam/liquid/tags/model_form.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/section.rb +87 -0
- data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +56 -0
- data/lib/locomotive/steam/liquid/tags/snippet.rb +3 -2
- data/lib/locomotive/steam/liquid/template.rb +0 -5
- data/lib/locomotive/steam/middlewares.rb +1 -1
- data/lib/locomotive/steam/middlewares/auth.rb +29 -13
- data/lib/locomotive/steam/middlewares/concerns/helpers.rb +59 -0
- data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +94 -0
- data/lib/locomotive/steam/middlewares/encoded_link_redirection.rb +45 -0
- data/lib/locomotive/steam/middlewares/entry_submission.rb +1 -1
- data/lib/locomotive/steam/middlewares/favicon.rb +1 -1
- data/lib/locomotive/steam/middlewares/locale.rb +63 -15
- data/lib/locomotive/steam/middlewares/locale_redirection.rb +18 -6
- data/lib/locomotive/steam/middlewares/logging.rb +1 -1
- data/lib/locomotive/steam/middlewares/page.rb +35 -6
- data/lib/locomotive/steam/middlewares/path.rb +1 -1
- data/lib/locomotive/steam/middlewares/private_access.rb +1 -1
- data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
- data/lib/locomotive/steam/middlewares/renderer.rb +2 -82
- data/lib/locomotive/steam/middlewares/robots.rb +1 -1
- data/lib/locomotive/steam/middlewares/section.rb +56 -0
- data/lib/locomotive/steam/middlewares/site.rb +1 -1
- data/lib/locomotive/steam/middlewares/sitemap.rb +58 -45
- data/lib/locomotive/steam/middlewares/templatized_page.rb +1 -1
- data/lib/locomotive/steam/middlewares/thread_safe.rb +85 -2
- data/lib/locomotive/steam/middlewares/timezone.rb +1 -1
- data/lib/locomotive/steam/middlewares/url_redirection.rb +1 -1
- data/lib/locomotive/steam/models/entity.rb +0 -2
- data/lib/locomotive/steam/models/mapper.rb +5 -3
- data/lib/locomotive/steam/models/scope.rb +8 -0
- data/lib/locomotive/steam/repositories.rb +4 -0
- data/lib/locomotive/steam/repositories/content_entry_repository.rb +6 -2
- data/lib/locomotive/steam/repositories/page_repository.rb +4 -1
- data/lib/locomotive/steam/repositories/section_repository.rb +14 -0
- data/lib/locomotive/steam/repositories/site_repository.rb +1 -1
- data/lib/locomotive/steam/repositories/snippet_repository.rb +0 -3
- data/lib/locomotive/steam/server.rb +3 -1
- data/lib/locomotive/steam/services.rb +17 -1
- data/lib/locomotive/steam/services/action_service.rb +10 -0
- data/lib/locomotive/steam/services/concerns/decorator.rb +0 -2
- data/lib/locomotive/steam/services/image_resizer_service.rb +1 -1
- data/lib/locomotive/steam/services/page_finder_service.rb +6 -0
- data/lib/locomotive/steam/services/section_finder_service.rb +17 -0
- data/lib/locomotive/steam/services/url_builder_service.rb +31 -17
- data/lib/locomotive/steam/services/url_finder_service.rb +87 -0
- data/lib/locomotive/steam/version.rb +2 -2
- data/locomotivecms_steam.gemspec +1 -1
- data/spec/fixtures/default/app/views/pages/tags/section.liquid.haml +11 -0
- data/spec/fixtures/default/app/views/sections/carousel.liquid +20 -0
- data/spec/fixtures/default/app/views/sections/footer.liquid +48 -0
- data/spec/fixtures/default/app/views/sections/header.liquid +54 -0
- data/spec/fixtures/default/config/deploy.yml +1 -1
- data/spec/fixtures/errors/section_bad_json_content.liquid +9 -0
- data/spec/fixtures/errors/section_bad_json_header.liquid +8 -0
- data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_sections.bson +0 -0
- data/spec/fixtures/mongodb/{sessions.metadata.json → locomotive_sections.metadata.json} +1 -1
- data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
- data/spec/integration/repositories/content_entry_repository_spec.rb +1 -1
- data/spec/integration/repositories/page_repository_spec.rb +1 -1
- data/spec/integration/repositories/theme_asset_repository_spec.rb +1 -1
- data/spec/integration/server/auth_spec.rb +0 -4
- data/spec/integration/server/basic_spec.rb +8 -0
- data/spec/integration/server/contact_form_spec.rb +15 -2
- data/spec/integration/server/sitemap_spec.rb +5 -3
- data/spec/integration/services/content_entry_service_spec.rb +1 -1
- data/spec/support/helpers.rb +3 -3
- data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +65 -0
- data/spec/unit/adapters/filesystem/sanitizers/site_spec.rb +28 -2
- data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +8 -4
- data/spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +2 -2
- data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +1 -1
- data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +27 -0
- data/spec/unit/entities/section_spec.rb +29 -0
- data/spec/unit/liquid/drops/params_spec.rb +38 -0
- data/spec/unit/liquid/drops/section_content_proxy_spec.rb +88 -0
- data/spec/unit/liquid/drops/section_spec.rb +26 -0
- data/spec/unit/liquid/filters/html_spec.rb +198 -170
- data/spec/unit/liquid/filters/json_spec.rb +7 -0
- data/spec/unit/liquid/tags/action_spec.rb +12 -2
- data/spec/unit/liquid/tags/alt_page_links_spec.rb +58 -0
- data/spec/unit/liquid/tags/global_section_spec.rb +130 -0
- data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
- data/spec/unit/liquid/tags/locale_switcher_spec.rb +1 -1
- data/spec/unit/liquid/tags/model_form_spec.rb +8 -0
- data/spec/unit/liquid/tags/path_to_spec.rb +26 -3
- data/spec/unit/liquid/tags/section_spec.rb +231 -0
- data/spec/unit/liquid/tags/sections_dropzone_spec.rb +107 -0
- data/spec/unit/middlewares/auth_spec.rb +9 -2
- data/spec/unit/middlewares/encoded_link_redirection_spec.rb +73 -0
- data/spec/unit/middlewares/entry_submission_spec.rb +1 -1
- data/spec/unit/middlewares/helpers_spec.rb +3 -64
- data/spec/unit/middlewares/locale_redirection_spec.rb +13 -2
- data/spec/unit/middlewares/locale_spec.rb +52 -10
- data/spec/unit/middlewares/page_spec.rb +57 -16
- data/spec/unit/middlewares/private_access_spec.rb +1 -1
- data/spec/unit/middlewares/redirection_spec.rb +1 -1
- data/spec/unit/middlewares/renderer_spec.rb +2 -1
- data/spec/unit/middlewares/section_spec.rb +70 -0
- data/spec/unit/middlewares/site_spec.rb +1 -1
- data/spec/unit/middlewares/sitemap_spec.rb +4 -42
- data/spec/unit/middlewares/url_redirection_spec.rb +1 -1
- data/spec/unit/repositories/content_entry_repository_spec.rb +13 -13
- data/spec/unit/repositories/section_repository_spec.rb +38 -0
- data/spec/unit/repositories/snippet_repository_spec.rb +0 -3
- data/spec/unit/services/action_service_spec.rb +19 -1
- data/spec/unit/services/asset_host_service_spec.rb +8 -0
- data/spec/unit/services/parent_finder_service_spec.rb +1 -2
- data/spec/unit/services/section_finder_service_spec.rb +28 -0
- data/spec/unit/services/url_builder_service_spec.rb +14 -4
- data/spec/unit/services/url_finder_service_spec.rb +100 -0
- data/spec/unit/services_spec.rb +34 -20
- metadata +72 -11
- data/lib/locomotive/steam/middlewares/helpers.rb +0 -140
- data/spec/fixtures/mongodb/sessions.bson +0 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Drops
|
5
|
+
|
6
|
+
# Required to allow the sync between the Locomotive editor
|
7
|
+
# and the string/text inputs of a section and section block
|
8
|
+
class SectionEditorSettingData < ::Liquid::Drop
|
9
|
+
|
10
|
+
def initialize(section)
|
11
|
+
@section = section
|
12
|
+
end
|
13
|
+
|
14
|
+
def before_method(meth)
|
15
|
+
block = nil
|
16
|
+
prefix = "section-#{@context['section'].id}"
|
17
|
+
matches = (@context['forloop.name'] || '').match(SECTIONS_BLOCK_FORLOOP_REGEXP)
|
18
|
+
|
19
|
+
# are we inside a block?
|
20
|
+
if matches && variable_name = matches[:name]
|
21
|
+
block = @context[variable_name]
|
22
|
+
prefix += "-block.#{block.id}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# only string and text inputs can synced
|
26
|
+
if is_text?(meth.to_s, block)
|
27
|
+
%( data-locomotive-editor-setting="#{prefix}.#{meth}")
|
28
|
+
else
|
29
|
+
''
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def is_text?(id, block)
|
36
|
+
settings = block ? block_settings(block['type']) : section_settings
|
37
|
+
|
38
|
+
# can happen if the developer forgets to assign a type to
|
39
|
+
# the default blocks
|
40
|
+
return false if settings.blank?
|
41
|
+
|
42
|
+
text_inputs(settings).include?(id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def text_inputs(settings)
|
46
|
+
settings.map do |input|
|
47
|
+
%w(text textarea).include?(input['type']) ? input['id'] : nil
|
48
|
+
end.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
def block_settings(type)
|
52
|
+
@section.definition['blocks'].find do |block|
|
53
|
+
block['type'] == type
|
54
|
+
end&.fetch('settings', nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
def section_settings
|
58
|
+
@section.definition['settings']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -4,7 +4,8 @@ module Locomotive
|
|
4
4
|
module Drops
|
5
5
|
class Site < I18nBase
|
6
6
|
|
7
|
-
delegate :name, :handle, :domains, :seo_title, :meta_keywords,
|
7
|
+
delegate :name, :handle, :domains, :seo_title, :meta_keywords,
|
8
|
+
:meta_description, :asset_host, :sections_content, to: :@_source
|
8
9
|
|
9
10
|
def index
|
10
11
|
@index ||= repository.root.to_liquid
|
@@ -35,14 +35,14 @@ module Locomotive
|
|
35
35
|
input.respond_to?(:url) ? input.url : input
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def any_asset_url(input, extension = nil, folder = nil)
|
39
39
|
return '' if input.nil?
|
40
40
|
|
41
41
|
if input =~ /^https?:/
|
42
42
|
input
|
43
43
|
else
|
44
|
-
uri = input.starts_with?('/') ? URI(input) : URI(asset_url("#{folder}/#{input}"))
|
45
|
-
uri.path = "#{uri.path}#{extension}" unless uri.path.ends_with?(extension)
|
44
|
+
uri = input.starts_with?('/') ? URI(input) : URI(asset_url(folder.blank? ? input : "#{folder}/#{input}"))
|
45
|
+
uri.path = "#{uri.path}#{extension}" unless extension.blank? || uri.path.ends_with?(extension)
|
46
46
|
uri.to_s
|
47
47
|
end
|
48
48
|
end
|
@@ -18,10 +18,15 @@ module Locomotive
|
|
18
18
|
%{<link rel="#{rel}" type="#{type}" title="#{title}" href="#{input}" />}
|
19
19
|
end
|
20
20
|
|
21
|
+
# Write the url of any theme file
|
22
|
+
def theme_asset_url(input)
|
23
|
+
any_asset_url(input)
|
24
|
+
end
|
25
|
+
|
21
26
|
# Write the url of a theme stylesheet
|
22
27
|
# input: name of the css file
|
23
28
|
def stylesheet_url(input)
|
24
|
-
|
29
|
+
any_asset_url(input, '.css', 'stylesheets')
|
25
30
|
end
|
26
31
|
|
27
32
|
# Write the link tag of a theme stylesheet
|
@@ -37,7 +42,7 @@ module Locomotive
|
|
37
42
|
# Write the url to javascript resource
|
38
43
|
# input: name of the javascript file
|
39
44
|
def javascript_url(input)
|
40
|
-
|
45
|
+
any_asset_url(input, '.js', 'javascripts')
|
41
46
|
end
|
42
47
|
|
43
48
|
# Write the link to javascript resource
|
@@ -9,7 +9,9 @@ module Locomotive
|
|
9
9
|
fields = fields.split(',').map(&:strip)
|
10
10
|
end
|
11
11
|
|
12
|
-
if input.
|
12
|
+
if input.is_a?(Hash)
|
13
|
+
object_to_json(input, fields)
|
14
|
+
elsif input.respond_to?(:each)
|
13
15
|
'[' + input.map do |object|
|
14
16
|
fields.size == 1 ? object[fields.first].to_json : object_to_json(object, fields)
|
15
17
|
end.join(',') + ']'
|
@@ -54,9 +54,9 @@ module Locomotive
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def safe_params(context)
|
57
|
-
return {} if context[
|
57
|
+
return {} if context.registers[:params].blank?
|
58
58
|
|
59
|
-
context[
|
59
|
+
context.registers[:params].dup.tap do |params|
|
60
60
|
# Tempfile can't be converted in Duktape for obvious reasons
|
61
61
|
replace_tempfile(params)
|
62
62
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
|
6
|
+
class AltPageLinks < ::Liquid::Tag
|
7
|
+
|
8
|
+
include Concerns::I18nPage
|
9
|
+
|
10
|
+
def render(context)
|
11
|
+
set_vars_from_context(context)
|
12
|
+
|
13
|
+
if @site.locales.size == 1
|
14
|
+
''
|
15
|
+
else
|
16
|
+
(
|
17
|
+
[%(<link rel="alternate" hreflang="x-default" href="#{url_for(@site.default_locale, true)}" />)] +
|
18
|
+
@site.locales.map do |locale|
|
19
|
+
%(<link rel="alternate" hreflang="#{locale}" href="#{url_for(locale)}" />)
|
20
|
+
end
|
21
|
+
).join("\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Examples:
|
28
|
+
# - http://www.example.com/fr (even if the default locale is fr)
|
29
|
+
# - http://www.example.com/ (as the default url (x-default) for the index page)
|
30
|
+
#
|
31
|
+
# Note: the index page has a different behaviour because rendering "/" depends
|
32
|
+
# on the language returned by the browser (so might be different based on the user session).
|
33
|
+
def url_for(locale, default = false)
|
34
|
+
change_page_locale(locale, @page) do
|
35
|
+
fullpath = services.url_builder.url_for(@page.send(:_source), locale, @page.index? && !default ? true : nil)
|
36
|
+
|
37
|
+
if @page.index? && default
|
38
|
+
fullpath.gsub!(/\/#{locale}$/, '/')
|
39
|
+
end
|
40
|
+
|
41
|
+
@base_url + fullpath
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def services
|
46
|
+
@context.registers[:services]
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_vars_from_context(context)
|
50
|
+
@context = context
|
51
|
+
@site = context.registers[:site]
|
52
|
+
@page = context['page']
|
53
|
+
@base_url = context['base_url']
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
::Liquid::Template.register_tag('alt_page_links'.freeze, AltPageLinks)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Locomotive::Steam::Liquid::Tags::Concerns
|
2
|
+
|
3
|
+
module Section
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def render_section(context, template, section, content)
|
8
|
+
context.stack do
|
9
|
+
# build a drop from the content and add it to the new context
|
10
|
+
context['section'] = Locomotive::Steam::Liquid::Drops::Section.new(
|
11
|
+
section,
|
12
|
+
content
|
13
|
+
)
|
14
|
+
|
15
|
+
# assign an id if specified in the context
|
16
|
+
context['section'].id ||= context['section_id'] if context['section_id'].present?
|
17
|
+
|
18
|
+
begin
|
19
|
+
_render(context, template)
|
20
|
+
rescue Locomotive::Steam::ParsingRenderingError => e
|
21
|
+
e.file = section.name + ' [Section]'
|
22
|
+
raise e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def _render(context, template)
|
28
|
+
if context.registers[:live_editing]
|
29
|
+
editor_settings_lookup(template.root)
|
30
|
+
end
|
31
|
+
|
32
|
+
context.stack do
|
33
|
+
html = template.render(context)
|
34
|
+
section = context['section']
|
35
|
+
|
36
|
+
tag_id = %(id="locomotive-section-#{section.id}")
|
37
|
+
tag_class = %(class="#{['locomotive-section', section.css_class].compact.join(' ')}")
|
38
|
+
tag_data = %(data-locomotive-section-type="#{section.type}")
|
39
|
+
|
40
|
+
%(<div #{tag_id} #{tag_class} #{tag_data}>#{html}</div>)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# in order to enable string/text synchronization with the editor:
|
45
|
+
# - find variables like {{ section.settings.<id> }} or {{ block.settings.<id> }}
|
46
|
+
# - once found, get the closest tag
|
47
|
+
# - add custom data attributes to it
|
48
|
+
def editor_settings_lookup(root)
|
49
|
+
previous_node = nil
|
50
|
+
new_nodelist = []
|
51
|
+
|
52
|
+
return if root.nodelist.blank?
|
53
|
+
|
54
|
+
root.nodelist.each_with_index do |node, index|
|
55
|
+
if node.is_a?(::Liquid::Variable) && previous_node.is_a?(::Liquid::Token)
|
56
|
+
matches = node.raw.match(Locomotive::Steam::SECTIONS_SETTINGS_VARIABLE_REGEXP)
|
57
|
+
|
58
|
+
# is a section setting variable?
|
59
|
+
if matches && matches[:id] && wrapped_around_tag?(index, root.nodelist)
|
60
|
+
# open the closest HTML tag
|
61
|
+
previous_node.gsub!(/>(\s*)\z/, '\1')
|
62
|
+
|
63
|
+
# here we go, add a liquid variable!
|
64
|
+
new_nodelist.push(::Liquid::Variable.new(
|
65
|
+
"section.editor_setting_data.#{matches[:id]}",
|
66
|
+
node.instance_variable_get(:@options))
|
67
|
+
)
|
68
|
+
|
69
|
+
# close the tag
|
70
|
+
new_nodelist.push(::Liquid::Token.new('>', previous_node.line_number))
|
71
|
+
end
|
72
|
+
elsif node.respond_to?(:nodelist)
|
73
|
+
editor_settings_lookup(node)
|
74
|
+
end
|
75
|
+
|
76
|
+
new_nodelist.push(node)
|
77
|
+
|
78
|
+
previous_node = node
|
79
|
+
end
|
80
|
+
|
81
|
+
(root.instance_variable_get(:@body) || root).instance_variable_set(:@nodelist, new_nodelist)
|
82
|
+
end
|
83
|
+
|
84
|
+
def wrapped_around_tag?(index, nodelist)
|
85
|
+
return false if index + 1 >= nodelist.size
|
86
|
+
|
87
|
+
previous_node = nodelist[index - 1]
|
88
|
+
next_node = nodelist[index + 1]
|
89
|
+
|
90
|
+
return false unless next_node.is_a?(::Liquid::Token)
|
91
|
+
|
92
|
+
(previous_node =~ /\>\s*\z/).present? && (next_node =~ /\A\s*\</).present?
|
93
|
+
end
|
94
|
+
|
95
|
+
def notify_on_parsing(type, source: :page, is_dropzone: false, key: nil, id: nil, label: nil, placement: nil)
|
96
|
+
ActiveSupport::Notifications.instrument('steam.parse.section', {
|
97
|
+
attributes: {
|
98
|
+
type: type,
|
99
|
+
source: source,
|
100
|
+
id: id,
|
101
|
+
key: key,
|
102
|
+
is_dropzone: is_dropzone,
|
103
|
+
label: label,
|
104
|
+
placement: placement
|
105
|
+
},
|
106
|
+
page: options[:page],
|
107
|
+
block: current_inherited_block_name
|
108
|
+
})
|
109
|
+
end
|
110
|
+
|
111
|
+
def current_inherited_block_name
|
112
|
+
options[:inherited_blocks].try(:[], :nested).try(:last).try(:name)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
class GlobalSection < Locomotive::Steam::Liquid::Tags::Section
|
6
|
+
|
7
|
+
def parse(tokens)
|
8
|
+
notify_on_parsing(evaluate_section_name,
|
9
|
+
source: :site,
|
10
|
+
id: "site-#{evaluate_section_name}",
|
11
|
+
key: evaluate_section_name,
|
12
|
+
placement: @section_options[:placement]&.to_sym
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def find_section_content(context)
|
19
|
+
context['site']&.sections_content&.fetch(@section_type, nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_section_dom_id(context)
|
23
|
+
context['section_id'] = "site-#{@section_type}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
::Liquid::Template.register_tag('global_section'.freeze, GlobalSection)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
class Section < ::Liquid::Include
|
6
|
+
|
7
|
+
include Concerns::Section
|
8
|
+
|
9
|
+
def initialize(tag_name, markup, options)
|
10
|
+
if markup =~ /(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)\s*,*(.*)?/o
|
11
|
+
@section_type, _options = $1, $2
|
12
|
+
raw_options = parse_options_from_string(_options)
|
13
|
+
@section_options = interpolate_options(raw_options, {})
|
14
|
+
super
|
15
|
+
else
|
16
|
+
raise ::Liquid::SyntaxError.new("Syntax Error in 'section' - Valid syntax: section section_type, id: '<string>', placement: 'top|bottom' (id and placement are optional)")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse(tokens)
|
21
|
+
notify_on_parsing(evaluate_section_name,
|
22
|
+
id: "page-#{@section_options[:id] || evaluate_section_name}",
|
23
|
+
key: (@section_options[:id] || evaluate_section_name).to_s,
|
24
|
+
label: @section_options[:label],
|
25
|
+
placement: @section_options[:placement]&.to_sym
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def render(context)
|
30
|
+
# @options doesn't include the page key if cache is on
|
31
|
+
@options[:page] = context.registers[:page]
|
32
|
+
|
33
|
+
# get the type/slug of the section
|
34
|
+
# @section_options = interpolate_options(@raw_section_options, context)
|
35
|
+
@section_type = evaluate_section_name(context)
|
36
|
+
@template_name = "sections-#{@section_type}"
|
37
|
+
|
38
|
+
section = find_section(context)
|
39
|
+
template = load_cached_partial(context)
|
40
|
+
|
41
|
+
# if the tag is called by the Section middleware, use the content
|
42
|
+
# from the request.
|
43
|
+
content = context.registers[:_section_content]
|
44
|
+
|
45
|
+
# if no content from the middleware, go get it from the page
|
46
|
+
content ||= find_section_content(context)
|
47
|
+
|
48
|
+
context.stack do
|
49
|
+
set_section_dom_id(context)
|
50
|
+
render_section(context, template, section, content)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def set_section_dom_id(context)
|
57
|
+
context['section_id'] = "page-#{@section_options[:id] || @section_type}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_template_from_file_system(context)
|
61
|
+
section = find_section(context)
|
62
|
+
raise SectionNotFound.new("Section with slug '#{@section_type}' was not found") if section.nil?
|
63
|
+
section.liquid_source
|
64
|
+
end
|
65
|
+
|
66
|
+
def find_section(context)
|
67
|
+
context.registers[:services].section_finder.find(@section_type)
|
68
|
+
end
|
69
|
+
|
70
|
+
def find_section_content(context)
|
71
|
+
section_id = @section_options[:id].presence || @section_type
|
72
|
+
context['page']&.sections_content&.fetch(section_id, nil)
|
73
|
+
end
|
74
|
+
|
75
|
+
def evaluate_section_name(context = nil)
|
76
|
+
context.try(:evaluate, @template_name) ||
|
77
|
+
(!@template_name.is_a?(String) && @template_name.send(:state).first) ||
|
78
|
+
@template_name
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
::Liquid::Template.register_tag('section'.freeze, Section)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|