puffer_pages 0.1.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +3 -1
- data/.rvmrc +1 -1
- data/.travis.yml +13 -5
- data/CHANGELOG.md +130 -7
- data/Gemfile +10 -1
- data/README.md +18 -20
- data/Rakefile +1 -1
- data/app/assets/javascripts/puffer/codemirror.js +4237 -2223
- data/app/assets/javascripts/puffer/codemirror/css.js +359 -18
- data/app/assets/javascripts/puffer/codemirror/htmlmixed.js +15 -14
- data/app/assets/javascripts/puffer/codemirror/javascript.js +91 -29
- data/app/assets/javascripts/puffer/codemirror/liquid.js +185 -0
- data/app/assets/javascripts/puffer/codemirror/xml.js +99 -27
- data/app/assets/javascripts/puffer/codemirror/yaml.js +95 -0
- data/app/assets/javascripts/puffer/liquid.js +28 -12
- data/app/assets/javascripts/puffer/matchbrackets.js +63 -0
- data/app/assets/javascripts/puffer/multiplex.js +95 -0
- data/app/assets/javascripts/puffer/puffer_pages.js +140 -44
- data/app/assets/stylesheets/puffer/codemirror.css +203 -67
- data/app/assets/stylesheets/puffer/codemirror/ambiance-mobile.css +6 -0
- data/app/assets/stylesheets/puffer/codemirror/ambiance.css +76 -0
- data/app/assets/stylesheets/puffer/codemirror/blackboard.css +25 -0
- data/app/assets/stylesheets/puffer/codemirror/cobalt.css +4 -4
- data/app/assets/stylesheets/puffer/codemirror/eclipse.css +1 -1
- data/app/assets/stylesheets/puffer/codemirror/elegant.css +2 -2
- data/app/assets/stylesheets/puffer/codemirror/erlang-dark.css +21 -0
- data/app/assets/stylesheets/puffer/codemirror/lesser-dark.css +44 -0
- data/app/assets/stylesheets/puffer/codemirror/monokai.css +4 -4
- data/app/assets/stylesheets/puffer/codemirror/neat.css +3 -3
- data/app/assets/stylesheets/puffer/codemirror/night.css +4 -4
- data/app/assets/stylesheets/puffer/codemirror/rubyblue.css +5 -5
- data/app/assets/stylesheets/puffer/codemirror/solarized.css +207 -0
- data/app/assets/stylesheets/puffer/codemirror/twilight.css +26 -0
- data/app/assets/stylesheets/puffer/codemirror/vibrant-ink.css +27 -0
- data/app/assets/stylesheets/puffer/codemirror/xq-dark.css +46 -0
- data/app/assets/stylesheets/puffer/puffer_pages.css +64 -35
- data/app/components/codemirror/form.html.erb +22 -6
- data/app/components/codemirror_component.rb +1 -8
- data/app/components/handlers/form.html.erb +8 -0
- data/app/components/handlers_component.rb +8 -0
- data/app/components/page_parts/_page_part.html.erb +6 -0
- data/app/components/page_parts/form.html.erb +8 -27
- data/app/components/page_parts_component.rb +1 -3
- data/app/components/render/_tree_page.html.erb +3 -2
- data/app/controllers/admin/layouts_controller.rb +1 -1
- data/app/controllers/admin/origins_controller.rb +3 -0
- data/app/controllers/admin/pages_controller.rb +1 -1
- data/app/controllers/admin/snippets_controller.rb +1 -1
- data/app/controllers/pages_controller.rb +3 -3
- data/app/helpers/puffer_pages_helper.rb +3 -3
- data/app/models/puffer_pages/layout.rb +2 -7
- data/app/models/puffer_pages/origin.rb +2 -0
- data/app/models/puffer_pages/page.rb +1 -117
- data/app/models/puffer_pages/page_part.rb +2 -22
- data/app/models/puffer_pages/snippet.rb +2 -5
- data/config/routes.rb +3 -0
- data/db/migrate/20120812100913_create_origins.rb +16 -0
- data/db/migrate/20120924120226_migrate_to_uuid.rb +126 -0
- data/db/migrate/20130110144030_add_handler_to_page_parts.rb +9 -0
- data/db/migrate/20130118064524_add_locales_to_pages.rb +9 -0
- data/gemfiles/Gemfile.rails-3-1 +7 -0
- data/gemfiles/Gemfile.rails-3-2 +7 -0
- data/gemfiles/Gemfile.rails-head +7 -0
- data/lib/puffer_pages.rb +43 -7
- data/lib/puffer_pages/backends.rb +16 -0
- data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/layouts_base.rb +2 -5
- data/lib/puffer_pages/backends/controllers/origins_base.rb +43 -0
- data/lib/puffer_pages/backends/controllers/pages_base.rb +52 -0
- data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/snippets_base.rb +2 -5
- data/lib/puffer_pages/backends/models/layout.rb +34 -0
- data/lib/puffer_pages/backends/models/mixins/importable.rb +42 -0
- data/lib/puffer_pages/backends/models/mixins/localable.rb +65 -0
- data/lib/puffer_pages/backends/models/mixins/renderable.rb +153 -0
- data/lib/puffer_pages/backends/models/mixins/translatable.rb +52 -0
- data/lib/puffer_pages/backends/models/origin.rb +59 -0
- data/lib/puffer_pages/backends/models/page.rb +221 -0
- data/lib/puffer_pages/backends/models/page_part.rb +71 -0
- data/lib/puffer_pages/backends/models/snippet.rb +34 -0
- data/lib/puffer_pages/engine.rb +13 -2
- data/lib/puffer_pages/extensions/context.rb +31 -0
- data/lib/puffer_pages/extensions/core.rb +1 -8
- data/lib/puffer_pages/extensions/pagenator.rb +69 -0
- data/lib/puffer_pages/extensions/renderer.rb +31 -0
- data/lib/puffer_pages/globalize/migrator.rb +23 -0
- data/lib/puffer_pages/handlers.rb +29 -0
- data/lib/puffer_pages/handlers/base.rb +21 -0
- data/lib/puffer_pages/handlers/yaml.rb +20 -0
- data/lib/puffer_pages/helpers.rb +14 -0
- data/lib/puffer_pages/liquid/backend.rb +16 -0
- data/lib/puffer_pages/liquid/file_system.rb +36 -12
- data/lib/puffer_pages/liquid/page_drop.rb +26 -23
- data/lib/puffer_pages/liquid/tags/array.rb +39 -0
- data/lib/puffer_pages/liquid/tags/{javascripts.rb → assets.rb} +13 -4
- data/lib/puffer_pages/liquid/tags/helper.rb +15 -0
- data/lib/puffer_pages/liquid/tags/include.rb +32 -0
- data/lib/puffer_pages/liquid/tags/javascript.rb +15 -0
- data/lib/puffer_pages/liquid/tags/partials.rb +22 -0
- data/lib/puffer_pages/liquid/tags/render.rb +28 -0
- data/lib/puffer_pages/liquid/tags/scope.rb +31 -0
- data/lib/puffer_pages/liquid/tags/super.rb +36 -0
- data/lib/puffer_pages/liquid/tags/translate.rb +56 -0
- data/lib/puffer_pages/liquid/tags/url.rb +53 -0
- data/lib/puffer_pages/liquid/tags/yield.rb +3 -1
- data/lib/puffer_pages/log_subscriber.rb +29 -0
- data/lib/puffer_pages/migrations.rb +31 -0
- data/lib/puffer_pages/renderer.rb +25 -0
- data/lib/puffer_pages/rspec/matchers.rb +27 -0
- data/lib/puffer_pages/rspec/matchers/render_page.rb +90 -0
- data/lib/puffer_pages/version.rb +1 -1
- data/puffer_pages.gemspec +18 -18
- data/spec/controllers/pages_controller_spec.rb +44 -0
- data/spec/controllers/puffer_pages_controller_spec.rb +194 -0
- data/spec/data/broken.json +8 -0
- data/spec/data/import.json +55 -0
- data/spec/data/localized.json +106 -0
- data/spec/data/unlocalized.json +82 -0
- data/spec/dummy/.rvmrc +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +6 -0
- data/spec/dummy/app/views/layouts/sample.en.erb +1 -0
- data/spec/dummy/app/views/layouts/sample.ru.erb +1 -0
- data/spec/dummy/app/views/shared/_first.html.erb +1 -0
- data/spec/dummy/config/application.rb +21 -2
- data/spec/dummy/config/boot.rb +0 -2
- data/spec/dummy/config/database.yml +7 -1
- data/spec/dummy/config/environments/development.rb +11 -2
- data/spec/dummy/config/environments/pg_test.rb +6 -6
- data/spec/dummy/config/environments/production.rb +19 -3
- data/spec/dummy/config/environments/test.rb +6 -6
- data/spec/dummy/config/initializers/inflections.rb +5 -0
- data/spec/dummy/config/initializers/puffer_pages.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +5 -3
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/db/migrate/{20090422092419_create_pages.rb → 20130118071511_create_pages.rb} +1 -0
- data/spec/dummy/db/migrate/{20090504132337_create_page_parts.rb → 20130118071512_create_page_parts.rb} +1 -0
- data/spec/dummy/db/migrate/{20090506102004_create_layouts.rb → 20130118071513_create_layouts.rb} +1 -0
- data/spec/dummy/db/migrate/{20090510121824_create_snippets.rb → 20130118071514_create_snippets.rb} +1 -0
- data/spec/dummy/db/migrate/20130118071515_create_origins.rb +17 -0
- data/spec/dummy/db/migrate/20130118071516_migrate_to_uuid.rb +127 -0
- data/spec/dummy/db/migrate/20130118071517_add_handler_to_page_parts.rb +10 -0
- data/spec/dummy/db/migrate/20130118071518_add_locales_to_pages.rb +10 -0
- data/spec/dummy/db/migrate/20130118071519_add_translations.rb +9 -0
- data/spec/dummy/db/schema.rb +65 -17
- data/spec/fabricators/articles_fabricator.rb +2 -2
- data/spec/fabricators/layouts_fabricator.rb +24 -3
- data/spec/fabricators/origin_fabricator.rb +5 -0
- data/spec/fabricators/page_parts_fabricator.rb +17 -2
- data/spec/fabricators/pages_fabricator.rb +20 -5
- data/spec/fabricators/snippets_fabricator.rb +14 -3
- data/spec/lib/handlers/base_spec.rb +10 -0
- data/spec/lib/handlers/yaml_spec.rb +34 -0
- data/spec/lib/handlers_spec.rb +36 -0
- data/spec/lib/liquid/backend_spec.rb +20 -0
- data/spec/lib/liquid/interpolation_spec.rb +25 -0
- data/spec/lib/liquid/tags/include_spec.rb +38 -0
- data/spec/lib/liquid/tags/partials_spec.rb +39 -0
- data/spec/lib/liquid/tags/scope_spec.rb +18 -0
- data/spec/lib/liquid/tags/translate_spec.rb +107 -0
- data/spec/lib/liquid/tags_spec.rb +81 -0
- data/spec/lib/page_drop_spec.rb +65 -0
- data/spec/lib/pagenator_spec.rb +176 -0
- data/spec/lib/rspec/matchers/render_page_spec.rb +107 -0
- data/spec/models/puffer_pages/layout_spec.rb +15 -0
- data/spec/models/puffer_pages/localable_spec.rb +62 -0
- data/spec/models/puffer_pages/origin_spec.rb +112 -0
- data/spec/models/puffer_pages/page_part_spec.rb +14 -0
- data/spec/models/puffer_pages/page_spec.rb +307 -0
- data/spec/models/puffer_pages/renderable_spec.rb +84 -0
- data/spec/models/puffer_pages/snippet_spec.rb +15 -0
- data/spec/requests/origins_requests_spec.rb +37 -0
- data/spec/spec_helper.rb +7 -6
- metadata +349 -87
- data/Gemfile.lock +0 -176
- data/app/assets/javascripts/puffer/overlay.js +0 -51
- data/app/controllers/puffer_pages/pages_base.rb +0 -38
- data/app/models/layout.rb +0 -2
- data/app/models/page.rb +0 -2
- data/app/models/page_part.rb +0 -2
- data/app/models/snippet.rb +0 -2
- data/app/views/layouts/puffer_pages_layout.html.erb +0 -2
- data/config/puffer_routes.rb +0 -3
- data/gemfiles/Gemfile-rails-3.1 +0 -5
- data/gemfiles/Gemfile-rails-3.1.lock +0 -173
- data/gemfiles/Gemfile-rails-3.2 +0 -5
- data/gemfiles/Gemfile-rails-3.2.lock +0 -171
- data/lib/puffer_pages/extensions/controller.rb +0 -30
- data/lib/puffer_pages/extensions/mapper.rb +0 -23
- data/lib/puffer_pages/liquid/tags/page_attribute.rb +0 -39
- data/lib/puffer_pages/liquid/tags/stylesheets.rb +0 -38
- data/spec/controllers/articles_controller_spec.rb +0 -65
- data/spec/dummy/app/controllers/articles_controller.rb +0 -9
- data/spec/integration/navigation_spec.rb +0 -9
- data/spec/lib/drops_spec.rb +0 -55
- data/spec/lib/tags_spec.rb +0 -98
- data/spec/models/page_spec.rb +0 -235
- data/spec/puffer_pages_spec.rb +0 -7
@@ -2,14 +2,14 @@ module PufferPages
|
|
2
2
|
module Liquid
|
3
3
|
module Tags
|
4
4
|
|
5
|
-
class
|
5
|
+
class Assets < ::Liquid::Tag
|
6
6
|
Syntax = /^(#{::Liquid::QuotedFragment}+)/
|
7
7
|
|
8
8
|
def initialize(tag_name, markup, tokens)
|
9
9
|
if markup =~ Syntax
|
10
10
|
@paths = variables_from_string(markup)
|
11
11
|
else
|
12
|
-
raise SyntaxError.new("Syntax Error in '
|
12
|
+
raise SyntaxError.new("Syntax Error in '#{tag_name}' - Valid syntax: #{tag_name} path [, path, path ...]")
|
13
13
|
end
|
14
14
|
|
15
15
|
super
|
@@ -17,7 +17,15 @@ module PufferPages
|
|
17
17
|
|
18
18
|
def render(context)
|
19
19
|
paths = @paths.map {|path| "'#{context[path]}'" }.join(', ')
|
20
|
-
|
20
|
+
|
21
|
+
erb = case @tag_name
|
22
|
+
when 'javascripts'
|
23
|
+
"<%= javascript_include_tag #{paths} %>"
|
24
|
+
when 'stylesheets'
|
25
|
+
"<%= stylesheet_link_tag #{paths} %>"
|
26
|
+
end
|
27
|
+
|
28
|
+
context.registers[:tracker].register(erb)
|
21
29
|
end
|
22
30
|
|
23
31
|
private
|
@@ -35,4 +43,5 @@ module PufferPages
|
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
38
|
-
Liquid::Template.register_tag('javascripts', PufferPages::Liquid::Tags::
|
46
|
+
Liquid::Template.register_tag('javascripts', PufferPages::Liquid::Tags::Assets)
|
47
|
+
Liquid::Template.register_tag('stylesheets', PufferPages::Liquid::Tags::Assets)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Helper < ::Liquid::Tag
|
6
|
+
def render(context)
|
7
|
+
context.registers[:tracker].register("<%= #{@tag_name} %>")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Liquid::Template.register_tag('csrf_meta_tags', PufferPages::Liquid::Tags::Helper)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Include < ::Liquid::Include
|
6
|
+
def render(context)
|
7
|
+
source = _read_template_from_file_system(context)
|
8
|
+
variable = context[@variable_name || @template_name[1..-2]]
|
9
|
+
|
10
|
+
context.stack do
|
11
|
+
@attributes.each do |key, value|
|
12
|
+
context[key] = context[value]
|
13
|
+
end
|
14
|
+
|
15
|
+
if variable.is_a?(Array)
|
16
|
+
variable.collect do |variable|
|
17
|
+
context[@template_name[1..-2]] = variable
|
18
|
+
source.render(context)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
context[@template_name[1..-2]] = variable
|
22
|
+
source.render(context)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Liquid::Template.register_tag('include', PufferPages::Liquid::Tags::Include)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Javascript < ::Liquid::Block
|
6
|
+
def render(context)
|
7
|
+
context.registers[:tracker].register("<%= javascript_tag do %>#{super}<% end %>")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Liquid::Template.register_tag('javascript', PufferPages::Liquid::Tags::Javascript)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Partials < Include
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def _read_template_from_file_system(context)
|
10
|
+
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
11
|
+
template_name = "#{@tag_name.pluralize}/#{context[@template_name]}"
|
12
|
+
|
13
|
+
file_system.read_template_file(template_name, context)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Liquid::Template.register_tag('snippet', PufferPages::Liquid::Tags::Partials)
|
22
|
+
Liquid::Template.register_tag('layout', PufferPages::Liquid::Tags::Partials)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Render < ::Liquid::Tag
|
6
|
+
Syntax = /^(#{::Liquid::QuotedFragment})/
|
7
|
+
|
8
|
+
def initialize(tag_name, markup, tokens)
|
9
|
+
if markup =~ Syntax
|
10
|
+
@path = $1
|
11
|
+
else
|
12
|
+
raise SyntaxError.new("Syntax Error in 'render' - Valid syntax: render path")
|
13
|
+
end
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def render(context)
|
19
|
+
path = context[@path]
|
20
|
+
context.registers[:tracker].register("<%= render '#{path}' %>")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Liquid::Template.register_tag('render', PufferPages::Liquid::Tags::Render)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Scope < ::Liquid::Block
|
6
|
+
def initialize(tag_name, markup, tokens)
|
7
|
+
@attributes = {}
|
8
|
+
markup.scan(::Liquid::TagAttributes) do |key, value|
|
9
|
+
@attributes[key] = value
|
10
|
+
end
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(context)
|
16
|
+
context.stack do
|
17
|
+
@attributes.each do |key, value|
|
18
|
+
context[key] = context[value]
|
19
|
+
end
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Liquid::Template.register_tag('scope', PufferPages::Liquid::Tags::Scope)
|
31
|
+
Liquid::Template.register_tag('context', PufferPages::Liquid::Tags::Scope)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Super < ::Liquid::Include
|
6
|
+
def initialize(tag_name, markup, tokens)
|
7
|
+
@attributes = {}
|
8
|
+
markup.scan(::Liquid::TagAttributes) do |key, value|
|
9
|
+
@attributes[key] = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(context)
|
14
|
+
source = _read_template_from_file_system(context)
|
15
|
+
|
16
|
+
context.stack do
|
17
|
+
@attributes.each do |key, value|
|
18
|
+
context[key] = context[value]
|
19
|
+
end
|
20
|
+
|
21
|
+
source.render(context)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def _read_template_from_file_system(context)
|
27
|
+
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
28
|
+
file_system.read_template_file(:super, context)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Liquid::Template.register_tag('super', PufferPages::Liquid::Tags::Super)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Translate < ::Liquid::Tag
|
6
|
+
Syntax = /^(#{::Liquid::QuotedFragment})/
|
7
|
+
|
8
|
+
def initialize(tag_name, markup, tokens)
|
9
|
+
if markup =~ Syntax
|
10
|
+
@key = $1
|
11
|
+
else
|
12
|
+
raise SyntaxError.new("Syntax Error in 'translate' - Valid syntax: translate key")
|
13
|
+
end
|
14
|
+
|
15
|
+
@options = {}
|
16
|
+
markup.scan(::Liquid::TagAttributes) do |key, value|
|
17
|
+
@options[key.to_sym] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(context)
|
24
|
+
key = context[@key]
|
25
|
+
options = @options.each_with_object({}) do |(name, value), result|
|
26
|
+
result[name] = context[value] unless I18n::RESERVED_KEYS.include?(name)
|
27
|
+
end
|
28
|
+
processed = context[:processed]
|
29
|
+
|
30
|
+
if processed && key.first == '.'
|
31
|
+
I18n.translate i18n_key(processed, key.last(-1)),
|
32
|
+
options.merge!(:default => i18n_defaults(processed, key.last(-1)))
|
33
|
+
else
|
34
|
+
I18n.translate key, options
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def i18n_key(processed, key)
|
39
|
+
array_to_key processed.i18n_scope, key
|
40
|
+
end
|
41
|
+
|
42
|
+
def i18n_defaults(processed, key)
|
43
|
+
processed.i18n_defaults.map { |default| array_to_key default, key }
|
44
|
+
end
|
45
|
+
|
46
|
+
def array_to_key *array
|
47
|
+
array.flatten.map { |segment| segment.to_s.gsub(?., ?/) }.join(?.).to_sym
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Liquid::Template.register_tag('translate', PufferPages::Liquid::Tags::Translate)
|
56
|
+
Liquid::Template.register_tag('t', PufferPages::Liquid::Tags::Translate)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Url < ::Liquid::Tag
|
6
|
+
Syntax = /^(#{::Liquid::VariableSignature}+)\s*(.*)\s*/
|
7
|
+
|
8
|
+
def initialize(tag_name, markup, tokens)
|
9
|
+
if markup =~ Syntax
|
10
|
+
|
11
|
+
@helper_name, @arguments, @attributes = $1, [], {}
|
12
|
+
|
13
|
+
@arguments = $2.split(',')
|
14
|
+
attributes = @arguments.pop if @arguments.last && @arguments.last.strip =~ /(#{::Liquid::TagAttributes})/
|
15
|
+
|
16
|
+
@arguments = @arguments.map do |var|
|
17
|
+
var.strip =~ /(#{::Liquid::QuotedFragment})/
|
18
|
+
$1 ? $1 : nil
|
19
|
+
end.compact
|
20
|
+
|
21
|
+
attributes.scan(::Liquid::TagAttributes) do |key, value|
|
22
|
+
@attributes[key] = value
|
23
|
+
end if attributes.present?
|
24
|
+
else
|
25
|
+
raise SyntaxError.new("Error in tag '#{tag_name}' - Valid syntax: #{tag_name} helper_name [object, object...] [, option:value option:value...]")
|
26
|
+
end
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def render(context)
|
32
|
+
key = context[@key]
|
33
|
+
arguments = @arguments.map do |argument|
|
34
|
+
argument = context[argument]
|
35
|
+
argument.to_param if argument.is_a?(::Liquid::Drop)
|
36
|
+
argument
|
37
|
+
end
|
38
|
+
attributes = @attributes.each_with_object({}) do |(name, value), result|
|
39
|
+
result[name.to_sym] = context[value]
|
40
|
+
end
|
41
|
+
attributes.merge(:path_only => true) if @tag_name == 'path'
|
42
|
+
|
43
|
+
context.registers[:controller].send("#{@helper_name}_#{@tag_name}", *arguments, attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Liquid::Template.register_tag('path', PufferPages::Liquid::Tags::Url)
|
53
|
+
Liquid::Template.register_tag('url', PufferPages::Liquid::Tags::Url)
|
@@ -18,7 +18,9 @@ module PufferPages
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def render(context)
|
21
|
-
context.registers[:tracker].register(@name ?
|
21
|
+
context.registers[:tracker].register(@name ?
|
22
|
+
"<%= yield :'#{@name}' %>" :
|
23
|
+
"<%= yield %>")
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PufferPages
|
2
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
3
|
+
def render_page event
|
4
|
+
message = " PufferPages: rendered page /#{event.payload[:subject].location} #{duration(event)}"
|
5
|
+
info message
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_page_part event
|
9
|
+
message = " PufferPages: rendered page_part #{event.payload[:subject].name} #{duration(event)}"
|
10
|
+
debug message
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_layout event
|
14
|
+
message = " PufferPages: rendered layout #{event.payload[:subject].name} #{duration(event)}"
|
15
|
+
debug message
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_snippet event
|
19
|
+
message = " PufferPages: rendered snippet #{event.payload[:subject].name} #{duration(event)}"
|
20
|
+
debug message
|
21
|
+
end
|
22
|
+
|
23
|
+
def duration event
|
24
|
+
'(%.1fms)' % event.duration
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
PufferPages::LogSubscriber.attach_to :puffer_pages
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Migrations
|
3
|
+
def self.create_translation_tables! options = {}
|
4
|
+
unless PufferPages.localize
|
5
|
+
puts "WARN: Translation tables creation skip. Set `PufferPages.localize = true` to perform it"
|
6
|
+
return
|
7
|
+
end
|
8
|
+
options = options.reverse_merge migrate_data: true
|
9
|
+
|
10
|
+
[PufferPages::PagePart, PufferPages::Layout, PufferPages::Snippet].each do |model|
|
11
|
+
model.create_translation_table!({
|
12
|
+
body: { type: :text }
|
13
|
+
}, options)
|
14
|
+
puts "-- Created translation table for #{model} with #{options}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.drop_translation_tables! options = {}
|
19
|
+
unless PufferPages.localize
|
20
|
+
puts "WARN: Translation tables dropping skip. Set `PufferPages.localize = true` to perform it"
|
21
|
+
return
|
22
|
+
end
|
23
|
+
options = options.reverse_merge migrate_data: true
|
24
|
+
|
25
|
+
[PufferPages::PagePart, PufferPages::Layout, PufferPages::Snippet].each do |model|
|
26
|
+
model.drop_translation_table! options
|
27
|
+
puts "-- Dropped translation table for #{model} with #{options}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PufferPages
|
2
|
+
class Renderer < ActionView::TemplateRenderer
|
3
|
+
def render(context, options)
|
4
|
+
@view = context
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def determine_template(options)
|
9
|
+
@view.assign(@view.assigns.merge!('puffer_page' => options[:puffer_page]))
|
10
|
+
|
11
|
+
super
|
12
|
+
rescue ActionView::MissingTemplate
|
13
|
+
options[:text] = ''
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_layout(layout, keys)
|
18
|
+
layout = "<%= render(:inline => @puffer_page.render(puffer_pages_context),
|
19
|
+
:layout => @puffer_page.layout_for_render) %>"
|
20
|
+
|
21
|
+
handler = ActionView::Template.handler_for_extension("erb")
|
22
|
+
ActionView::Template.new(layout, "puffer pages layout wrapper", handler, :locals => keys)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|