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.
Files changed (197) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +3 -1
  3. data/.rvmrc +1 -1
  4. data/.travis.yml +13 -5
  5. data/CHANGELOG.md +130 -7
  6. data/Gemfile +10 -1
  7. data/README.md +18 -20
  8. data/Rakefile +1 -1
  9. data/app/assets/javascripts/puffer/codemirror.js +4237 -2223
  10. data/app/assets/javascripts/puffer/codemirror/css.js +359 -18
  11. data/app/assets/javascripts/puffer/codemirror/htmlmixed.js +15 -14
  12. data/app/assets/javascripts/puffer/codemirror/javascript.js +91 -29
  13. data/app/assets/javascripts/puffer/codemirror/liquid.js +185 -0
  14. data/app/assets/javascripts/puffer/codemirror/xml.js +99 -27
  15. data/app/assets/javascripts/puffer/codemirror/yaml.js +95 -0
  16. data/app/assets/javascripts/puffer/liquid.js +28 -12
  17. data/app/assets/javascripts/puffer/matchbrackets.js +63 -0
  18. data/app/assets/javascripts/puffer/multiplex.js +95 -0
  19. data/app/assets/javascripts/puffer/puffer_pages.js +140 -44
  20. data/app/assets/stylesheets/puffer/codemirror.css +203 -67
  21. data/app/assets/stylesheets/puffer/codemirror/ambiance-mobile.css +6 -0
  22. data/app/assets/stylesheets/puffer/codemirror/ambiance.css +76 -0
  23. data/app/assets/stylesheets/puffer/codemirror/blackboard.css +25 -0
  24. data/app/assets/stylesheets/puffer/codemirror/cobalt.css +4 -4
  25. data/app/assets/stylesheets/puffer/codemirror/eclipse.css +1 -1
  26. data/app/assets/stylesheets/puffer/codemirror/elegant.css +2 -2
  27. data/app/assets/stylesheets/puffer/codemirror/erlang-dark.css +21 -0
  28. data/app/assets/stylesheets/puffer/codemirror/lesser-dark.css +44 -0
  29. data/app/assets/stylesheets/puffer/codemirror/monokai.css +4 -4
  30. data/app/assets/stylesheets/puffer/codemirror/neat.css +3 -3
  31. data/app/assets/stylesheets/puffer/codemirror/night.css +4 -4
  32. data/app/assets/stylesheets/puffer/codemirror/rubyblue.css +5 -5
  33. data/app/assets/stylesheets/puffer/codemirror/solarized.css +207 -0
  34. data/app/assets/stylesheets/puffer/codemirror/twilight.css +26 -0
  35. data/app/assets/stylesheets/puffer/codemirror/vibrant-ink.css +27 -0
  36. data/app/assets/stylesheets/puffer/codemirror/xq-dark.css +46 -0
  37. data/app/assets/stylesheets/puffer/puffer_pages.css +64 -35
  38. data/app/components/codemirror/form.html.erb +22 -6
  39. data/app/components/codemirror_component.rb +1 -8
  40. data/app/components/handlers/form.html.erb +8 -0
  41. data/app/components/handlers_component.rb +8 -0
  42. data/app/components/page_parts/_page_part.html.erb +6 -0
  43. data/app/components/page_parts/form.html.erb +8 -27
  44. data/app/components/page_parts_component.rb +1 -3
  45. data/app/components/render/_tree_page.html.erb +3 -2
  46. data/app/controllers/admin/layouts_controller.rb +1 -1
  47. data/app/controllers/admin/origins_controller.rb +3 -0
  48. data/app/controllers/admin/pages_controller.rb +1 -1
  49. data/app/controllers/admin/snippets_controller.rb +1 -1
  50. data/app/controllers/pages_controller.rb +3 -3
  51. data/app/helpers/puffer_pages_helper.rb +3 -3
  52. data/app/models/puffer_pages/layout.rb +2 -7
  53. data/app/models/puffer_pages/origin.rb +2 -0
  54. data/app/models/puffer_pages/page.rb +1 -117
  55. data/app/models/puffer_pages/page_part.rb +2 -22
  56. data/app/models/puffer_pages/snippet.rb +2 -5
  57. data/config/routes.rb +3 -0
  58. data/db/migrate/20120812100913_create_origins.rb +16 -0
  59. data/db/migrate/20120924120226_migrate_to_uuid.rb +126 -0
  60. data/db/migrate/20130110144030_add_handler_to_page_parts.rb +9 -0
  61. data/db/migrate/20130118064524_add_locales_to_pages.rb +9 -0
  62. data/gemfiles/Gemfile.rails-3-1 +7 -0
  63. data/gemfiles/Gemfile.rails-3-2 +7 -0
  64. data/gemfiles/Gemfile.rails-head +7 -0
  65. data/lib/puffer_pages.rb +43 -7
  66. data/lib/puffer_pages/backends.rb +16 -0
  67. data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/layouts_base.rb +2 -5
  68. data/lib/puffer_pages/backends/controllers/origins_base.rb +43 -0
  69. data/lib/puffer_pages/backends/controllers/pages_base.rb +52 -0
  70. data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/snippets_base.rb +2 -5
  71. data/lib/puffer_pages/backends/models/layout.rb +34 -0
  72. data/lib/puffer_pages/backends/models/mixins/importable.rb +42 -0
  73. data/lib/puffer_pages/backends/models/mixins/localable.rb +65 -0
  74. data/lib/puffer_pages/backends/models/mixins/renderable.rb +153 -0
  75. data/lib/puffer_pages/backends/models/mixins/translatable.rb +52 -0
  76. data/lib/puffer_pages/backends/models/origin.rb +59 -0
  77. data/lib/puffer_pages/backends/models/page.rb +221 -0
  78. data/lib/puffer_pages/backends/models/page_part.rb +71 -0
  79. data/lib/puffer_pages/backends/models/snippet.rb +34 -0
  80. data/lib/puffer_pages/engine.rb +13 -2
  81. data/lib/puffer_pages/extensions/context.rb +31 -0
  82. data/lib/puffer_pages/extensions/core.rb +1 -8
  83. data/lib/puffer_pages/extensions/pagenator.rb +69 -0
  84. data/lib/puffer_pages/extensions/renderer.rb +31 -0
  85. data/lib/puffer_pages/globalize/migrator.rb +23 -0
  86. data/lib/puffer_pages/handlers.rb +29 -0
  87. data/lib/puffer_pages/handlers/base.rb +21 -0
  88. data/lib/puffer_pages/handlers/yaml.rb +20 -0
  89. data/lib/puffer_pages/helpers.rb +14 -0
  90. data/lib/puffer_pages/liquid/backend.rb +16 -0
  91. data/lib/puffer_pages/liquid/file_system.rb +36 -12
  92. data/lib/puffer_pages/liquid/page_drop.rb +26 -23
  93. data/lib/puffer_pages/liquid/tags/array.rb +39 -0
  94. data/lib/puffer_pages/liquid/tags/{javascripts.rb → assets.rb} +13 -4
  95. data/lib/puffer_pages/liquid/tags/helper.rb +15 -0
  96. data/lib/puffer_pages/liquid/tags/include.rb +32 -0
  97. data/lib/puffer_pages/liquid/tags/javascript.rb +15 -0
  98. data/lib/puffer_pages/liquid/tags/partials.rb +22 -0
  99. data/lib/puffer_pages/liquid/tags/render.rb +28 -0
  100. data/lib/puffer_pages/liquid/tags/scope.rb +31 -0
  101. data/lib/puffer_pages/liquid/tags/super.rb +36 -0
  102. data/lib/puffer_pages/liquid/tags/translate.rb +56 -0
  103. data/lib/puffer_pages/liquid/tags/url.rb +53 -0
  104. data/lib/puffer_pages/liquid/tags/yield.rb +3 -1
  105. data/lib/puffer_pages/log_subscriber.rb +29 -0
  106. data/lib/puffer_pages/migrations.rb +31 -0
  107. data/lib/puffer_pages/renderer.rb +25 -0
  108. data/lib/puffer_pages/rspec/matchers.rb +27 -0
  109. data/lib/puffer_pages/rspec/matchers/render_page.rb +90 -0
  110. data/lib/puffer_pages/version.rb +1 -1
  111. data/puffer_pages.gemspec +18 -18
  112. data/spec/controllers/pages_controller_spec.rb +44 -0
  113. data/spec/controllers/puffer_pages_controller_spec.rb +194 -0
  114. data/spec/data/broken.json +8 -0
  115. data/spec/data/import.json +55 -0
  116. data/spec/data/localized.json +106 -0
  117. data/spec/data/unlocalized.json +82 -0
  118. data/spec/dummy/.rvmrc +1 -0
  119. data/spec/dummy/app/controllers/application_controller.rb +6 -0
  120. data/spec/dummy/app/views/layouts/sample.en.erb +1 -0
  121. data/spec/dummy/app/views/layouts/sample.ru.erb +1 -0
  122. data/spec/dummy/app/views/shared/_first.html.erb +1 -0
  123. data/spec/dummy/config/application.rb +21 -2
  124. data/spec/dummy/config/boot.rb +0 -2
  125. data/spec/dummy/config/database.yml +7 -1
  126. data/spec/dummy/config/environments/development.rb +11 -2
  127. data/spec/dummy/config/environments/pg_test.rb +6 -6
  128. data/spec/dummy/config/environments/production.rb +19 -3
  129. data/spec/dummy/config/environments/test.rb +6 -6
  130. data/spec/dummy/config/initializers/inflections.rb +5 -0
  131. data/spec/dummy/config/initializers/puffer_pages.rb +4 -0
  132. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  133. data/spec/dummy/config/initializers/wrap_parameters.rb +5 -3
  134. data/spec/dummy/config/routes.rb +2 -1
  135. data/spec/dummy/db/migrate/{20090422092419_create_pages.rb → 20130118071511_create_pages.rb} +1 -0
  136. data/spec/dummy/db/migrate/{20090504132337_create_page_parts.rb → 20130118071512_create_page_parts.rb} +1 -0
  137. data/spec/dummy/db/migrate/{20090506102004_create_layouts.rb → 20130118071513_create_layouts.rb} +1 -0
  138. data/spec/dummy/db/migrate/{20090510121824_create_snippets.rb → 20130118071514_create_snippets.rb} +1 -0
  139. data/spec/dummy/db/migrate/20130118071515_create_origins.rb +17 -0
  140. data/spec/dummy/db/migrate/20130118071516_migrate_to_uuid.rb +127 -0
  141. data/spec/dummy/db/migrate/20130118071517_add_handler_to_page_parts.rb +10 -0
  142. data/spec/dummy/db/migrate/20130118071518_add_locales_to_pages.rb +10 -0
  143. data/spec/dummy/db/migrate/20130118071519_add_translations.rb +9 -0
  144. data/spec/dummy/db/schema.rb +65 -17
  145. data/spec/fabricators/articles_fabricator.rb +2 -2
  146. data/spec/fabricators/layouts_fabricator.rb +24 -3
  147. data/spec/fabricators/origin_fabricator.rb +5 -0
  148. data/spec/fabricators/page_parts_fabricator.rb +17 -2
  149. data/spec/fabricators/pages_fabricator.rb +20 -5
  150. data/spec/fabricators/snippets_fabricator.rb +14 -3
  151. data/spec/lib/handlers/base_spec.rb +10 -0
  152. data/spec/lib/handlers/yaml_spec.rb +34 -0
  153. data/spec/lib/handlers_spec.rb +36 -0
  154. data/spec/lib/liquid/backend_spec.rb +20 -0
  155. data/spec/lib/liquid/interpolation_spec.rb +25 -0
  156. data/spec/lib/liquid/tags/include_spec.rb +38 -0
  157. data/spec/lib/liquid/tags/partials_spec.rb +39 -0
  158. data/spec/lib/liquid/tags/scope_spec.rb +18 -0
  159. data/spec/lib/liquid/tags/translate_spec.rb +107 -0
  160. data/spec/lib/liquid/tags_spec.rb +81 -0
  161. data/spec/lib/page_drop_spec.rb +65 -0
  162. data/spec/lib/pagenator_spec.rb +176 -0
  163. data/spec/lib/rspec/matchers/render_page_spec.rb +107 -0
  164. data/spec/models/puffer_pages/layout_spec.rb +15 -0
  165. data/spec/models/puffer_pages/localable_spec.rb +62 -0
  166. data/spec/models/puffer_pages/origin_spec.rb +112 -0
  167. data/spec/models/puffer_pages/page_part_spec.rb +14 -0
  168. data/spec/models/puffer_pages/page_spec.rb +307 -0
  169. data/spec/models/puffer_pages/renderable_spec.rb +84 -0
  170. data/spec/models/puffer_pages/snippet_spec.rb +15 -0
  171. data/spec/requests/origins_requests_spec.rb +37 -0
  172. data/spec/spec_helper.rb +7 -6
  173. metadata +349 -87
  174. data/Gemfile.lock +0 -176
  175. data/app/assets/javascripts/puffer/overlay.js +0 -51
  176. data/app/controllers/puffer_pages/pages_base.rb +0 -38
  177. data/app/models/layout.rb +0 -2
  178. data/app/models/page.rb +0 -2
  179. data/app/models/page_part.rb +0 -2
  180. data/app/models/snippet.rb +0 -2
  181. data/app/views/layouts/puffer_pages_layout.html.erb +0 -2
  182. data/config/puffer_routes.rb +0 -3
  183. data/gemfiles/Gemfile-rails-3.1 +0 -5
  184. data/gemfiles/Gemfile-rails-3.1.lock +0 -173
  185. data/gemfiles/Gemfile-rails-3.2 +0 -5
  186. data/gemfiles/Gemfile-rails-3.2.lock +0 -171
  187. data/lib/puffer_pages/extensions/controller.rb +0 -30
  188. data/lib/puffer_pages/extensions/mapper.rb +0 -23
  189. data/lib/puffer_pages/liquid/tags/page_attribute.rb +0 -39
  190. data/lib/puffer_pages/liquid/tags/stylesheets.rb +0 -38
  191. data/spec/controllers/articles_controller_spec.rb +0 -65
  192. data/spec/dummy/app/controllers/articles_controller.rb +0 -9
  193. data/spec/integration/navigation_spec.rb +0 -9
  194. data/spec/lib/drops_spec.rb +0 -55
  195. data/spec/lib/tags_spec.rb +0 -98
  196. data/spec/models/page_spec.rb +0 -235
  197. 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 Javascripts < ::Liquid::Tag
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 'javascripts' - Valid syntax: javascripts path [, path, path ...]")
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
- context.registers[:tracker].register "<%= javascript_include_tag #{paths} %>"
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::Javascripts)
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 ? "<%= yield :'#{@name}' %>" : "<%= yield %>")
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