write specs + refactor the site liquid drop
did
committed Feb 06, 2015
commit 19eeb96040656bb7ef490763e91c1144ea3972fd
Showing 15
changed files with
464 additions
and 424 deletions
locomotive/steam/liquid.rb b/lib/locomotive/steam/liquid.rb
+1
-1
| @@ | @@ -9,6 +9,6 @@ require_relative 'liquid/tags/hybrid' |
| require_relative 'liquid/tags/path_helper' | |
| # %w{. drops tags filters}.each do |dir| | |
| - | %w{. filters tags}.each do |dir| |
| + | %w{. drops filters tags}.each do |dir| |
| Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib } | |
| end | |
locomotive/steam/liquid/drops/base.rb b/lib/locomotive/steam/liquid/drops/base.rb
+29
-27
| @@ | @@ -1,39 +1,41 @@ |
| # Liquify taken from Mephisto sources (http://mephistoblog.com/) | |
| module Locomotive | |
| - | module Liquid |
| - | module Drops |
| - | class Base < ::Liquid::Drop |
| + | module Steam |
| + | module Liquid |
| + | module Drops |
| + | class Base < ::Liquid::Drop |
| - | @@forbidden_attributes = %w{_id _version _index} |
| + | @@forbidden_attributes = %w{_id _version _index} |
| - | def initialize(source) |
| - | @_source = source |
| - | end |
| + | def initialize(source) |
| + | @_source = source |
| + | end |
| - | def id |
| - | (@_source.respond_to?(:id) ? @_source.id : nil) || 'new' |
| - | end |
| + | def id |
| + | (@_source.respond_to?(:id) ? @_source.id : nil) || 'new' |
| + | end |
| - | # converts an array of records to an array of liquid drops |
| - | def self.liquify(*records, &block) |
| - | i = -1 |
| - | records = |
| - | records.inject [] do |all, r| |
| - | i+=1 |
| - | attrs = (block && block.arity == 1) ? [r] : [r, i] |
| - | all << (block ? block.call(*attrs) : r.to_liquid) |
| - | all |
| - | end |
| - | records.compact! |
| - | records |
| - | end |
| + | # converts an array of records to an array of liquid drops |
| + | def self.liquify(*records, &block) |
| + | i = -1 |
| + | records = |
| + | records.inject [] do |all, r| |
| + | i+=1 |
| + | attrs = (block && block.arity == 1) ? [r] : [r, i] |
| + | all << (block ? block.call(*attrs) : r.to_liquid) |
| + | all |
| + | end |
| + | records.compact! |
| + | records |
| + | end |
| - | protected |
| + | protected |
| - | def liquify(*records, &block) |
| - | self.class.liquify(*records, &block) |
| - | end |
| + | def liquify(*records, &block) |
| + | self.class.liquify(*records, &block) |
| + | end |
| + | end |
| end | |
| end | |
| end | |
locomotive/steam/liquid/drops/content_entry.rb b/lib/locomotive/steam/liquid/drops/content_entry.rb
+64
-64
| @@ | @@ -1,78 +1,78 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| - | class ContentEntry < Base |
| + | # module Locomotive |
| + | # module Liquid |
| + | # module Drops |
| + | # class ContentEntry < Base |
| - | delegate :_slug, :_permalink, :_translated, :seo_title, :meta_keywords, :meta_description, to: :@_source |
| + | # delegate :_slug, :_permalink, :_translated, :seo_title, :meta_keywords, :meta_description, to: :@_source |
| - | def _id |
| - | @_source._id.to_s |
| - | end |
| + | # def _id |
| + | # @_source._id.to_s |
| + | # end |
| - | def _label |
| - | @_label ||= @_source._label |
| - | end |
| + | # def _label |
| + | # @_label ||= @_source._label |
| + | # end |
| - | # Returns the next content for the parent content type. |
| - | # If no content is found, nil is returned. |
| - | # |
| - | # Usage: |
| - | # |
| - | # {% if article.next %} |
| - | # <a href="/articles/{{ article.next._permalink }}">Read next article</a> |
| - | # {% endif %} |
| - | # |
| - | def next |
| - | @next ||= @_source.next.to_liquid |
| - | end |
| + | # # Returns the next content for the parent content type. |
| + | # # If no content is found, nil is returned. |
| + | # # |
| + | # # Usage: |
| + | # # |
| + | # # {% if article.next %} |
| + | # # <a href="/articles/{{ article.next._permalink }}">Read next article</a> |
| + | # # {% endif %} |
| + | # # |
| + | # def next |
| + | # @next ||= @_source.next.to_liquid |
| + | # end |
| - | # Returns the previous content for the parent content type. |
| - | # If no content is found, nil is returned. |
| - | # |
| - | # Usage: |
| - | # |
| - | # {% if article.previous %} |
| - | # <a href="/articles/{{ article.previous._permalink }}">Read previous article</a> |
| - | # {% endif %} |
| - | # |
| - | def previous |
| - | @previous ||= @_source.previous.to_liquid |
| - | end |
| + | # # Returns the previous content for the parent content type. |
| + | # # If no content is found, nil is returned. |
| + | # # |
| + | # # Usage: |
| + | # # |
| + | # # {% if article.previous %} |
| + | # # <a href="/articles/{{ article.previous._permalink }}">Read previous article</a> |
| + | # # {% endif %} |
| + | # # |
| + | # def previous |
| + | # @previous ||= @_source.previous.to_liquid |
| + | # end |
| - | def errors |
| - | @_source.errors.messages.to_hash.stringify_keys |
| - | end |
| + | # def errors |
| + | # @_source.errors.messages.to_hash.stringify_keys |
| + | # end |
| - | def before_method(meth) |
| - | return '' if @_source.nil? |
| + | # def before_method(meth) |
| + | # return '' if @_source.nil? |
| - | if not @@forbidden_attributes.include?(meth.to_s) |
| - | value = @_source.send(meth) |
| + | # if not @@forbidden_attributes.include?(meth.to_s) |
| + | # value = @_source.send(meth) |
| - | if value.respond_to?(:all) # check for an association |
| - | filter_and_order_list(value) |
| - | else |
| - | value |
| - | end |
| - | else |
| - | nil |
| - | end |
| - | end |
| + | # if value.respond_to?(:all) # check for an association |
| + | # filter_and_order_list(value) |
| + | # else |
| + | # value |
| + | # end |
| + | # else |
| + | # nil |
| + | # end |
| + | # end |
| - | protected |
| + | # protected |
| - | def filter_and_order_list(list) |
| - | conditions, order_by = HashWithIndifferentAccess.new(_visible: true), nil |
| + | # def filter_and_order_list(list) |
| + | # conditions, order_by = HashWithIndifferentAccess.new(_visible: true), nil |
| - | if @context['with_scope'] |
| - | conditions.merge!(@context['with_scope']) |
| - | order_by = conditions.delete(:order_by).try(:split) |
| - | end |
| + | # if @context['with_scope'] |
| + | # conditions.merge!(@context['with_scope']) |
| + | # order_by = conditions.delete(:order_by).try(:split) |
| + | # end |
| - | list.filtered(conditions, order_by) |
| - | end |
| + | # list.filtered(conditions, order_by) |
| + | # end |
| - | end |
| - | end |
| - | end |
| - | end |
| + | # end |
| + | # end |
| + | # end |
| + | # end |
locomotive/steam/liquid/drops/content_types.rb b/lib/locomotive/steam/liquid/drops/content_types.rb
+119
-119
| @@ | @@ -1,119 +1,119 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| - | class ContentTypes < ::Liquid::Drop |
| - | |
| - | def before_method(meth) |
| - | type = @context.registers[:site].content_types.where(slug: meth.to_s).first |
| - | ContentTypeProxyCollection.new(type) |
| - | end |
| - | |
| - | end |
| - | |
| - | class ContentTypeProxyCollection < ProxyCollection |
| - | |
| - | def initialize(content_type) |
| - | @content_type = content_type |
| - | @collection = nil |
| - | end |
| - | |
| - | def public_submission_url |
| - | site = @context.registers[:controller].send(:current_site) |
| - | @context.registers[:controller].locomotive_entry_submissions_path(site, @content_type.slug) |
| - | end |
| - | |
| - | def api |
| - | Locomotive.log :warn, "[Liquid template] the api for content_types has been deprecated and replaced by public_submission_url instead." |
| - | { 'create' => public_submission_url } |
| - | end |
| - | |
| - | def before_method(meth) |
| - | klass = @content_type.entries.klass # delegate to the proxy class |
| - | |
| - | if (meth.to_s =~ /^group_by_(.+)$/) == 0 |
| - | klass.send(:group_by_select_option, $1, @content_type.order_by_definition) |
| - | elsif (meth.to_s =~ /^(.+)_options$/) == 0 |
| - | klass.send(:"#{$1}_options").map { |option| option['name'] } |
| - | else |
| - | Locomotive.log :warn, "[Liquid template] trying to call #{meth} on a content_type object" |
| - | end |
| - | end |
| - | |
| - | protected |
| - | |
| - | def collection |
| - | options = {} |
| - | |
| - | if @context['with_scope'] |
| - | self.modify_with_scope |
| - | |
| - | options = { where: @context['with_scope'] } |
| - | |
| - | options[:order_by] = options[:where].delete(:order_by) |
| - | end |
| - | |
| - | @collection ||= @content_type.ordered_entries(options).visible |
| - | end |
| - | |
| - | # Modify the attributes of the with_scope tag so that |
| - | # they can be resolved by MongoDB. |
| - | # |
| - | def modify_with_scope |
| - | @context['with_scope'].dup.each do |key, value| |
| - | field = @content_type.find_entries_custom_field(key.to_s) |
| - | |
| - | next if field.nil? |
| - | |
| - | case field.type.to_sym |
| - | when :belongs_to |
| - | self.modify_with_scope_key(key, "#{key.to_s}_id", self.object_to_id(field, value)) |
| - | when :many_to_many |
| - | self.modify_with_scope_key(key, "#{key.to_s.singularize}_ids", self.object_to_id(field, value)) |
| - | when :select |
| - | option = field.select_options.detect { |option| [option.name, option._id.to_s].include?(value) } |
| - | self.modify_with_scope_key(key, "#{key.to_s}_id", option.try(:_id)) |
| - | end |
| - | end |
| - | end |
| - | |
| - | # Change the value of a key of the with_scope depending of its type. |
| - | # If the key is a Origin::Key, we only change the name. |
| - | # If the key is a String, we replace it. |
| - | # |
| - | # @param [ Object ] key Either a String or a Origin::Key |
| - | # @param [ String ] name The new name of the key |
| - | # @param [ String ] value The new value associated to the key |
| - | # |
| - | def modify_with_scope_key(key, name, value) |
| - | if key.respond_to?(:operator) |
| - | key.instance_variable_set :@name, name |
| - | @context['with_scope'][key] = value |
| - | else |
| - | @context['with_scope'].delete(key) |
| - | @context['with_scope'][name] = value |
| - | end |
| - | end |
| - | |
| - | # Get the _id attribute of a object or a list of objects which |
| - | # can include String (needed to retrieve a model |
| - | # based on its permalink or its label field) or ContentEntry instances. |
| - | # |
| - | # @param [ Object ] field The custom field |
| - | # @param [ Object ] value An object (content entry or label) or a list of objects |
| - | # |
| - | def object_to_id(field, value) |
| - | if value.respond_to?(:map) |
| - | value.map { |el| self.object_to_id(field, el) } |
| - | elsif value.respond_to?(:_id) |
| - | value._id |
| - | else |
| - | model = Locomotive::ContentType.class_name_to_content_type(field.class_name, @content_type.site) |
| - | model.entries.or({ _slug: value }, { model.label_field_name => value }).first.try(:_id) |
| - | end |
| - | end |
| - | |
| - | end |
| - | |
| - | end |
| - | end |
| - | end |
| + | # module Locomotive |
| + | # module Liquid |
| + | # module Drops |
| + | # class ContentTypes < ::Liquid::Drop |
| + | |
| + | # def before_method(meth) |
| + | # type = @context.registers[:site].content_types.where(slug: meth.to_s).first |
| + | # ContentTypeProxyCollection.new(type) |
| + | # end |
| + | |
| + | # end |
| + | |
| + | # class ContentTypeProxyCollection < ProxyCollection |
| + | |
| + | # def initialize(content_type) |
| + | # @content_type = content_type |
| + | # @collection = nil |
| + | # end |
| + | |
| + | # def public_submission_url |
| + | # site = @context.registers[:controller].send(:current_site) |
| + | # @context.registers[:controller].locomotive_entry_submissions_path(site, @content_type.slug) |
| + | # end |
| + | |
| + | # def api |
| + | # Locomotive.log :warn, "[Liquid template] the api for content_types has been deprecated and replaced by public_submission_url instead." |
| + | # { 'create' => public_submission_url } |
| + | # end |
| + | |
| + | # def before_method(meth) |
| + | # klass = @content_type.entries.klass # delegate to the proxy class |
| + | |
| + | # if (meth.to_s =~ /^group_by_(.+)$/) == 0 |
| + | # klass.send(:group_by_select_option, $1, @content_type.order_by_definition) |
| + | # elsif (meth.to_s =~ /^(.+)_options$/) == 0 |
| + | # klass.send(:"#{$1}_options").map { |option| option['name'] } |
| + | # else |
| + | # Locomotive.log :warn, "[Liquid template] trying to call #{meth} on a content_type object" |
| + | # end |
| + | # end |
| + | |
| + | # protected |
| + | |
| + | # def collection |
| + | # options = {} |
| + | |
| + | # if @context['with_scope'] |
| + | # self.modify_with_scope |
| + | |
| + | # options = { where: @context['with_scope'] } |
| + | |
| + | # options[:order_by] = options[:where].delete(:order_by) |
| + | # end |
| + | |
| + | # @collection ||= @content_type.ordered_entries(options).visible |
| + | # end |
| + | |
| + | # # Modify the attributes of the with_scope tag so that |
| + | # # they can be resolved by MongoDB. |
| + | # # |
| + | # def modify_with_scope |
| + | # @context['with_scope'].dup.each do |key, value| |
| + | # field = @content_type.find_entries_custom_field(key.to_s) |
| + | |
| + | # next if field.nil? |
| + | |
| + | # case field.type.to_sym |
| + | # when :belongs_to |
| + | # self.modify_with_scope_key(key, "#{key.to_s}_id", self.object_to_id(field, value)) |
| + | # when :many_to_many |
| + | # self.modify_with_scope_key(key, "#{key.to_s.singularize}_ids", self.object_to_id(field, value)) |
| + | # when :select |
| + | # option = field.select_options.detect { |option| [option.name, option._id.to_s].include?(value) } |
| + | # self.modify_with_scope_key(key, "#{key.to_s}_id", option.try(:_id)) |
| + | # end |
| + | # end |
| + | # end |
| + | |
| + | # # Change the value of a key of the with_scope depending of its type. |
| + | # # If the key is a Origin::Key, we only change the name. |
| + | # # If the key is a String, we replace it. |
| + | # # |
| + | # # @param [ Object ] key Either a String or a Origin::Key |
| + | # # @param [ String ] name The new name of the key |
| + | # # @param [ String ] value The new value associated to the key |
| + | # # |
| + | # def modify_with_scope_key(key, name, value) |
| + | # if key.respond_to?(:operator) |
| + | # key.instance_variable_set :@name, name |
| + | # @context['with_scope'][key] = value |
| + | # else |
| + | # @context['with_scope'].delete(key) |
| + | # @context['with_scope'][name] = value |
| + | # end |
| + | # end |
| + | |
| + | # # Get the _id attribute of a object or a list of objects which |
| + | # # can include String (needed to retrieve a model |
| + | # # based on its permalink or its label field) or ContentEntry instances. |
| + | # # |
| + | # # @param [ Object ] field The custom field |
| + | # # @param [ Object ] value An object (content entry or label) or a list of objects |
| + | # # |
| + | # def object_to_id(field, value) |
| + | # if value.respond_to?(:map) |
| + | # value.map { |el| self.object_to_id(field, el) } |
| + | # elsif value.respond_to?(:_id) |
| + | # value._id |
| + | # else |
| + | # model = Locomotive::ContentType.class_name_to_content_type(field.class_name, @content_type.site) |
| + | # model.entries.or({ _slug: value }, { model.label_field_name => value }).first.try(:_id) |
| + | # end |
| + | # end |
| + | |
| + | # end |
| + | |
| + | # end |
| + | # end |
| + | # end |
locomotive/steam/liquid/drops/current_user.rb b/lib/locomotive/steam/liquid/drops/current_user.rb
+17
-17
| @@ | @@ -1,21 +1,21 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| - | class CurrentUser < Base |
| + | # module Locomotive |
| + | # module Liquid |
| + | # module Drops |
| + | # class CurrentUser < Base |
| - | def logged_in? |
| - | @_source.present? |
| - | end |
| + | # def logged_in? |
| + | # @_source.present? |
| + | # end |
| - | def name |
| - | @_source.name if logged_in? |
| - | end |
| + | # def name |
| + | # @_source.name if logged_in? |
| + | # end |
| - | def email |
| - | @_source.email if logged_in? |
| - | end |
| + | # def email |
| + | # @_source.email if logged_in? |
| + | # end |
| - | end |
| - | end |
| - | end |
| - | end |
| + | # end |
| + | # end |
| + | # end |
| + | # end |
locomotive/steam/liquid/drops/page.rb b/lib/locomotive/steam/liquid/drops/page.rb
+88
-88
| @@ | @@ -1,115 +1,115 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| - | class Page < Base |
| + | # module Locomotive |
| + | # module Liquid |
| + | # module Drops |
| + | # class Page < Base |
| - | delegate :seo_title, :meta_keywords, :meta_description, :redirect_url, :handle, to: :@_source |
| + | # delegate :seo_title, :meta_keywords, :meta_description, :redirect_url, :handle, to: :@_source |
| - | def title |
| - | title = @_source.templatized? ? @context['entry'].try(:_label) : nil |
| - | title || @_source.title |
| - | end |
| + | # def title |
| + | # title = @_source.templatized? ? @context['entry'].try(:_label) : nil |
| + | # title || @_source.title |
| + | # end |
| - | def slug |
| - | slug = @_source.templatized? ? @context['entry'].try(:_slug).try(:singularize) : nil |
| - | slug || @_source.slug |
| - | end |
| + | # def slug |
| + | # slug = @_source.templatized? ? @context['entry'].try(:_slug).try(:singularize) : nil |
| + | # slug || @_source.slug |
| + | # end |
| - | def original_title |
| - | @_source.title |
| - | end |
| + | # def original_title |
| + | # @_source.title |
| + | # end |
| - | def original_slug |
| - | @_source.slug |
| - | end |
| + | # def original_slug |
| + | # @_source.slug |
| + | # end |
| - | def parent |
| - | @parent ||= @_source.parent.to_liquid |
| - | end |
| + | # def parent |
| + | # @parent ||= @_source.parent.to_liquid |
| + | # end |
| - | def breadcrumbs |
| - | @breadcrumbs ||= liquify(*@_source.ancestors_and_self) |
| - | end |
| + | # def breadcrumbs |
| + | # @breadcrumbs ||= liquify(*@_source.ancestors_and_self) |
| + | # end |
| - | def children |
| - | @children ||= liquify(*@_source.children) |
| - | end |
| + | # def children |
| + | # @children ||= liquify(*@_source.children) |
| + | # end |
| - | def fullpath |
| - | @fullpath ||= @_source.fullpath |
| - | end |
| + | # def fullpath |
| + | # @fullpath ||= @_source.fullpath |
| + | # end |
| - | def depth |
| - | @_source.depth |
| - | end |
| + | # def depth |
| + | # @_source.depth |
| + | # end |
| - | def listed? |
| - | @_source.listed? |
| - | end |
| + | # def listed? |
| + | # @_source.listed? |
| + | # end |
| - | def published? |
| - | @_source.published? |
| - | end |
| + | # def published? |
| + | # @_source.published? |
| + | # end |
| - | def redirect? |
| - | @_source.redirect? |
| - | end |
| + | # def redirect? |
| + | # @_source.redirect? |
| + | # end |
| - | def is_layout? |
| - | @_source.is_layout? |
| - | end |
| + | # def is_layout? |
| + | # @_source.is_layout? |
| + | # end |
| - | def templatized? |
| - | @_source.templatized? |
| - | end |
| + | # def templatized? |
| + | # @_source.templatized? |
| + | # end |
| - | def content_type |
| - | if @_source.content_type |
| - | ContentTypeProxyCollection.new(@_source.content_type) |
| - | else |
| - | nil |
| - | end |
| - | end |
| + | # def content_type |
| + | # if @_source.content_type |
| + | # ContentTypeProxyCollection.new(@_source.content_type) |
| + | # else |
| + | # nil |
| + | # end |
| + | # end |
| - | def editable_elements |
| - | @editable_elements_hash ||= build_editable_elements_hash |
| - | end |
| + | # def editable_elements |
| + | # @editable_elements_hash ||= build_editable_elements_hash |
| + | # end |
| - | def before_method(meth) |
| - | # @deprecated |
| - | @_source.editable_elements.where(slug: meth).try(:first).try(:content) |
| - | end |
| + | # def before_method(meth) |
| + | # # @deprecated |
| + | # @_source.editable_elements.where(slug: meth).try(:first).try(:content) |
| + | # end |
| - | private |
| + | # private |
| - | def build_editable_elements_hash |
| - | {}.tap do |hash| |
| - | @_source.editable_elements.each do |el| |
| - | safe_slug = el.slug.parameterize.underscore |
| - | keys = el.block.try(:split, '/').try(:compact) || [] |
| + | # def build_editable_elements_hash |
| + | # {}.tap do |hash| |
| + | # @_source.editable_elements.each do |el| |
| + | # safe_slug = el.slug.parameterize.underscore |
| + | # keys = el.block.try(:split, '/').try(:compact) || [] |
| - | _hash = _build_editable_elements_hashes(hash, keys) |
| + | # _hash = _build_editable_elements_hashes(hash, keys) |
| - | _hash[safe_slug] = el.content |
| - | end |
| - | end |
| - | end |
| + | # _hash[safe_slug] = el.content |
| + | # end |
| + | # end |
| + | # end |
| - | def _build_editable_elements_hashes(hash, keys) |
| - | _hash = hash |
| + | # def _build_editable_elements_hashes(hash, keys) |
| + | # _hash = hash |
| - | keys.each do |key| |
| - | safe_key = key.parameterize.underscore |
| + | # keys.each do |key| |
| + | # safe_key = key.parameterize.underscore |
| - | _hash[safe_key] = {} if _hash[safe_key].nil? |
| + | # _hash[safe_key] = {} if _hash[safe_key].nil? |
| - | _hash = _hash[safe_key] |
| - | end |
| - | |
| - | _hash |
| - | end |
| + | # _hash = _hash[safe_key] |
| + | # end |
| + | |
| + | # _hash |
| + | # end |
| - | end |
| - | end |
| - | end |
| - | end |
| + | # end |
| + | # end |
| + | # end |
| + | # end |
locomotive/steam/liquid/drops/proxy_collection.rb b/lib/locomotive/steam/liquid/drops/proxy_collection.rb
+46
-46
| @@ | @@ -1,64 +1,64 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| + | # module Locomotive |
| + | # module Liquid |
| + | # module Drops |
| - | class ProxyCollection < ::Liquid::Drop |
| + | # class ProxyCollection < ::Liquid::Drop |
| - | def initialize(collection) |
| - | @collection = collection |
| - | end |
| + | # def initialize(collection) |
| + | # @collection = collection |
| + | # end |
| - | def first |
| - | self.collection.first |
| - | end |
| + | # def first |
| + | # self.collection.first |
| + | # end |
| - | def last |
| - | self.collection.last |
| - | end |
| + | # def last |
| + | # self.collection.last |
| + | # end |
| - | def each(&block) |
| - | self.collection.each(&block) |
| - | end |
| + | # def each(&block) |
| + | # self.collection.each(&block) |
| + | # end |
| - | def each_with_index(&block) |
| - | self.collection.each_with_index(&block) |
| - | end |
| + | # def each_with_index(&block) |
| + | # self.collection.each_with_index(&block) |
| + | # end |
| - | def count |
| - | @count ||= self.collection.count |
| - | end |
| + | # def count |
| + | # @count ||= self.collection.count |
| + | # end |
| - | def all |
| - | self.collection |
| - | end |
| + | # def all |
| + | # self.collection |
| + | # end |
| - | alias :size :count |
| - | alias :length :count |
| + | # alias :size :count |
| + | # alias :length :count |
| - | def empty |
| - | self.collection.empty? |
| - | end |
| + | # def empty |
| + | # self.collection.empty? |
| + | # end |
| - | def any |
| - | self.collection.any? |
| - | end |
| + | # def any |
| + | # self.collection.any? |
| + | # end |
| - | def content_type |
| + | # def content_type |
| - | end |
| + | # end |
| - | protected |
| + | # protected |
| - | def paginate(options = {}) |
| - | @collection = collection.page(options[:page]).per(options[:per_page]) |
| - | end |
| + | # def paginate(options = {}) |
| + | # @collection = collection.page(options[:page]).per(options[:per_page]) |
| + | # end |
| - | def collection |
| - | @collection |
| - | end |
| + | # def collection |
| + | # @collection |
| + | # end |
| - | end |
| + | # end |
| - | end |
| - | end |
| - | end |
| \ No newline at end of file | |
| + | # end |
| + | # end |
| + | # end |
locomotive/steam/liquid/drops/session_proxy.rb b/lib/locomotive/steam/liquid/drops/session_proxy.rb
+12
-12
| @@ | @@ -1,16 +1,16 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| + | # module Locomotive |
| + | # module Liquid |
| + | # module Drops |
| - | class SessionProxy < ::Liquid::Drop |
| + | # class SessionProxy < ::Liquid::Drop |
| - | def before_method(meth) |
| - | controller = @context.registers[:controller] |
| - | controller.session[meth.to_sym] |
| - | end |
| + | # def before_method(meth) |
| + | # controller = @context.registers[:controller] |
| + | # controller.session[meth.to_sym] |
| + | # end |
| - | end |
| + | # end |
| - | end |
| - | end |
| - | end |
| \ No newline at end of file | |
| + | # end |
| + | # end |
| + | # end |
locomotive/steam/liquid/drops/site.rb b/lib/locomotive/steam/liquid/drops/site.rb
+20
-17
| @@ | @@ -1,28 +1,31 @@ |
| module Locomotive | |
| - | module Liquid |
| - | module Drops |
| - | class Site < Base |
| + | module Steam |
| + | module Liquid |
| + | module Drops |
| + | class Site < Base |
| - | delegate :name, :seo_title, :meta_keywords, :meta_description, to: :@_source |
| + | delegate :name, :domains, :seo_title, :meta_keywords, :meta_description, to: :@_source |
| - | def index |
| - | @index ||= @_source.pages.root.first |
| - | end |
| + | def index |
| + | @index ||= repository.root.to_liquid |
| + | end |
| - | def pages |
| - | liquify(*self.scoped_pages) |
| - | end |
| + | def pages |
| + | @pages ||= liquify(*self.scoped_pages) |
| + | end |
| - | def domains |
| - | @_source.domains |
| - | end |
| + | protected |
| - | protected |
| + | def repository |
| + | @context.registers[:services].repositories.page |
| + | end |
| - | def scoped_pages |
| - | @_source.ordered_pages(@context['with_scope']) |
| - | end |
| + | def scoped_pages |
| + | repository.all(@context['with_scope']) |
| + | |
| + | end |
| + | end |
| end | |
| end | |
| end | |
locomotive/steam/liquid/drops/uploader.rb b/lib/locomotive/steam/liquid/drops/uploader.rb
+0
-21
| @@ | @@ -1,21 +0,0 @@ |
| - | module Locomotive |
| - | module Liquid |
| - | module Drops |
| - | class Uploader < Base |
| - | |
| - | delegate :size, to: :@_source |
| - | |
| - | def url |
| - | url, timestamp = @_source.url, @_source.model.updated_at.to_i |
| - | |
| - | @context.registers[:asset_host].compute(url, timestamp) |
| - | end |
| - | |
| - | def filename |
| - | File.basename(@_source.url) |
| - | end |
| - | |
| - | end |
| - | end |
| - | end |
| - | end |
| \ No newline at end of file | |
locomotive/steam/liquid/tags/path_helper.rb b/lib/locomotive/steam/liquid/tags/path_helper.rb
+7
-7
| @@ | @@ -4,14 +4,14 @@ module Locomotive |
| module Tags | |
| module PathHelper | |
| - | Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/ |
| + | Syntax = /(#{::Liquid::VariableSignature}+)/o |
| - | def initialize(tag_name, markup, tokens, context) |
| + | def initialize(tag_name, markup, options) |
| if markup =~ Syntax | |
| - | @handle = $1 |
| - | @options = {} |
| + | @handle = $1 |
| + | @path_options = {} |
| markup.scan(::Liquid::TagAttributes) do |key, value| | |
| - | @options[key] = value |
| + | @path_options[key] = value |
| end | |
| else | |
| self.wrong_syntax! | |
| @@ | @@ -56,7 +56,7 @@ module Locomotive |
| ::Mongoid::Fields::I18n.with_locale(self.locale) do | |
| if templatized | |
| criteria = site.pages.where(target_klass_name: handle.class.to_s, templatized: true) | |
| - | criteria = criteria.where(handle: @options['with']) if @options['with'] |
| + | criteria = criteria.where(handle: @path_options['with']) if @path_options['with'] |
| criteria.first.tap do |page| | |
| page.content_entry = handle if page | |
| end | |
| @@ | @@ -77,7 +77,7 @@ module Locomotive |
| end | |
| def locale | |
| - | @options['locale'] || I18n.locale |
| + | @path_options['locale'] || I18n.locale |
| end | |
| end | |
locomotive/steam/liquid/tags/path_to.rb b/lib/locomotive/steam/liquid/tags/path_to.rb
+1
-1
| @@ | @@ -11,7 +11,7 @@ module Locomotive |
| end | |
| def wrong_syntax! | |
| - | raise SyntaxError.new("Syntax Error in 'path_to' - Valid syntax: path_to <page|page_handle|content_entry>(, locale: [fr|de|...], with: <page_handle>") |
| + | raise SyntaxError.new("Valid syntax: path_to <page|page_handle|content_entry>(, locale: [fr|de|...], with: <page_handle>") |
| end | |
| end | |
locomotive/steam/repositories/page.rb b/lib/locomotive/steam/repositories/page.rb
+8
-4
| @@ | @@ -4,12 +4,12 @@ module Locomotive |
| class Page < Struct.new(:site) | |
| - | def by_handle(handle) |
| - | site.pages.where(handle: handle).first |
| + | def all(conditions = {}) |
| + | site.pages.ordered_pages(conditions) |
| end | |
| - | def parent_of(page) |
| - | page.parent |
| + | def by_handle(handle) |
| + | site.pages.where(handle: handle).first |
| end | |
| def by_fullpath(path) | |
| @@ | @@ -20,6 +20,10 @@ module Locomotive |
| site.pages.root.first | |
| end | |
| + | def parent_of(page) |
| + | page.parent |
| + | end |
| + | |
| def children_of(page) | |
| page.children | |
| end | |
spec/spec_helper.rb
+1
-0
| @@ | @@ -11,6 +11,7 @@ SimpleCov.start do |
| add_group "Liquid Filters", "lib/locomotive/steam/liquid/filters" | |
| add_group "Liquid Tags", "lib/locomotive/steam/liquid/tags" | |
| + | add_group "Liquid Drops", "lib/locomotive/steam/liquid/drops" |
| add_group "Repositories", "lib/locomotive/steam/repositories" | |
| add_group "Services", "lib/locomotive/steam/services" | |
| end | |
spec/unit/liquid/drops/site_spec.rb
+51
-0
| @@ | @@ -0,0 +1,51 @@ |
| + | require 'spec_helper' |
| + | |
| + | describe Locomotive::Steam::Liquid::Drops::Site do |
| + | |
| + | let(:services) { Locomotive::Steam::Services.build_instance } |
| + | let(:context) { ::Liquid::Context.new({}, {}, { services: services }) } |
| + | let(:site) { instance_double('Site', name: 'Locomotive', domains: ['acme.org'], seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description') } |
| + | let(:drop) { Locomotive::Steam::Liquid::Drops::Site.new(site).tap { |d| d.context = context } } |
| + | |
| + | subject { drop } |
| + | |
| + | describe 'general attributes' do |
| + | |
| + | it { expect(subject.name).to eq 'Locomotive' } |
| + | it { expect(subject.seo_title).to eq 'seo title' } |
| + | it { expect(subject.meta_keywords).to eq 'keywords' } |
| + | it { expect(subject.meta_description).to eq 'description' } |
| + | it { expect(subject.domains).to eq ['acme.org'] } |
| + | |
| + | end |
| + | |
| + | describe '#index' do |
| + | |
| + | let(:index) { instance_double('IndexPage', to_liquid: { 'title' => 'Home page' }) } |
| + | |
| + | before do |
| + | allow(services.repositories.page).to receive(:root).and_return(index) |
| + | end |
| + | |
| + | it { expect(subject.index).to eq({ 'title' => 'Home page' }) } |
| + | |
| + | end |
| + | |
| + | describe '#pages' do |
| + | |
| + | let(:pages) do |
| + | [ |
| + | instance_double('AboutUsPage', to_liquid: { 'title' => 'About us' }), |
| + | instance_double('ContactPage', to_liquid: { 'title' => 'Contact' }) |
| + | ] |
| + | end |
| + | |
| + | before do |
| + | allow(services.repositories.page).to receive(:all).and_return(pages) |
| + | end |
| + | |
| + | it { expect(subject.pages).to eq([{ 'title' => 'About us' }, { 'title' => 'Contact' }]) } |
| + | |
| + | end |
| + | |
| + | end |