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
@@ -0,0 +1,31 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Extensions
|
3
|
+
module Liquid
|
4
|
+
module Context
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
alias_method_chain :resolve, :interpolation
|
9
|
+
end
|
10
|
+
|
11
|
+
def resolve_with_interpolation key
|
12
|
+
if key.is_a? Symbol
|
13
|
+
scope = @scopes.detect { |s| s.key? key }
|
14
|
+
scope ||= @environments.detect { |s| s.key? key }
|
15
|
+
scope[key] if scope
|
16
|
+
else
|
17
|
+
resolved = resolve_without_interpolation key
|
18
|
+
if resolved.is_a?(String) && key =~ /^"(.*)"$/
|
19
|
+
resolved.gsub!(/\#\{(.*?)\}/) do
|
20
|
+
::Liquid::Variable.new($1).render(self)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
resolved
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Liquid::Context.send :include, PufferPages::Extensions::Liquid::Context
|
@@ -1,17 +1,10 @@
|
|
1
|
-
Kernel.class_eval do
|
2
|
-
def swallow_nil
|
3
|
-
yield
|
4
|
-
rescue NoMethodError
|
5
|
-
nil
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
1
|
Array.class_eval do
|
10
2
|
def arranged
|
11
3
|
arranged = ActiveSupport::OrderedHash.new
|
12
4
|
insertion_points = [arranged]
|
13
5
|
depth = 0
|
14
6
|
each do |node|
|
7
|
+
next if node.depth > depth && insertion_points.last.keys.last && node.parent_id != insertion_points.last.keys.last.id
|
15
8
|
insertion_points.push insertion_points.last.values.last if node.depth > depth
|
16
9
|
(depth - node.depth).times { insertion_points.pop } if node.depth < depth
|
17
10
|
insertion_points.last.merge! node => ActiveSupport::OrderedHash.new
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Extensions
|
3
|
+
module Pagenator # There is no error in module name
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :_puffer_pages_options
|
8
|
+
self._puffer_pages_options = {:pagenated => false}
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def inherited(klass)
|
13
|
+
super
|
14
|
+
klass._puffer_pages_options = _puffer_pages_options.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
def puffer_pages options = {}
|
18
|
+
_puffer_pages_options[:pagenated] = true
|
19
|
+
_puffer_pages_options[:only] = Array.wrap(options[:only]).map(&:to_s).presence
|
20
|
+
_puffer_pages_options[:except] = Array.wrap(options[:except]).map(&:to_s).presence
|
21
|
+
_puffer_pages_options[:scope] = options[:scope]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def _normalize_options options
|
26
|
+
super
|
27
|
+
if options[:puffer_page] || _puffer_pages_action?
|
28
|
+
scope = options[:puffer_scope].presence || _puffer_pages_options[:scope].presence
|
29
|
+
page = options.values_at(:puffer_page, :partial, :action, :file).delete_if(&:blank?).first
|
30
|
+
options[:puffer_page] = _puffer_pages_template(page, scope)
|
31
|
+
options[:layout] = 'puffer_page'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def _puffer_pages_action?
|
38
|
+
if only = _puffer_pages_options[:only]
|
39
|
+
only.include?(action_name)
|
40
|
+
elsif except = _puffer_pages_options[:except]
|
41
|
+
!except.include?(action_name)
|
42
|
+
else
|
43
|
+
_puffer_pages_options[:pagenated]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def _puffer_pages_template suggest, scope = nil
|
48
|
+
return suggest if suggest.is_a?(PufferPages::Page)
|
49
|
+
|
50
|
+
scope = case scope
|
51
|
+
when Proc
|
52
|
+
scope.call(self)
|
53
|
+
when String, Symbol
|
54
|
+
send scope
|
55
|
+
else
|
56
|
+
scope
|
57
|
+
end
|
58
|
+
|
59
|
+
PufferPages::Page.controller_scope(scope).find_view_page(
|
60
|
+
suggest.presence || request.path_info,
|
61
|
+
:formats => lookup_context.formats
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
ActionController::Base.send :include, PufferPages::Extensions::Pagenator
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Extensions
|
3
|
+
module Renderer
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
alias_method_chain :render, :puffer_pages
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_with_puffer_pages(context, options)
|
11
|
+
if options.key?(:puffer_page) && options[:puffer_page].is_a?(PufferPages::Page)
|
12
|
+
render_puffer_page(context, options)
|
13
|
+
else
|
14
|
+
render_without_puffer_pages(context, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_puffer_page(context, options)
|
19
|
+
_puffer_page_renderer.render(context, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def _puffer_page_renderer #:nodoc:
|
25
|
+
@_puffer_page_renderer ||= PufferPages::Renderer.new(@lookup_context)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ActionView::Renderer.send :include, PufferPages::Extensions::Renderer
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'globalize'
|
2
|
+
|
3
|
+
module PufferPages
|
4
|
+
module Globalize
|
5
|
+
class Migrator < ::Globalize::ActiveRecord::Migration::Migrator
|
6
|
+
def create_translation_table
|
7
|
+
connection.create_table(translations_table_name, id: false) do |t|
|
8
|
+
t.uuid :id, primary_key: true
|
9
|
+
t.uuid "#{table_name.sub(/^#{table_name_prefix}/, '').singularize}_id"
|
10
|
+
t.string :locale
|
11
|
+
fields.each do |name, options|
|
12
|
+
if options.is_a? Hash
|
13
|
+
t.column name, options.delete(:type), options
|
14
|
+
else
|
15
|
+
t.column name, options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Handlers
|
3
|
+
class HandlerMissing < Exception; end
|
4
|
+
|
5
|
+
def self.handlers
|
6
|
+
@handlers ||= HashWithIndifferentAccess.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.register klass, *types
|
10
|
+
handlers.merge! Hash[types.flatten.map { |type| [type, klass.new(type)] }]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.process type, *args
|
14
|
+
raise HandlerMissing.new("Can not find handler for '#{type}' type") unless handlers[type]
|
15
|
+
handlers[type].process(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.select
|
19
|
+
handlers.values.map { |handler| [
|
20
|
+
I18n.t("puffer_pages.handlers.#{handler.type}"),
|
21
|
+
handler.type,
|
22
|
+
{ 'data-codemirror-mode' => handler.codemirror_mode }
|
23
|
+
] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'puffer_pages/handlers/base'
|
29
|
+
require 'puffer_pages/handlers/yaml'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Handlers
|
3
|
+
class Base
|
4
|
+
attr_reader :type
|
5
|
+
|
6
|
+
def initialize type
|
7
|
+
@type = type
|
8
|
+
end
|
9
|
+
|
10
|
+
def process renderable, context = nil
|
11
|
+
renderable.render context
|
12
|
+
end
|
13
|
+
|
14
|
+
def codemirror_mode
|
15
|
+
'text/x-liquid-html'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
PufferPages::Handlers.register PufferPages::Handlers::Base, :html
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Handlers
|
3
|
+
class Yaml < Base
|
4
|
+
def process renderable, context = nil
|
5
|
+
renderable.self_and_ancestors.where(handler: 'yaml').reverse.each_with_object({}) do |renderable, result|
|
6
|
+
load_arguments = [renderable.render(context)]
|
7
|
+
load_arguments.push renderable.name if YAML.method(:load).arity == -2
|
8
|
+
hash = YAML.load *load_arguments
|
9
|
+
result.deep_merge! hash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def codemirror_mode
|
14
|
+
'text/x-liquid-yaml'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
PufferPages::Handlers.register PufferPages::Handlers::Yaml, :yaml
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Helpers
|
3
|
+
def puffer_pages_context
|
4
|
+
drops = assigns.each_with_object({}) do |(key, value), result|
|
5
|
+
result[key] = value if value.respond_to?(:to_liquid)
|
6
|
+
end
|
7
|
+
registers = assigns.each_with_object({}) do |(key, value), result|
|
8
|
+
result[key] = value
|
9
|
+
end
|
10
|
+
|
11
|
+
{ drops: drops, registers: registers.merge!(:controller => controller) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
class Backend
|
4
|
+
include ::I18n::Backend::Simple::Implementation
|
5
|
+
|
6
|
+
def load_translations; end
|
7
|
+
def store_translations(*args); end
|
8
|
+
def initialized?; true; end
|
9
|
+
|
10
|
+
def translations
|
11
|
+
Contextuality.page_translations || {}
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,31 +2,55 @@ module PufferPages
|
|
2
2
|
module Liquid
|
3
3
|
class FileSystem < ::Liquid::BlankFileSystem
|
4
4
|
|
5
|
-
def read_template_file
|
6
|
-
case template_type
|
5
|
+
def read_template_file template_path, context
|
6
|
+
source = case template_type(template_path)
|
7
7
|
when :snippet then
|
8
8
|
template_path = template_path.gsub(/^snippets\//, '')
|
9
|
-
snippet =
|
10
|
-
raise ::Liquid::FileSystemError,
|
11
|
-
|
9
|
+
snippet = snippet(template_path)
|
10
|
+
raise ::Liquid::FileSystemError,
|
11
|
+
"No such snippet '#{template_path}' found" unless snippet
|
12
|
+
snippet
|
12
13
|
when :layout then
|
13
14
|
template_path = template_path.gsub(/^layouts\//, '')
|
14
|
-
layout =
|
15
|
-
raise ::Liquid::FileSystemError,
|
16
|
-
|
15
|
+
layout = layout(template_path)
|
16
|
+
raise ::Liquid::FileSystemError,
|
17
|
+
"No such layout '#{template_path}' found" unless layout
|
18
|
+
layout
|
19
|
+
when :super then
|
20
|
+
page_part = context[:processed]
|
21
|
+
raise ::Liquid::FileSystemError,
|
22
|
+
"Can not render super page_part outside the page_part context" unless page_part.is_a?(PufferPages::PagePart)
|
23
|
+
parent_part = page_part.parent
|
24
|
+
raise ::Liquid::FileSystemError,
|
25
|
+
"No super page_part found for #{page_part.name}" unless parent_part
|
26
|
+
parent_part
|
17
27
|
when :page_part then
|
18
|
-
page_part = context.registers[:page].
|
19
|
-
raise ::Liquid::FileSystemError,
|
20
|
-
|
28
|
+
page_part = context.registers[:page].inherited_page_part(template_path)
|
29
|
+
raise ::Liquid::FileSystemError,
|
30
|
+
"No such page_part '#{template_path}' found for current page" unless page_part
|
31
|
+
page_part
|
21
32
|
end
|
33
|
+
|
34
|
+
source.respond_to?(:render) ? source : ::Liquid::Template.parse(source)
|
22
35
|
end
|
23
36
|
|
24
37
|
def template_type template_path
|
25
|
-
return :
|
38
|
+
return :super if template_path == :super
|
26
39
|
return :layout if template_path.start_with? 'layouts/'
|
40
|
+
return :snippet if template_path.start_with? 'snippets/'
|
27
41
|
return :page_part
|
28
42
|
end
|
29
43
|
|
44
|
+
def snippet name
|
45
|
+
@snippets_cache ||= {}
|
46
|
+
@snippets_cache[name] ||= PufferPages::Snippet.find_snippet(name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def layout name
|
50
|
+
@layouts_cache ||= {}
|
51
|
+
@layouts_cache[name] ||= PufferPages::Layout.find_layout(name)
|
52
|
+
end
|
53
|
+
|
30
54
|
end
|
31
55
|
end
|
32
56
|
end
|
@@ -2,57 +2,60 @@ module PufferPages
|
|
2
2
|
module Liquid
|
3
3
|
class PageDrop < ::Liquid::Drop
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
delegate *(PufferPages::Page.statuses.map {|s| "#{s}?"} << {:to => :page})
|
6
|
+
delegate :id, :slug, :created_at, :updated_at, :to => :page
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def initialize page, current_page = nil, controller = nil
|
12
|
-
@page, @current_page, @controller = page, current_page, controller
|
8
|
+
def initialize page
|
9
|
+
@page = page
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", self.class.new(page.parent, current_page, controller))
|
18
|
-
end
|
12
|
+
def name
|
13
|
+
@context ? page.render(page.name, @context) : page.name
|
19
14
|
end
|
20
15
|
|
21
|
-
%w(ancestors self_and_ancestors children self_and_children siblings
|
16
|
+
%w(parent root ancestors self_and_ancestors children self_and_children siblings
|
17
|
+
self_and_siblings descendants, self_and_descendants).each do |attribute|
|
22
18
|
define_method attribute do
|
23
|
-
instance_variable_get("@#{attribute}") ||
|
19
|
+
instance_variable_get("@#{attribute}") ||
|
20
|
+
instance_variable_set("@#{attribute}", page.send(attribute))
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
27
24
|
def path
|
28
|
-
puffer_page_path page.to_location
|
25
|
+
controller.puffer_pages.puffer_page_path page.to_location
|
29
26
|
end
|
30
27
|
|
31
28
|
def url
|
32
|
-
puffer_page_url page.to_location
|
29
|
+
controller.puffer_pages.puffer_page_url page.to_location
|
33
30
|
end
|
34
31
|
|
35
32
|
def current?
|
36
|
-
page == current_page
|
33
|
+
current_page && page == current_page
|
37
34
|
end
|
38
35
|
|
39
36
|
def ancestor?
|
40
|
-
page.is_ancestor_of?
|
37
|
+
current_page && page.is_ancestor_of?(current_page)
|
41
38
|
end
|
42
39
|
|
43
|
-
def ==
|
44
|
-
|
40
|
+
def == other
|
41
|
+
page == other.send(:page)
|
45
42
|
end
|
46
43
|
|
47
|
-
def before_method
|
48
|
-
|
44
|
+
def before_method name
|
45
|
+
page_part = page.inherited_page_part(name)
|
46
|
+
page_part.handle(@context) if page_part && @context
|
49
47
|
end
|
50
48
|
|
51
49
|
private
|
50
|
+
attr_reader :page
|
52
51
|
|
53
|
-
|
54
|
-
|
52
|
+
def current_page
|
53
|
+
@current_page ||= @context.registers[:page] if @context
|
54
|
+
end
|
55
55
|
|
56
|
+
def controller
|
57
|
+
@controller ||= @context.registers[:controller] if @context
|
58
|
+
end
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PufferPages
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
|
5
|
+
class Array < ::Liquid::Tag
|
6
|
+
Syntax = /^(#{::Liquid::VariableSignature}+)\s*=\s*(.*)\s*/
|
7
|
+
|
8
|
+
def initialize(tag_name, markup, tokens)
|
9
|
+
if markup =~ Syntax
|
10
|
+
@variable_name = $1
|
11
|
+
@items = variables_from_string($2)
|
12
|
+
else
|
13
|
+
raise SyntaxError.new("Syntax Error in 'array' - Valid syntax: array array_name = item[, item ...]")
|
14
|
+
end
|
15
|
+
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(context)
|
20
|
+
context[@variable_name] = @items.map { |item| context[item] }
|
21
|
+
''
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def variables_from_string(markup)
|
27
|
+
markup.split(',').map do |var|
|
28
|
+
var.strip =~ /\s*(#{::Liquid::QuotedFragment})\s*/
|
29
|
+
$1 ? $1 : nil
|
30
|
+
end.compact
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Liquid::Template.register_tag('array', PufferPages::Liquid::Tags::Array)
|