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
@@ -1,4 +1,15 @@
1
- Fabricator(:snippet) do
2
- name { Forgery::LoremIpsum.word }
3
- body { Forgery::LoremIpsum.sentence }
1
+ Fabricator(:snippet, class_name: :'puffer_pages/snippet') do
2
+ name { Forgery::LoremIpsum.word(random: true) }
3
+ body { Forgery::LoremIpsum.sentence(random: true) }
4
+ if PufferPages.localize
5
+ body_translations do
6
+ (I18n.available_locales - [I18n.locale]).each_with_object({}) do |locale, result|
7
+ result[locale] = Forgery::LoremIpsum.sentence(random: true)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ Fabricator(:custom, from: :snippet) do
14
+ name { "custom" }
4
15
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Handlers::Base do
4
+ subject { described_class.new(:html) }
5
+ let(:page_part) { Fabricate :main, body: 'just {{type}}' }
6
+
7
+ context do
8
+ specify { subject.process(page_part, drops: { type: 'plain html' }).should == 'just plain html' }
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Handlers::Yaml do
4
+ subject { described_class.new(:yaml) }
5
+
6
+ let!(:root) { Fabricate :root, name: 'root', page_parts: [ancestors.last] }
7
+ let!(:first) { Fabricate :page, slug: 'first', parent: root, page_parts: [ancestors.first] }
8
+ let!(:second) { Fabricate :page, slug: 'second', parent: first, page_parts: [page_part] }
9
+ let(:page_part) {
10
+ Fabricate.build :main, handler: 'yaml', body: YAML.dump(config: { value: 42, array: [1, 2], hash: { foo: 1 } })
11
+ }
12
+ let(:ancestors) {
13
+ [
14
+ Fabricate.build(:main, handler: 'yaml', body: YAML.dump(config: { array: [4, 5], hash: { bar: 2 } })),
15
+ Fabricate.build(:main, handler: 'yaml', body: YAML.dump(config: { value: 33, hash: { bar: 1, baz: 3 } }))
16
+ ]
17
+ }
18
+
19
+ context do
20
+ specify { subject.process(page_part).should ==
21
+ { config: { value: 42, array: [1, 2], hash: { foo: 1, bar: 2, baz: 3 } } } }
22
+ end
23
+
24
+ context 'error yaml' do
25
+ let(:page_part) {
26
+ Fabricate.build :main, handler: 'yaml', body: " key: value\n key:value\n key:value"
27
+ }
28
+
29
+ specify do
30
+ expect { subject.process(page_part).should }.
31
+ to raise_exception Psych::SyntaxError
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Handlers do
4
+ before(:all) { @handlers = subject.handlers }
5
+ after(:all) { subject.instance_variable_set(:@handlers, @handlers) }
6
+
7
+ before { subject.instance_variable_set(:@handlers, nil) }
8
+
9
+ context do
10
+ let(:klass) do
11
+ Class.new do
12
+ attr_accessor :type
13
+ def initialize type
14
+ @type = type
15
+ end
16
+
17
+ def process *args
18
+ "processed #{@type}, #{args.first}"
19
+ end
20
+
21
+ def codemirror_mode
22
+ 'mode'
23
+ end
24
+ end
25
+ end
26
+ before { subject.register klass, :html, :json }
27
+
28
+ specify { subject.handlers[:html].should be_a klass }
29
+ specify { subject.handlers[:json].should be_a klass }
30
+ specify { subject.select.should == [
31
+ ['translation missing: en.puffer_pages.handlers.html', :html, {"data-codemirror-mode" => "mode"}],
32
+ ['translation missing: en.puffer_pages.handlers.json', :json, {"data-codemirror-mode" => "mode"}]
33
+ ] }
34
+ specify { subject.process('html', 'object').should == 'processed html, object' }
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Liquid::Backend do
4
+ let(:backend) { described_class.new }
5
+ let(:translations) { { en: { hello: 'PufferPages world' } } }
6
+
7
+ specify { backend.translations == {} }
8
+
9
+ specify do
10
+ contextualize(page_translations: translations) do
11
+ backend.translations
12
+ end.should == translations
13
+ end
14
+
15
+ specify do
16
+ contextualize(page_translations: translations) do
17
+ backend.translate(:en, 'hello')
18
+ end.should == 'PufferPages world'
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Interpolation' do
4
+ let!(:root) { Fabricate :root }
5
+
6
+ context 'double quotes' do
7
+ let!(:layout) { Fabricate :application, body: '{% assign var = "#{foo} interpolation" %}{{ var }}' }
8
+ specify { root.render('foo' => 'bar').should == 'bar interpolation' }
9
+ end
10
+
11
+ context 'single quotes' do
12
+ let!(:layout) { Fabricate :application, body: '{% assign var = \'#{foo} interpolation\' %}{{ var }}' }
13
+ specify { root.render('foo' => 'bar').should == '#{foo} interpolation' }
14
+ end
15
+
16
+ context 'filters' do
17
+ let!(:layout) { Fabricate :application, body: '{% assign var = "#{foo | capitalize} interpolation" %}{{ var }}' }
18
+ specify { root.render('foo' => 'bar').should == 'Bar interpolation' }
19
+ end
20
+
21
+ context 'filters with parameters' do
22
+ let!(:layout) { Fabricate :application, body: '{% assign var = "#{foo | minus: 1} interpolation" %}{{ var }}' }
23
+ specify { root.render('foo' => 4).should == '3 interpolation' }
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Liquid::Tags::Include do
4
+ describe 'include page_part' do
5
+ let!(:root) { Fabricate :root, page_parts: [main, sidebar] }
6
+ let!(:main) { Fabricate :main }
7
+ let!(:sidebar) { Fabricate :sidebar }
8
+
9
+ specify { root.render("{% include '#{PufferPages.primary_page_part_name}' %}").should == main.body }
10
+ specify { root.render("{% assign sb = 'sidebar' %}{% include sb %}").should == sidebar.body }
11
+ end
12
+
13
+ describe 'include snippet' do
14
+ let!(:root) { Fabricate :root }
15
+ let!(:custom) { Fabricate :custom }
16
+
17
+ specify { root.render("{% include 'snippets/custom' %}").should == custom.body }
18
+ specify { root.render("{% assign snippet = 'snippets/custom' %}{% include snippet %}").should == custom.body }
19
+
20
+ context do
21
+ let!(:custom) { Fabricate :custom, body: "{{ variable }}" }
22
+ specify { root.render("{% include 'snippets/custom', variable: 'hello' %}").should == 'hello' }
23
+ end
24
+ end
25
+
26
+ describe 'include layout' do
27
+ let!(:root) { Fabricate :root }
28
+ let!(:application) { Fabricate :application }
29
+
30
+ specify { root.render("{% include 'layouts/application' %}").should == application.body }
31
+ specify { root.render("{% assign layout = 'layouts/application' %}{% include layout %}").should == application.body }
32
+
33
+ context do
34
+ let!(:application) { Fabricate :application, body: "{{ variable }}" }
35
+ specify { root.render("{% include 'layouts/application', variable: 'hello' %}").should == 'hello' }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Liquid::Tags::Partials do
4
+ describe 'snippet' do
5
+ let!(:root) { Fabricate :root }
6
+ let!(:custom) { Fabricate :custom }
7
+
8
+ specify { root.render("{% snippet 'custom' %}").should == custom.body }
9
+ specify { root.render("{% assign snippet = 'custom' %}{% snippet snippet %}").should == custom.body }
10
+
11
+ context do
12
+ let!(:custom) { Fabricate :custom, body: "{{ custom }}" }
13
+ specify { root.render("{% snippet 'custom' with 'hello' %}").should == 'hello' }
14
+ end
15
+
16
+ context do
17
+ let!(:custom) { Fabricate :custom, body: "{{ variable }}" }
18
+ specify { root.render("{% snippet 'custom', variable: 'hello' %}").should == 'hello' }
19
+ end
20
+ end
21
+
22
+ describe 'layout' do
23
+ let!(:root) { Fabricate :root }
24
+ let!(:application) { Fabricate :application }
25
+
26
+ specify { root.render("{% layout 'application' %}").should == application.body }
27
+ specify { root.render("{% assign layout = 'application' %}{% layout layout %}").should == application.body }
28
+
29
+ context do
30
+ let!(:application) { Fabricate :application, body: "{{ application }}" }
31
+ specify { root.render("{% layout 'application' with 'hello' %}").should == 'hello' }
32
+ end
33
+
34
+ context do
35
+ let!(:application) { Fabricate :application, body: "{{ variable }}" }
36
+ specify { root.render("{% layout 'application', variable: 'hello' %}").should == 'hello' }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Liquid::Tags::Scope do
4
+ let(:klass) do
5
+ Class.new do
6
+ include PufferPages::Backends::Mixins::Renderable
7
+
8
+ def render *args
9
+ render_template *args
10
+ end
11
+ end
12
+ end
13
+ let(:template) do
14
+ klass.new
15
+ end
16
+
17
+ specify { template.render("{% scope foo: 'hello' %}{{ foo }}{% endscope %}").should == 'hello' }
18
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Liquid::Tags::Translate do
4
+
5
+ def render_page(page, drops = {})
6
+ page.render({ self: page }.merge(drops))
7
+ end
8
+
9
+ before do
10
+ @backend = I18n.backend
11
+ I18n.backend = I18n::Backend::Simple.new
12
+ end
13
+ after do
14
+ I18n.backend = @backend
15
+ end
16
+
17
+ context '#i18n_defaults and #i18n_scope' do
18
+ let!(:root) { Fabricate :root }
19
+ let!(:foo) { Fabricate :page, slug: 'foo', parent_id: root.id }
20
+ let!(:bar) { Fabricate :page, slug: 'bar', parent_id: foo.id }
21
+ let!(:main) { Fabricate :main, page_id: root.id }
22
+ let!(:foo_main) { Fabricate :main, page_id: foo.id }
23
+ let!(:bar_main) { Fabricate :main, page_id: bar.id }
24
+ let!(:layout) { Fabricate :application }
25
+ let!(:snippet) { Fabricate :custom }
26
+
27
+ specify { main.i18n_scope.should == [:pages, :page_parts, :body] }
28
+ specify { main.i18n_defaults.should == [[:pages, :page_parts, :body], [:pages]] }
29
+ specify { foo_main.i18n_scope.should == [:pages, :foo, :page_parts, :body] }
30
+ specify { foo_main.i18n_defaults.should == [[:pages, :foo, :page_parts, :body], [:pages, :foo],
31
+ [:pages, :page_parts, :body], [:pages]] }
32
+ specify { bar_main.i18n_scope.should == [:pages, :foo, :bar, :page_parts, :body] }
33
+ specify { bar_main.i18n_defaults.should == [[:pages, :foo, :bar, :page_parts, :body], [:pages, :foo, :bar],
34
+ [:pages, :foo, :page_parts, :body], [:pages, :foo], [:pages, :page_parts, :body], [:pages]] }
35
+
36
+ specify { layout.i18n_scope.should == [:layouts, :application] }
37
+ specify { layout.i18n_defaults.should == [] }
38
+
39
+ specify { snippet.i18n_scope.should == [:snippets, :custom] }
40
+ specify { snippet.i18n_defaults.should == [] }
41
+ end
42
+
43
+ context 'layouts' do
44
+ let!(:root) { Fabricate :root }
45
+
46
+ context 'partial' do
47
+ before { I18n.backend.store_translations(:en, layouts: { application: { hello: 'I18n partial hello' } }) }
48
+ let!(:layout) { Fabricate :application, body: "{% t '.hello' %}" }
49
+ specify { root.render.should == 'I18n partial hello' }
50
+ end
51
+
52
+ context 'full' do
53
+ before { I18n.backend.store_translations(:en, world: { hello: 'I18n full hello' }) }
54
+ let!(:layout) { Fabricate :application, body: "{% t 'world.hello' %}" }
55
+ specify { root.render.should == 'I18n full hello' }
56
+ end
57
+ end
58
+
59
+ context 'snippets' do
60
+ let!(:root) { Fabricate :root }
61
+ let!(:layout) { Fabricate :application, body: "{% snippet 'custom' %}" }
62
+
63
+ context 'partial' do
64
+ before { I18n.backend.store_translations(:en, snippets: { custom: { hello: 'I18n partial hello' } }) }
65
+ let!(:snippet) { Fabricate :custom, body: "{% t '.hello' %}" }
66
+ specify { root.render.should == 'I18n partial hello' }
67
+ end
68
+
69
+ context 'full' do
70
+ before { I18n.backend.store_translations(:en, world: { hello: 'I18n full hello' }) }
71
+ let!(:snippet) { Fabricate :custom, body: "{% t 'world.hello' %}" }
72
+ specify { root.render.should == 'I18n full hello' }
73
+ end
74
+ end
75
+
76
+ context 'root page_parts' do
77
+ let!(:root) { Fabricate :root }
78
+ let!(:layout) { Fabricate :application, body: "{% include 'body' %}" }
79
+
80
+ context 'partial fallback' do
81
+ before { I18n.backend.store_translations(:en, pages: { hello: 'I18n partial hello fallback' }) }
82
+ let!(:main) { Fabricate :main, body: "{% t '.hello' %}", page_id: root.id }
83
+ specify { root.render.should == 'I18n partial hello fallback' }
84
+ end
85
+
86
+ context 'partial' do
87
+ before { I18n.backend.store_translations(:en, pages: { page_parts: { body: { hello: 'I18n partial hello' } } }) }
88
+ let!(:main) { Fabricate :main, body: "{% t '.hello' %}", page_id: root.id }
89
+ specify { root.render.should == 'I18n partial hello' }
90
+ end
91
+
92
+ context 'full' do
93
+ before { I18n.backend.store_translations(:en, world: { hello: 'I18n full hello' }) }
94
+ let!(:main) { Fabricate :main, body: "{% t 'world.hello' %}", page_id: root.id }
95
+ specify { root.render.should == 'I18n full hello' }
96
+ end
97
+ end
98
+
99
+ context 'options' do
100
+ let!(:root) { Fabricate :root }
101
+ let!(:layout) { Fabricate :application, body: "{% t '.hello' param: 'hello' %}" }
102
+ before { I18n.backend.store_translations(:en, layouts: { application: { hello: 'some params %{param}' } }) }
103
+
104
+ specify { root.render.should == 'some params hello' }
105
+ end
106
+
107
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Tags' do
4
+
5
+ def render_page(page, drops = {})
6
+ page.render({ self: page }.merge(drops))
7
+ end
8
+
9
+ describe 'stylesheets' do
10
+
11
+ it 'should render stylesheets with proper params' do
12
+ @page = Fabricate :page, :layout_name => 'foo_layout'
13
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign st = 'styles' %}{% stylesheets 'reset', st %}"
14
+ render_page(@page).should == "<%= stylesheet_link_tag 'reset', 'styles' %>"
15
+ end
16
+
17
+ end
18
+
19
+ describe 'javascripts' do
20
+
21
+ it 'should render javascripts with proper params' do
22
+ @page = Fabricate :page, :layout_name => 'foo_layout'
23
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign ctrl = 'controls' %}{% javascripts 'prototype', ctrl %}"
24
+ render_page(@page).should == "<%= javascript_include_tag 'prototype', 'controls' %>"
25
+ end
26
+
27
+ end
28
+
29
+ describe 'javascript' do
30
+
31
+ it 'should render javascript tag' do
32
+ @page = Fabricate :page, :layout_name => 'foo_layout'
33
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% javascript %}\nvar i = \"\";\ni = 2;\n{% endjavascript %}"
34
+ render_page(@page).should == "<%= javascript_tag do %>\nvar i = \"\";\ni = 2;\n<% end %>"
35
+ end
36
+
37
+ end
38
+
39
+ describe 'super' do
40
+ let!(:root){
41
+ Fabricate :page, :layout_name => 'foo', :page_parts => [
42
+ Fabricate(:page_part, :name => 'sidebar', :body => "root sidebar {{var}}")
43
+ ]
44
+ }
45
+ let!(:page){
46
+ Fabricate :page, :slug => 'page', :parent => root, :page_parts => [
47
+ Fabricate(:page_part, :name => 'sidebar', :body => "wrap {% super var:'hello' %} sidebar")
48
+ ]
49
+ }
50
+ let!(:page2){
51
+ Fabricate :page, :slug => 'page2', :parent => page, :page_parts => [
52
+ Fabricate(:page_part, :name => 'sidebar', :body => "wrap2 {% super %} sidebar")
53
+ ]
54
+ }
55
+
56
+ specify{page.render("{% include 'sidebar' %}").should == "wrap root sidebar hello sidebar"}
57
+ specify{page2.render("{% include 'sidebar' %}").should == "wrap2 wrap root sidebar hello sidebar sidebar"}
58
+ end
59
+
60
+ describe 'array' do
61
+ subject{Liquid::Template.parse("{% array arr = 'one', 2, var %}{{arr[0]}} {{arr[1]}} {{arr[2]}}")}
62
+ specify{subject.render('var' => 'three').should == 'one 2 three'}
63
+ end
64
+
65
+ context 'url helpers' do
66
+ include RSpec::Rails::ControllerExampleGroup
67
+
68
+ controller{}
69
+
70
+ def render template, variables = {}
71
+ Liquid::Template.parse(template).render!(variables.stringify_keys, {:registers => {:controller => controller}})
72
+ end
73
+
74
+ specify { render("{% url admin_pages %}").should == 'http://test.host/admin/pages' }
75
+ specify { render("{% path admin_page 10 %}").should == '/admin/pages/10' }
76
+ specify { render("{% path admin_pages key: 'value' %}").should == '/admin/pages?key=value' }
77
+ specify { render("{% path admin_page 'haha' %}").should == '/admin/pages/haha' }
78
+ specify { render("{% path admin_page var %}", { var: 'foo' }).should == '/admin/pages/foo' }
79
+ specify { render("{% path admin_page 10, key: value %}", { value: 'hello' }).should == '/admin/pages/10?key=hello' }
80
+ end
81
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Liquid::PageDrop do
4
+
5
+ def render_layout layout, current_page, page = nil
6
+ current_page.render(layout, other: page)
7
+ end
8
+
9
+ context do
10
+ let(:hash) { { 'hello' => '{{ self.name }}' } }
11
+
12
+ let!(:root) { Fabricate :root, name: 'root' }
13
+ let!(:first) { Fabricate :page, slug: 'first', parent: root }
14
+ let!(:second) { Fabricate :page, slug: 'second', parent: first, page_parts: [main, sidebar] }
15
+ let!(:main) { Fabricate(:main) }
16
+ let!(:sidebar) { Fabricate(:sidebar, handler: 'yaml', body: YAML.dump(hash)) }
17
+
18
+ before do
19
+ root.reload
20
+ first.reload
21
+ second.reload
22
+ end
23
+
24
+ specify { render_layout('{{ self.parent.name }}', second).should == first.name }
25
+ specify { render_layout('{{ self.root.name }}', second).should == 'root' }
26
+
27
+ specify { render_layout('{{ other.current? }}', first, first).should == 'true' }
28
+ specify { render_layout('{{ other.current? }}', first, root).should == 'false' }
29
+ specify { render_layout('{{ other.current? }}', first, second).should == 'false' }
30
+
31
+ specify { render_layout('{{ other.ancestor? }}', first, first).should == 'false' }
32
+ specify { render_layout('{{ other.ancestor? }}', first, root).should == 'true' }
33
+ specify { render_layout('{{ other.ancestor? }}', first, second).should == 'false' }
34
+
35
+ specify { render_layout('{% if self == other %}equal{% else %}not equal{% endif %}', first, first).should == 'equal' }
36
+ specify { render_layout('{% if self == other %}equal{% else %}not equal{% endif %}', first, root).should == 'not equal' }
37
+ specify { render_layout('{% if self == other %}equal{% else %}not equal{% endif %}', first, second).should == 'not equal' }
38
+
39
+ specify { render_layout('{{ self.body }}', second).should == main.body }
40
+ specify { render_layout('{{ self.sidebar.hello }}', second).should == second.name }
41
+
42
+ context do
43
+ include RSpec::Rails::RequestExampleGroup
44
+
45
+ context 'url helpers' do
46
+ let!(:application) { Fabricate :application, :body => '{{ self.path }} {{ self.url }}' }
47
+
48
+ specify do
49
+ get "/#{second.location}"
50
+ response.body.should == '/first/second http://www.example.com/first/second'
51
+ end
52
+ end
53
+
54
+ context 'render tag' do
55
+ let!(:application) { Fabricate :application, :body => "{% render 'shared/first' %}" }
56
+
57
+ specify do
58
+ get "/#{second.location}"
59
+ response.body.should == 'shared/first content'
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ end