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
@@ -7,10 +7,26 @@
7
7
  </div>
8
8
  </div>
9
9
  <% end %>
10
- <ul class="codemirror_buttons">
11
- <% buttons.each do |button| %>
12
- <li data-codemirror-button="<%= button %>"><%= t(".#{button}") %></li>
13
- <% end %>
14
- </ul>
15
- <%= f.text_area field, field.input_options.merge(:data => {:codemirror => true}) %>
10
+ <% if @record.respond_to? "#{field}_translations" %>
11
+ <ul class="rui-tabs locales" data-tabs="{Cookie: {}}" data-fullscreen="false">
12
+ <ul class="rui-tabs-list">
13
+ <% I18n.available_locales.sort_by { |locale| locale == I18n.default_locale ? 0 : 1 }.each do |locale| %>
14
+ <li class="rui-tabs-tab">
15
+ <%= link_to locale, "##{@record.class.to_s.underscore}_#{@record.new_record? ? 'new_tab_panel_index' : @record.id}_#{field}_translations_#{locale}" %>
16
+ </li>
17
+ <% end %>
18
+ </ul>
19
+ <%= f.fields_for "#{field}_translations" do |fields| %>
20
+ <% I18n.available_locales.sort_by { |locale| locale == I18n.default_locale ? 0 : 1 }.each do |locale| %>
21
+ <li id="<%= "#{@record.class.to_s.underscore}_#{@record.new_record? ? 'new_tab_panel_index' : @record.id}_#{field}_translations_#{locale}" %>" class="rui-tabs-panel">
22
+ <%= fields.text_area locale, field.input_options.merge(data: { codemirror: { mode: field.options[:mode] || 'text/html' } }, value: @record.send("#{field}_translations")[locale]) %>
23
+ </li>
24
+ <% end %>
25
+ <% end %>
26
+ </ul>
27
+ <% else %>
28
+ <div class="codemirror_wrapper" data-fullscreen="false">
29
+ <%= f.text_area field, field.input_options.merge(data: { codemirror: { mode: field.options[:mode] || 'text/html' } }) %>
30
+ </div>
31
+ <% end %>
16
32
  <% end %>
@@ -1,9 +1,2 @@
1
1
  class CodemirrorComponent < BaseComponent
2
- helper_method :buttons
3
-
4
- private
5
-
6
- def buttons
7
- PufferPages.codemirror_buttons + Array.wrap(field.options[:buttons])
8
- end
9
- end
2
+ end
@@ -0,0 +1,8 @@
1
+ <%= component_fields_for @record do |f| %>
2
+ <div class="label handler">
3
+ <%= f.label field %><%= f.select field, @options, { include_blank: false }, field.input_options %>
4
+ <div class="field_error">
5
+ <%= @record.errors[field.name.to_sym].first %>
6
+ </div>
7
+ </div>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ class HandlersComponent < SelectComponent
2
+
3
+ private
4
+
5
+ def select_options
6
+ PufferPages::Handlers.select
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ <%= form.fields_for field.name, page_part, :child_index => child_index do |page_part_builder| %>
2
+ <% field.children.each do |field| %>
3
+ <%= field.render :form, parent_controller, page_part_builder.object, :builder => page_part_builder %>
4
+ <% end %>
5
+ <%= page_part_builder.hidden_field :id, :data => { :acts => 'id' } if page_part_builder.object.persisted? %>
6
+ <% end %>
@@ -1,9 +1,9 @@
1
- <%= fields_for @record do |f| %>
2
- <ul id="<%= field.name %>" class="rui-tabs" data-tabs="{closable: true, onSelect: page_part_tab_select, onRemove: page_part_tab_remove, addButton: page_part_tab_add}">
1
+ <%= component_fields_for @record do |f| %>
2
+ <ul id="<%= field.name %>" class="rui-tabs" data-fullscreen="false" data-tabs="{closable: true, scrollTabs: true, Cookie: {}, onSelect: page_part_tab_select, onRemove: page_part_tab_remove, addButton: page_part_tab_add}" data-new-panel="<%= render('page_part', :form => f, :page_part => PufferPages::PagePart.new, :child_index => 'new_tab_panel_index').gsub(/\n/, '').strip %>" data-new-panel-variable="new_tab_panel_index">
3
3
  <ul class="rui-tabs-list">
4
- <% @record.send(field.name).each_with_index do |page_part, index| %>
5
- <li>
6
- <%= link_to "#page_part_tab_#{index}" do %>
4
+ <% @record.send(field.name).each_with_index do |page_part| %>
5
+ <li class="rui-tabs-tab">
6
+ <%= link_to "##{page_part.class.to_s.underscore}_#{page_part.id}" do %>
7
7
  <%= page_part.name %>
8
8
  <% if page_part.errors[:name].present? %>
9
9
  <span class="field_error">
@@ -14,29 +14,10 @@
14
14
  </li>
15
15
  <% end %>
16
16
  </ul>
17
- <% @record.send(field.name).each_with_index do |page_part, index| -%>
18
- <li id="<%= "page_part_tab_#{index}" %>" class="rui-tabs-panel">
19
- <%= f.fields_for field.name, page_part do |page_part_builder| %>
20
- <% field.children.each do |field| %>
21
- <%= field.render :form, parent_controller, page_part_builder.object, :builder => page_part_builder %>
22
- <% end %>
23
- <%= page_part_builder.hidden_field :id unless page_part_builder.object.persisted? %>
24
- <% end %>
17
+ <% @record.send(field.name).each do |page_part| -%>
18
+ <li id="<%= "#{page_part.class.to_s.underscore}_#{page_part.id}" %>" class="rui-tabs-panel" data-name="<%= page_part.name %>" data-entity-model="<%= page_part.class.model_name.underscore %>" data-entity-id="<%= page_part.id if page_part.persisted? %>">
19
+ <%= render 'page_part', :form => f, :page_part => page_part, :child_index => nil %>
25
20
  </li>
26
21
  <% end -%>
27
22
  </ul>
28
- <div id="page_parts_marked_for_destroy">
29
- </div>
30
-
31
- <% new_page_part_tab_panel = capture do %>
32
- <%= f.fields_for field.name, PagePart.new, :child_index => 'new_page_part_tab_panel_index' do |page_part_builder| %>
33
- <% field.children.each do |field| %>
34
- <%= field.render :form, parent_controller, page_part_builder.object, :builder => page_part_builder %>
35
- <% end %>
36
- <% end %>
37
- <% end %>
38
-
39
- <%= javascript_tag do %>
40
- var new_page_part_tab_panel = '<%= j new_page_part_tab_panel.strip.html_safe %>'
41
- <% end %>
42
23
  <% end %>
@@ -1,7 +1,5 @@
1
1
  class PagePartsComponent < Puffer::Component::Base
2
-
3
2
  def form
4
3
  render
5
4
  end
6
-
7
- end
5
+ end
@@ -1,2 +1,3 @@
1
- <strong><%= tree_page.id %></strong><%= tree_page.name %>
2
- (<%= tree_page.status %>, <%= link_to t('.view'), puffer_page_path(tree_page.to_location), :target => '_blank' %>)
1
+ <%= tree_page.name %><strong><%= "/" + tree_page.location.to_s %></strong>
2
+ <%= tree_page.status %>
3
+ <%= link_to t('.view'), puffer_pages.puffer_page_path(tree_page.to_location), :target => '_blank' if tree_page.status.published? %>
@@ -1,3 +1,3 @@
1
1
  class Admin::LayoutsController < PufferPages::LayoutsBase
2
-
2
+ unloadable
3
3
  end
@@ -0,0 +1,3 @@
1
+ class Admin::OriginsController < PufferPages::OriginsBase
2
+ unloadable
3
+ end
@@ -1,3 +1,3 @@
1
1
  class Admin::PagesController < PufferPages::PagesBase
2
-
2
+ unloadable
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class Admin::SnippetsController < PufferPages::SnippetsBase
2
-
2
+ unloadable
3
3
  end
@@ -1,8 +1,8 @@
1
1
  class PagesController < ApplicationController
2
+ unloadable
2
3
 
3
4
  def index
4
- @page = Page.find_page params[:path]
5
- render :inline => @page.render(default_drops(@page)), :layout => @page.render_layout, :content_type => @page.content_type
5
+ page = PufferPages::Page.find_page(request.path_info)
6
+ render :puffer_page => page, :content_type => page.content_type
6
7
  end
7
-
8
8
  end
@@ -1,4 +1,5 @@
1
1
  module PufferPagesHelper
2
+ unloadable
2
3
 
3
4
  def possible_layouts
4
5
  inherited_layout + (application_layouts + puffer_layouts).uniq.sort
@@ -9,7 +10,7 @@ module PufferPagesHelper
9
10
  end
10
11
 
11
12
  def puffer_layouts
12
- Layout.order(:name).all.map(&:name)
13
+ PufferPages::Layout.order(:name).all.map(&:name)
13
14
  end
14
15
 
15
16
  def inherited_layout
@@ -17,11 +18,10 @@ module PufferPagesHelper
17
18
  end
18
19
 
19
20
  def possible_statuses
20
- Page.statuses
21
+ PufferPages::Page.statuses
21
22
  end
22
23
 
23
24
  def tree_page
24
25
  render :partial => 'tree_page', :object => record
25
26
  end
26
-
27
27
  end
@@ -1,8 +1,3 @@
1
- class PufferPages::Layout < ActiveRecord::Base
2
- self.abstract_class = true
3
-
4
- validates_presence_of :name
5
- validates_uniqueness_of :name
6
-
7
- has_many :pages, :class_name => '::Page'
1
+ class PufferPages::Layout < PufferPages::Backends::Layout
2
+ translatable :body
8
3
  end
@@ -0,0 +1,2 @@
1
+ class PufferPages::Origin < PufferPages::Backends::Origin
2
+ end
@@ -1,118 +1,2 @@
1
- # encoding: UTF-8
2
- class PufferPages::Page < ActiveRecord::Base
3
- self.abstract_class = true
4
-
5
- def self.inherited base
6
- base.acts_as_nested_set
7
- super
8
- end
9
-
10
- scope :published, where(:status => 'published')
11
-
12
- def self.statuses
13
- %w(draft hidden published)
14
- end
15
-
16
- def self.find_page location
17
- page = PufferPages.single_section_page_path ?
18
- find_by_slug(location) : find_by_location(location)
19
- raise ActiveRecord::RecordNotFound unless page
20
- raise PufferPages::DraftPage.new("PufferPages can`t show this page because it is draft") if page.draft?
21
- page
22
- end
23
-
24
- def self.find_layout_page location
25
- location.gsub!(/^\/|\/$/, '')
26
- page = location.blank? ? Page.roots.first :
27
- where(['? like location', location]).where(['status not in (?)', 'draft']).order('lft desc').first
28
- raise PufferPages::LayoutMissed.new("PufferPages can`t render this page because layout page missed or draft") unless page
29
- page
30
- end
31
-
32
- has_many :page_parts, :order => "name = '#{PufferPages.primary_page_part_name}' desc, name", :dependent => :destroy, :class_name => '::PagePart', :validate => true
33
- accepts_nested_attributes_for :page_parts, :allow_destroy => true
34
- belongs_to :layout, :primary_key => :name, :foreign_key => :layout_name, :class_name => '::Layout'
35
-
36
- validates_presence_of :name
37
- validates_uniqueness_of :slug, :scope => (:parent_id unless PufferPages.single_section_page_path)
38
- validates_inclusion_of :status, :in => statuses
39
- validates_format_of :slug, :with => /\A\s*\Z/, :message => :root_slug_format, :if => :root?
40
- validates_format_of :slug, :with => /\A([\w]+[\w-]*(\.[\w]+)?|%)\Z/, :message => :slug_format, :unless => :root?
41
- validate do |page|
42
- page.errors.add(:layout_name, :blank) unless page.inherited_layout_name.present?
43
- end
44
-
45
- attr_protected :location
46
-
47
- before_validation :defaultize_attributes
48
- def defaultize_attributes
49
- self.status ||= 'draft'
50
- self.slug = slug.presence
51
- self.location = [swallow_nil{parent.location}, slug].compact.join('/').presence
52
- end
53
-
54
- before_update :update_locations, :if => :location_changed?
55
- def update_locations
56
- self.class.update_all "location = replace(location, '#{location_was}', '#{location}')", ["location like ?", location_was + '%']
57
- end
58
-
59
- after_initialize :build_main_part, :if => :root?
60
- before_save :build_main_part, :if => :root?
61
- def build_main_part
62
- page_parts.build(:name => PufferPages.primary_page_part_name) unless page_parts.map(&:name).include?(PufferPages.primary_page_part_name)
63
- end
64
-
65
- statuses.each do |status_name|
66
- define_method "#{status_name}?" do status == status_name end
67
- end
68
-
69
- def to_location
70
- PufferPages.single_section_page_path ? slug : location
71
- end
72
-
73
- def render(drops_or_context)
74
- if inherited_layout
75
- @template = Liquid::Template.parse(inherited_layout.body)
76
- tracker.cleanup @template.render(drops_or_context, :registers => {:tracker => tracker, :page => self, :file_system => PufferPages::Liquid::FileSystem.new})
77
- else
78
- inherited_page_parts.reverse.map{|part| part.render(drops_or_context, self)}.join
79
- end
80
- end
81
-
82
- def tracker
83
- @tracker ||= PufferPages::Liquid::Tracker.new
84
- end
85
-
86
- def inherited_layout_page
87
- @inherited_layout_page ||= layout_name? ? self : swallow_nil{parent.inherited_layout_page}
88
- end
89
-
90
- def inherited_layout_name
91
- @inherited_layout_name ||= swallow_nil{inherited_layout_page.layout_name}
92
- end
93
-
94
- def inherited_layout
95
- @inherited_layout ||= swallow_nil{inherited_layout_page.layout}
96
- end
97
-
98
- def render_layout
99
- inherited_layout ? false : inherited_layout_name
100
- end
101
-
102
- def inherited_page_parts
103
- ::PagePart.where(:page_parts => {:page_id => self_and_ancestors.map(&:id)}).joins(:page).order("page_parts.name = '#{PufferPages.primary_page_part_name}' desc, page_parts.name, pages.lft desc").uniq_by &:name
104
- end
105
-
106
- def part name
107
- inherited_page_parts.detect {|part| part.name == name}
108
- end
109
-
110
- def is_layout?
111
- self.location.include?('*')
112
- end
113
-
114
- def content_type
115
- Rack::Mime.mime_type(File.extname(slug.to_s), 'text/html')
116
- end
117
-
1
+ class PufferPages::Page < PufferPages::Backends::Page
118
2
  end
@@ -1,23 +1,3 @@
1
- class PufferPages::PagePart < ActiveRecord::Base
2
- self.abstract_class = true
3
-
4
- belongs_to :page, :class_name => '::Page'
5
-
6
- validates_presence_of :name
7
- validates_uniqueness_of :name, :scope => :page_id
8
-
9
- def render(drops_or_context, page = page)
10
- template = Liquid::Template.parse(body)
11
- result = tracker.cleanup template.render(drops_or_context, :registers => {:tracker => tracker, :page => page, :file_system => PufferPages::Liquid::FileSystem.new})
12
- main? ? result : "<% content_for :'#{name}' do %>#{result}<% end %>"
13
- end
14
-
15
- def tracker
16
- @tracker ||= PufferPages::Liquid::Tracker.new
17
- end
18
-
19
- def main?
20
- name == PufferPages.primary_page_part_name
21
- end
22
-
1
+ class PufferPages::PagePart < PufferPages::Backends::PagePart
2
+ translatable :body
23
3
  end
@@ -1,6 +1,3 @@
1
- class PufferPages::Snippet < ActiveRecord::Base
2
- self.abstract_class = true
3
-
4
- validates_presence_of :name
5
- validates_uniqueness_of :name
1
+ class PufferPages::Snippet < PufferPages::Backends::Snippet
2
+ translatable :body
6
3
  end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ PufferPages::Engine.routes.draw do
2
+ match '(*path)' => 'pages#index', :as => 'puffer_page'
3
+ end
@@ -0,0 +1,16 @@
1
+ class CreateOrigins < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :origins do |t|
4
+ t.string :name
5
+ t.string :host
6
+ t.string :path
7
+ t.string :token
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :origins
15
+ end
16
+ end
@@ -0,0 +1,126 @@
1
+ class PreviousPage < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ has_many :page_parts, :class_name => '::PreviousPagePart', :inverse_of => :page, :foreign_key => :page_id
4
+ def import_attributes
5
+ attributes.except *%w(id parent_id lft rgt depth location title description keywords)
6
+ end
7
+ end
8
+
9
+ class PreviousPagePart < ActiveRecord::Base
10
+ belongs_to :page, :class_name => '::PreviousPage', :inverse_of => :page_parts
11
+ def import_attributes
12
+ attributes.except *%w(id page_id)
13
+ end
14
+ end
15
+
16
+ class PreviousLayout < ActiveRecord::Base
17
+ def import_attributes
18
+ attributes.except *%w(id)
19
+ end
20
+ end
21
+
22
+ class PreviousSnippet < ActiveRecord::Base
23
+ def import_attributes
24
+ attributes.except *%w(id)
25
+ end
26
+ end
27
+
28
+ class MigrateToUuid < ActiveRecord::Migration
29
+ def up
30
+ [:pages, :page_parts, :layouts, :snippets].each do |table|
31
+ ActiveRecord::Base.connection.indexes(table).each do |index|
32
+ remove_index table, :name => index.name
33
+ end
34
+ rename_table table, :"previous_#{table}"
35
+ end
36
+
37
+ create_table :pages, :id => false do |t|
38
+ t.uuid :id, :primary_key => true
39
+ t.string :name
40
+ t.string :slug
41
+ t.string :layout_name
42
+ t.string :status
43
+ t.uuid :parent_id
44
+ t.integer :lft
45
+ t.integer :rgt
46
+ t.integer :depth, :default => 0
47
+ t.string :location
48
+ t.timestamps
49
+ end
50
+
51
+ create_table :page_parts, :id => false do |t|
52
+ t.uuid :id, :primary_key => true
53
+ t.string :name
54
+ t.text :body
55
+ t.uuid :page_id
56
+ t.timestamps
57
+ end
58
+
59
+ create_table :layouts, :id => false do |t|
60
+ t.uuid :id, :primary_key => true
61
+ t.string :name
62
+ t.text :body
63
+ t.timestamps
64
+ end
65
+
66
+ create_table :snippets, :id => false do |t|
67
+ t.uuid :id, :primary_key => true
68
+ t.string :name
69
+ t.text :body
70
+ t.timestamps
71
+ end
72
+
73
+ add_index :pages, :slug
74
+ add_index :pages, :location
75
+
76
+ add_index :page_parts, :name
77
+ add_index :page_parts, :page_id
78
+
79
+ add_index :layouts, :name
80
+
81
+ add_index :snippets, :name
82
+
83
+ [PufferPages::Page, PufferPages::PagePart, PufferPages::Layout, PufferPages::Snippet,
84
+ PreviousPage, PreviousPagePart, PreviousLayout, PreviousSnippet].each do |model|
85
+ model.reset_column_information
86
+ end
87
+
88
+ puts "\nMigrating data"
89
+ PufferPages::Page.transaction do
90
+ import_child_pages PreviousPage.roots
91
+ PreviousLayout.all.each { |layout| PufferPages::Layout.create!(layout.import_attributes); print '.' }
92
+ PreviousSnippet.all.each { |snippet| PufferPages::Snippet.create!(snippet.import_attributes); print '.' }
93
+ end
94
+ puts "\n"
95
+
96
+ [:pages, :page_parts, :layouts, :snippets].each do |table|
97
+ drop_table :"previous_#{table}"
98
+ end
99
+ end
100
+
101
+ def import_child_pages pages, new_parent = nil
102
+ pages.each do |page|
103
+ new_page = (new_parent ? new_parent.children : PufferPages::Page).create! page.import_attributes
104
+ new_page.page_parts = page.page_parts.map do |page_part|
105
+ print '.'
106
+ PufferPages::PagePart.create! page_part.import_attributes
107
+ end
108
+ print '.'
109
+ %w(title keywords description).each do |attribute|
110
+ print '.'
111
+ page_part = new_page.page_parts.detect { |page_part| page_part.name == attribute }
112
+ if page_part
113
+ page_part.update_attributes body: "#{page_part.body}\n--#{attribute} value--\n#{page.send(attribute)}"
114
+ else
115
+ new_page.page_parts.create! name: attribute, body: page.send(attribute)
116
+ end
117
+ end
118
+ page.save
119
+ import_child_pages page.children, new_page unless page.leaf?
120
+ end
121
+ end
122
+
123
+ def down
124
+ raise IrreversibleMigration
125
+ end
126
+ end