locomotivecms_builder 1.0.0.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +31 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +47 -0
- data/TODO +57 -0
- data/bin/builder +9 -0
- data/generators/blank/Gemfile.tt +20 -0
- data/generators/blank/app/content_types/.empty_directory +1 -0
- data/generators/blank/app/views/pages/404.liquid +11 -0
- data/generators/blank/app/views/pages/index.liquid +19 -0
- data/generators/blank/app/views/snippets/.empty_directory +1 -0
- data/generators/blank/config/deploy.yml +12 -0
- data/generators/blank/config/site.yml.tt +16 -0
- data/generators/blank/config/translations.yml +8 -0
- data/generators/blank/config.ru +3 -0
- data/generators/blank/data/.empty_directory +1 -0
- data/generators/blank/public/fonts/.empty_directory +1 -0
- data/generators/blank/public/images/.empty_directory +1 -0
- data/generators/blank/public/javascripts/.empty_directory +1 -0
- data/generators/blank/public/samples/.empty_directory +1 -0
- data/generators/blank/public/stylesheets/.empty_directory +1 -0
- data/generators/bootstrap/Gemfile.tt +20 -0
- data/generators/bootstrap/app/content_types/.empty_directory +1 -0
- data/generators/bootstrap/app/views/pages/404.liquid +13 -0
- data/generators/bootstrap/app/views/pages/404.liquid.haml +10 -0
- data/generators/bootstrap/app/views/pages/index.liquid +85 -0
- data/generators/bootstrap/app/views/pages/index.liquid.haml +72 -0
- data/generators/bootstrap/app/views/snippets/footer.liquid +3 -0
- data/generators/bootstrap/app/views/snippets/footer.liquid.haml +2 -0
- data/generators/bootstrap/config/deploy.yml +12 -0
- data/generators/bootstrap/config/site.yml.tt +16 -0
- data/generators/bootstrap/config/translations.yml +8 -0
- data/generators/bootstrap/config.ru +3 -0
- data/generators/bootstrap/data/.empty_directory +1 -0
- data/generators/bootstrap/public/fonts/FontAwesome.otf +0 -0
- data/generators/bootstrap/public/fonts/font-awesome-ie7.min.css +23 -0
- data/generators/bootstrap/public/fonts/font-awesome.css +469 -0
- data/generators/bootstrap/public/fonts/font-awesome.min.css +34 -0
- data/generators/bootstrap/public/fonts/fontawesome-webfont.eot +0 -0
- data/generators/bootstrap/public/fonts/fontawesome-webfont.ttf +0 -0
- data/generators/bootstrap/public/fonts/fontawesome-webfont.woff +0 -0
- data/generators/bootstrap/public/javascripts/bootstrap.js +2159 -0
- data/generators/bootstrap/public/javascripts/bootstrap.min.js +6 -0
- data/generators/bootstrap/public/samples/.empty_directory +1 -0
- data/generators/bootstrap/public/stylesheets/application.css.scss +39 -0
- data/generators/bootstrap/public/stylesheets/bootstrap-responsive.css +1092 -0
- data/generators/bootstrap/public/stylesheets/bootstrap-responsive.min.css +9 -0
- data/generators/bootstrap/public/stylesheets/bootstrap.css +5652 -0
- data/generators/bootstrap/public/stylesheets/bootstrap.min.css +726 -0
- data/generators/content_type/app/content_types/%name%.yml.tt +58 -0
- data/generators/content_type/data/%name%.yml.tt +24 -0
- data/generators/page/template.liquid.haml.tt +35 -0
- data/generators/page/template.liquid.tt +1 -0
- data/generators/snippet/template.liquid.haml.tt +4 -0
- data/generators/snippet/template.liquid.tt +4 -0
- data/lib/locomotive/builder/cli.rb +225 -0
- data/lib/locomotive/builder/exceptions.rb +17 -0
- data/lib/locomotive/builder/generators/content_type.rb +47 -0
- data/lib/locomotive/builder/generators/page.rb +57 -0
- data/lib/locomotive/builder/generators/site/base.rb +30 -0
- data/lib/locomotive/builder/generators/site/blank.rb +23 -0
- data/lib/locomotive/builder/generators/site/bootstrap.rb +35 -0
- data/lib/locomotive/builder/generators/site.rb +97 -0
- data/lib/locomotive/builder/generators/snippet.rb +54 -0
- data/lib/locomotive/builder/liquid/drops/base.rb +44 -0
- data/lib/locomotive/builder/liquid/drops/content_entry.rb +48 -0
- data/lib/locomotive/builder/liquid/drops/content_types.rb +121 -0
- data/lib/locomotive/builder/liquid/drops/page.rb +36 -0
- data/lib/locomotive/builder/liquid/drops/site.rb +21 -0
- data/lib/locomotive/builder/liquid/errors.rb +7 -0
- data/lib/locomotive/builder/liquid/filters/date.rb +98 -0
- data/lib/locomotive/builder/liquid/filters/html.rb +154 -0
- data/lib/locomotive/builder/liquid/filters/misc.rb +28 -0
- data/lib/locomotive/builder/liquid/filters/resize.rb +18 -0
- data/lib/locomotive/builder/liquid/filters/text.rb +50 -0
- data/lib/locomotive/builder/liquid/filters/translate.rb +24 -0
- data/lib/locomotive/builder/liquid/patches.rb +47 -0
- data/lib/locomotive/builder/liquid/tags/consume.rb +58 -0
- data/lib/locomotive/builder/liquid/tags/csrf.rb +34 -0
- data/lib/locomotive/builder/liquid/tags/editable/base.rb +46 -0
- data/lib/locomotive/builder/liquid/tags/editable/control.rb +19 -0
- data/lib/locomotive/builder/liquid/tags/editable/file.rb +15 -0
- data/lib/locomotive/builder/liquid/tags/editable/long_text.rb +15 -0
- data/lib/locomotive/builder/liquid/tags/editable/short_text.rb +15 -0
- data/lib/locomotive/builder/liquid/tags/editable.rb +5 -0
- data/lib/locomotive/builder/liquid/tags/extends.rb +25 -0
- data/lib/locomotive/builder/liquid/tags/google_analytics.rb +28 -0
- data/lib/locomotive/builder/liquid/tags/inline_editor.rb +16 -0
- data/lib/locomotive/builder/liquid/tags/locale_switcher.rb +180 -0
- data/lib/locomotive/builder/liquid/tags/nav.rb +167 -0
- data/lib/locomotive/builder/liquid/tags/paginate.rb +105 -0
- data/lib/locomotive/builder/liquid/tags/seo.rb +74 -0
- data/lib/locomotive/builder/liquid/tags/snippet.rb +42 -0
- data/lib/locomotive/builder/liquid/tags/with_scope.rb +43 -0
- data/lib/locomotive/builder/liquid.rb +19 -0
- data/lib/locomotive/builder/listen.rb +48 -0
- data/lib/locomotive/builder/misc/core_ext.rb +29 -0
- data/lib/locomotive/builder/misc/dragonfly.rb +82 -0
- data/lib/locomotive/builder/misc/httparty.rb +47 -0
- data/lib/locomotive/builder/misc/i18n.rb +2 -0
- data/lib/locomotive/builder/misc/will_paginate.rb +16 -0
- data/lib/locomotive/builder/misc.rb +5 -0
- data/lib/locomotive/builder/server/dynamic_assets.rb +31 -0
- data/lib/locomotive/builder/server/entry_submission.rb +116 -0
- data/lib/locomotive/builder/server/favicon.rb +17 -0
- data/lib/locomotive/builder/server/locale.rb +42 -0
- data/lib/locomotive/builder/server/middleware.rb +54 -0
- data/lib/locomotive/builder/server/not_found.rb +18 -0
- data/lib/locomotive/builder/server/page.rb +59 -0
- data/lib/locomotive/builder/server/path.rb +34 -0
- data/lib/locomotive/builder/server/renderer.rb +105 -0
- data/lib/locomotive/builder/server/templatized_page.rb +32 -0
- data/lib/locomotive/builder/server.rb +78 -0
- data/lib/locomotive/builder/standalone_server.rb +33 -0
- data/lib/locomotive/builder/version.rb +5 -0
- data/lib/locomotive/builder.rb +167 -0
- data/locales/de.yml +143 -0
- data/locales/en.yml +164 -0
- data/locales/es.yml +119 -0
- data/locales/et.yml +140 -0
- data/locales/fr.yml +133 -0
- data/locales/it.yml +141 -0
- data/locales/nb.yml +177 -0
- data/locales/nl.yml +148 -0
- data/locales/pl.yml +189 -0
- data/locales/pt-BR.yml +125 -0
- data/locales/ru.yml +210 -0
- data/locomotivecms_builder.gemspec +42 -0
- data/spec/integration/cassettes/pull.yml +590 -0
- data/spec/integration/cassettes/push.yml +775 -0
- data/spec/integration/integration_helper.rb +15 -0
- data/spec/integration/server_spec.rb +37 -0
- data/spec/integration/sites_spec.rb +27 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/helpers.rb +13 -0
- metadata +468 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Filters
|
|
5
|
+
module Translate
|
|
6
|
+
|
|
7
|
+
def translate(key, locale = nil)
|
|
8
|
+
translation = @context.registers[:mounting_point].translations[key.to_s]
|
|
9
|
+
|
|
10
|
+
if translation
|
|
11
|
+
translation.get(locale) || translation.get(Locomotive::Mounter.locale)
|
|
12
|
+
else
|
|
13
|
+
"[unknown translation key: #{key}]"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
::Liquid::Template.register_filter(Translate)
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Liquid
|
|
2
|
+
|
|
3
|
+
class Drop
|
|
4
|
+
|
|
5
|
+
def mounting_point
|
|
6
|
+
@context.registers[:mounting_point]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def site
|
|
10
|
+
@context.registers[:site]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Template
|
|
16
|
+
|
|
17
|
+
# creates a new <tt>Template</tt> object from liquid source code
|
|
18
|
+
def parse_with_utf8(source, context = {})
|
|
19
|
+
if RUBY_VERSION =~ /1\.9/
|
|
20
|
+
source = source.force_encoding('UTF-8') if source.present?
|
|
21
|
+
end
|
|
22
|
+
self.parse_without_utf8(source, context)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
alias_method_chain :parse, :utf8
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module StandardFilters
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def to_number(obj)
|
|
34
|
+
case obj
|
|
35
|
+
when Numeric
|
|
36
|
+
obj
|
|
37
|
+
when String
|
|
38
|
+
(obj.strip =~ /^\d+\.\d+$/) ? obj.to_f : obj.to_i
|
|
39
|
+
when DateTime, Date, Time
|
|
40
|
+
obj.to_time.to_i
|
|
41
|
+
else
|
|
42
|
+
0
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
|
|
6
|
+
# Consume web services as easy as pie directly in liquid !
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
#
|
|
10
|
+
# {% consume blog from 'http://nocoffee.tumblr.com/api/read.json?num=3' username: 'john', password: 'easy', format: 'json', expires_in: 3000 %}
|
|
11
|
+
# {% for post in blog.posts %}
|
|
12
|
+
# {{ post.title }}
|
|
13
|
+
# {% endfor %}
|
|
14
|
+
# {% endconsume %}
|
|
15
|
+
#
|
|
16
|
+
class Consume < ::Liquid::Block
|
|
17
|
+
|
|
18
|
+
Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}+)/
|
|
19
|
+
|
|
20
|
+
def initialize(tag_name, markup, tokens, context)
|
|
21
|
+
if markup =~ Syntax
|
|
22
|
+
@target = $1
|
|
23
|
+
@url = $2.gsub(/['"]/, '')
|
|
24
|
+
@options = {}
|
|
25
|
+
markup.scan(::Liquid::TagAttributes) do |key, value|
|
|
26
|
+
@options[key] = value if key != 'http'
|
|
27
|
+
end
|
|
28
|
+
@options.delete('expires_in')
|
|
29
|
+
else
|
|
30
|
+
raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume <var> from \"<url>\" [username: value, password: value]")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def render(context)
|
|
37
|
+
context.stack do
|
|
38
|
+
_response = nil
|
|
39
|
+
|
|
40
|
+
begin
|
|
41
|
+
_response = Locomotive::Builder::Httparty::Webservice.consume(@url, @options.symbolize_keys)
|
|
42
|
+
rescue Exception => e
|
|
43
|
+
_response = { 'error' => e.message.to_s }.to_liquid
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context.scopes.last[@target.to_s] = _response
|
|
47
|
+
|
|
48
|
+
render_all(@nodelist, context)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
::Liquid::Template.register_tag('consume', Consume)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
module Csrf
|
|
6
|
+
|
|
7
|
+
class Param < ::Liquid::Tag
|
|
8
|
+
|
|
9
|
+
def render(context)
|
|
10
|
+
%{<input type="hidden" name="authenticity_token" value="helloworld" />}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Meta < ::Liquid::Tag
|
|
16
|
+
|
|
17
|
+
def render(context)
|
|
18
|
+
%{
|
|
19
|
+
<meta name="csrf-param" content="authenticity_token" />
|
|
20
|
+
<meta name="csrf-token" content="helloworld" />
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
::Liquid::Template.register_tag('csrf_param', Csrf::Param)
|
|
29
|
+
::Liquid::Template.register_tag('csrf_meta', Csrf::Meta)
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
module Editable
|
|
6
|
+
class Base < ::Liquid::Block
|
|
7
|
+
|
|
8
|
+
Syntax = /(#{::Liquid::QuotedFragment})(\s*,\s*#{::Liquid::Expression}+)?/
|
|
9
|
+
|
|
10
|
+
def initialize(tag_name, markup, tokens, context)
|
|
11
|
+
if markup =~ Syntax
|
|
12
|
+
@slug = $1.gsub(/[\"\']/, '')
|
|
13
|
+
@options = {}
|
|
14
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/^'/, '').gsub(/'$/, '') }
|
|
15
|
+
else
|
|
16
|
+
raise ::Liquid::SyntaxError.new("Syntax Error in 'editable_xxx' - Valid syntax: editable_xxx <slug>(, <options>)")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
super
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def render(context)
|
|
23
|
+
current_page = context.registers[:page]
|
|
24
|
+
|
|
25
|
+
element = current_page.find_editable_element(context['block'].try(:name), @slug)
|
|
26
|
+
|
|
27
|
+
if element.present?
|
|
28
|
+
render_element(context, element)
|
|
29
|
+
else
|
|
30
|
+
super
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
|
|
36
|
+
def render_element(context, element)
|
|
37
|
+
element.content
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
module Editable
|
|
6
|
+
class Control < Base
|
|
7
|
+
|
|
8
|
+
def render(context)
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
::Liquid::Template.register_tag('editable_control', Control)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
require 'locomotive/builder/liquid/tags/editable/base'
|
|
2
|
+
require 'locomotive/builder/liquid/tags/editable/short_text'
|
|
3
|
+
require 'locomotive/builder/liquid/tags/editable/long_text'
|
|
4
|
+
require 'locomotive/builder/liquid/tags/editable/file'
|
|
5
|
+
require 'locomotive/builder/liquid/tags/editable/control'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
class Extends < ::Liquid::Extends
|
|
6
|
+
|
|
7
|
+
def parse_parent_template
|
|
8
|
+
mounting_point = @context[:mounting_point]
|
|
9
|
+
|
|
10
|
+
page = if @template_name == 'parent'
|
|
11
|
+
@context[:page].parent
|
|
12
|
+
else
|
|
13
|
+
mounting_point.pages[@template_name]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
::Liquid::Template.parse(page.source, { mounting_point: mounting_point, page: page })
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
::Liquid::Template.register_tag('extends', Extends)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
class GoogleAnalytics < ::Liquid::Tag
|
|
6
|
+
|
|
7
|
+
Syntax = /(#{::Liquid::Expression}+)?/
|
|
8
|
+
|
|
9
|
+
def initialize(tag_name, markup, tokens, context)
|
|
10
|
+
if markup =~ Syntax
|
|
11
|
+
@account_id = $1.gsub('\'', '')
|
|
12
|
+
else
|
|
13
|
+
raise ::Liquid::SyntaxError.new("Syntax Error in 'google_analytics' - Valid syntax: google_analytics <account_id>")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def render(context)
|
|
20
|
+
"<!-- google analytics for #{@account_id} -->"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
::Liquid::Template.register_tag('google_analytics', GoogleAnalytics)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
module Locomotive
|
|
2
|
+
module Builder
|
|
3
|
+
module Liquid
|
|
4
|
+
module Tags
|
|
5
|
+
# Display the links to change the locale of the current page
|
|
6
|
+
#
|
|
7
|
+
# Usage:
|
|
8
|
+
#
|
|
9
|
+
# {% locale_switcher %} => <div id="locale-switcher"><a href="/features" class="current en">Features</a><a href="/fr/fonctionnalites" class="fr">Fonctionnalités</a></div>
|
|
10
|
+
#
|
|
11
|
+
# {% locale_switcher label: locale, sep: ' - ' }
|
|
12
|
+
#
|
|
13
|
+
# options:
|
|
14
|
+
# - label: iso (de, fr, en, ...etc), locale (Deutsch, Français, English, ...etc), title (page title)
|
|
15
|
+
# - sep: piece of html code separating 2 locales
|
|
16
|
+
#
|
|
17
|
+
# notes:
|
|
18
|
+
# - "iso" is the default choice for label
|
|
19
|
+
# - " | " is the default separating code
|
|
20
|
+
#
|
|
21
|
+
class LocaleSwitcher < ::Liquid::Tag
|
|
22
|
+
|
|
23
|
+
Syntax = /(#{::Liquid::Expression}+)?/
|
|
24
|
+
|
|
25
|
+
def initialize(tag_name, markup, tokens, context)
|
|
26
|
+
@options = { label: 'iso', sep: ' | ' }
|
|
27
|
+
|
|
28
|
+
if markup =~ Syntax
|
|
29
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
|
30
|
+
|
|
31
|
+
@options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
|
|
32
|
+
else
|
|
33
|
+
raise ::Liquid::SyntaxError.new("Syntax Error in 'locale_switcher' - Valid syntax: locale_switcher <options>")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def render(context)
|
|
40
|
+
@site, @page = context.registers[:site], context.registers[:page]
|
|
41
|
+
@default_locale = context.registers[:mounting_point].default_locale
|
|
42
|
+
|
|
43
|
+
output = %(<div id="locale-switcher">)
|
|
44
|
+
|
|
45
|
+
output += @site.locales.collect do |locale|
|
|
46
|
+
Locomotive::Mounter.with_locale(locale) do
|
|
47
|
+
fullpath = localized_fullpath(locale)
|
|
48
|
+
|
|
49
|
+
if @page.templatized?
|
|
50
|
+
permalink = context['entry']._permalink
|
|
51
|
+
|
|
52
|
+
if permalink
|
|
53
|
+
fullpath.gsub!('*', permalink)
|
|
54
|
+
else
|
|
55
|
+
fullpath = '404'
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
css = link_class(locale, context['locale'])
|
|
60
|
+
|
|
61
|
+
%(<a href="/#{fullpath}" class="#{css}">#{link_label(locale)}</a>)
|
|
62
|
+
end
|
|
63
|
+
end.join(@options[:sep])
|
|
64
|
+
|
|
65
|
+
output += %(</div>)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def link_class(locale, current_locale)
|
|
71
|
+
css = [locale]
|
|
72
|
+
css << 'current' if locale.to_s == current_locale.to_s
|
|
73
|
+
css.join(' ')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def link_label(locale)
|
|
77
|
+
case @options[:label]
|
|
78
|
+
when 'iso' then locale
|
|
79
|
+
when 'locale' then I18n.t("locomotive.locales.#{locale}", locale: locale)
|
|
80
|
+
when 'title' then @page.title # FIXME: this returns nil if the page has not been translated in the locale
|
|
81
|
+
else
|
|
82
|
+
locale
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def localized_fullpath(locale)
|
|
87
|
+
# @site.localized_page_fullpath(@page, locale)
|
|
88
|
+
|
|
89
|
+
return nil if @page.fullpath_translations.blank?
|
|
90
|
+
|
|
91
|
+
fullpath = @page.safe_fullpath || @page.fullpath_or_default
|
|
92
|
+
|
|
93
|
+
if locale.to_s == @default_locale.to_s # no need to specify the locale
|
|
94
|
+
@page.index? ? '' : fullpath
|
|
95
|
+
elsif @page.index? # avoid /en/index or /fr/index, prefer /en or /fr instead
|
|
96
|
+
locale
|
|
97
|
+
else
|
|
98
|
+
File.join(locale, fullpath)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
::Liquid::Template.register_tag('locale_switcher', LocaleSwitcher)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
# module Locomotive
|
|
110
|
+
# module Builder
|
|
111
|
+
# module Liquid
|
|
112
|
+
# module Tags
|
|
113
|
+
|
|
114
|
+
# # Display the links to change the locale of the current page
|
|
115
|
+
# #
|
|
116
|
+
# # Usage:
|
|
117
|
+
# #
|
|
118
|
+
# # {% locale_switcher %} => <div id="locale-switcher"><a href="/features" class="current en">Features</a><a href="/fr/fonctionnalites" class="fr">Fonctionnalités</a></div>
|
|
119
|
+
# #
|
|
120
|
+
# # {% locale_switcher label: locale, sep: ' - ' }
|
|
121
|
+
# #
|
|
122
|
+
# # options:
|
|
123
|
+
# # - label: iso (de, fr, en, ...etc), locale (Deutsch, Français, English, ...etc), title (page title)
|
|
124
|
+
# # - sep: piece of html code separating 2 locales
|
|
125
|
+
# #
|
|
126
|
+
# # notes:
|
|
127
|
+
# # - "iso" is the default choice for label
|
|
128
|
+
# # - " | " is the default separating code
|
|
129
|
+
# #
|
|
130
|
+
# class LocaleSwitcher < ::Liquid::Tag
|
|
131
|
+
|
|
132
|
+
# Syntax = /(#{::Liquid::Expression}+)?/
|
|
133
|
+
|
|
134
|
+
# def initialize(tag_name, markup, tokens, context)
|
|
135
|
+
# @options = { label: 'iso', sep: ' | ' }
|
|
136
|
+
|
|
137
|
+
# if markup =~ Syntax
|
|
138
|
+
# markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
|
139
|
+
|
|
140
|
+
# @options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
|
|
141
|
+
# else
|
|
142
|
+
# raise ::Liquid::SyntaxError.new("Syntax Error in 'locale_switcher' - Valid syntax: locale_switcher <options>")
|
|
143
|
+
# end
|
|
144
|
+
|
|
145
|
+
# super
|
|
146
|
+
# end
|
|
147
|
+
|
|
148
|
+
# def render(context)
|
|
149
|
+
# @site, @page = context.registers[:site], context.registers[:page]
|
|
150
|
+
|
|
151
|
+
# output = %(<div id="locale-switcher">)
|
|
152
|
+
|
|
153
|
+
# output += @site.locales.collect do |locale|
|
|
154
|
+
# fullpath = locale.to_s == context['default_locale'].to_s ? '/' : locale
|
|
155
|
+
|
|
156
|
+
# %(<a href="/#{fullpath}" class="#{locale} #{'current' if locale.to_s == context['default_locale'].to_s}">#{link_label(locale)}</a>)
|
|
157
|
+
# end.join(@options[:sep])
|
|
158
|
+
|
|
159
|
+
# output += %(</div>)
|
|
160
|
+
# end
|
|
161
|
+
|
|
162
|
+
# private
|
|
163
|
+
|
|
164
|
+
# def link_label(locale)
|
|
165
|
+
# case @options[:label]
|
|
166
|
+
# when :iso then locale
|
|
167
|
+
# when :locale then I18n.t("locomotive.locales.#{locale}", locale: locale)
|
|
168
|
+
# when :title then @page.title # FIXME: this returns nil if the page has not been translated in the locale
|
|
169
|
+
# else
|
|
170
|
+
# locale
|
|
171
|
+
# end
|
|
172
|
+
# end
|
|
173
|
+
|
|
174
|
+
# end
|
|
175
|
+
|
|
176
|
+
# ::Liquid::Template.register_tag('locale_switcher', LocaleSwitcher)
|
|
177
|
+
# end
|
|
178
|
+
# end
|
|
179
|
+
# end
|
|
180
|
+
# end
|