remove useless code + improve codeclimate score

did committed Feb 02, 2015
commit e01db5f5bdef3aad4f3c0de4f978b86c336b495d
Showing 31 changed files with 123 additions and 946 deletions
Gemfile.lock +5 -3
@@ @@ -1,7 +1,7 @@
PATH
remote: .
specs:
- locomotivecms_steam (0.1.2.pre.beta)
+ locomotivecms_steam (0.2.0.pre.beta)
RedCloth (~> 4.2.9)
activesupport (~> 4.2.0)
coffee-script (~> 2.2.0)
@@ @@ -14,6 +14,7 @@ PATH
locomotivecms-solid (~> 4.0.0.alpha)
mimetype-fu (~> 0.1.2)
moneta (~> 0.8.0)
+ morphine (~> 0.1.1)
rack-cache (~> 1.2)
sprockets (~> 2.12.3)
sprockets-sass (~> 1.3.1)
@@ @@ -54,7 +55,7 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.8.0)
+ coffee-script-source (1.9.0)
colorize (0.7.5)
compass (1.0.3)
chunky_png (~> 1.2)
@@ @@ -115,6 +116,7 @@ GEM
mini_portile (0.6.2)
minitest (5.5.1)
moneta (0.8.0)
+ morphine (0.1.1)
multi_json (1.10.1)
multi_xml (0.5.5)
netrc (0.10.2)
@@ @@ -156,7 +158,7 @@ GEM
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
- sass (3.4.10)
+ sass (3.4.11)
simplecov (0.9.1)
docile (~> 1.1.0)
multi_json (~> 1.0)
locomotive/steam.rb b/lib/locomotive/steam.rb +0 -1
@@ @@ -7,7 +7,6 @@ require_relative 'steam/decorators'
require_relative 'steam/configuration'
require_relative 'steam/liquid'
- require_relative 'steam/morphine'
require_relative 'steam/repositories'
require_relative 'steam/services'
locomotive/steam/entities/content_type.rb b/lib/locomotive/steam/entities/content_type.rb +0 -11
@@ @@ -1,11 +0,0 @@
- module Locomotive
- module Steam
- module Entities
- class ContentType
- include Locomotive::Entity
- ## fields ##
-
- end
- end
- end
- end
locomotive/steam/entities/page.rb b/lib/locomotive/steam/entities/page.rb +0 -136
@@ @@ -1,136 +0,0 @@
- module Locomotive
- module Steam
- module Entities
- class Page
- include Locomotive::Entity
-
- ## fields ##
- attributes :parent, :title, :slug, :fullpath, :redirect_url, :redirect_type,
- :template, :handle, :listed, :searchable, :templatized, :content_type,
- :published, :cache_strategy, :response_type, :position, :seo_title,
- :meta_keywords, :meta_description, :editable_elements, :site, :children,
- :site_id, :parent_id
-
- ## aliases ##
- alias :listed? :listed
- alias :published? :published
- alias :templatized? :templatized
- alias :searchable? :searchable
-
- attr_accessor :templatized_from_parent
-
- # Tell if the page is either the index page.
- #
- # @return [ Boolean ] True if index page.
- #
- def index?
- 'index' == default_fullpath
- end
-
- # Tell if the page is either the index or the 404 page.
- #
- # @return [ Boolean ] True if index or 404 page.
- #
- def index_or_404?
- %w(index 404).include?(default_fullpath)
- end
-
-
- # Returns unique fullpath for depth, 404, index calculation.
- #
- # @return [String] Fullpath based on first locale found
- def default_fullpath
- fullpath.values.first
- end
-
- alias :index_or_not_found? :index_or_404?
-
- def with_cache?
- self.cache_strategy != 'none'
- end
-
- def default_response_type?
- self.response_type == 'text/html'
- end
-
- # Is it a redirect page ?
- #
- # @return [ Boolean ] True if the redirect_url property is set
- #
- def redirect?
- false
- #!self.redirect_url.blank?
- end
-
- # Depth of the page in the site tree.
- # Both the index and 404 pages are 0-depth.
- #
- # @return [ Integer ] The depth
- #
- def depth
- return 0 if %w(index 404).include?(default_fullpath)
- default_fullpath.split('/').size
- end
-
- def unpublished?
- !self.published?
- end
-
- # Modified setter in order to set correctly the slug
- #
- # @param [ String ] fullpath The fullpath
- #
- def fullpath_with_setting_slug=(fullpath)
- fullpath.each do |key, value|
- if value && (self.slug ||= {})[key].nil?
- self.slug[key] = File.basename(value)
- end
- end
- self.fullpath_without_setting_slug = fullpath
- end
-
- alias_method_chain :fullpath=, :setting_slug
-
- # Modified setter in order to set inheritance fields from parent
- #
- # @param [ String ] fullpath The fullpath
- #
- # def parent_with_inheritance=(parent)
- # self.templatized_from_parent = parent.templatized?
-
- # # copy properties from the parent
- # %w(templatized content_type).each do |name|
- # self.send(:"#{name}=", parent.send(name.to_sym))
- # end
-
- # self.parent_without_inheritance = parent
- # end
- # alias_method_chain :parent=, :inheritance
-
-
- # Find an editable element from its block and slug (the couple is unique)
- #
- # @param [ String ] block The name of the block
- # @param [ String ] slug The slug of the element
- #
- # @return [ Object ] The editable element or nil if not found
- #
- def find_editable_element(block, slug)
- (self.editable_elements || []).detect do |el|
- el.block.to_s == block.to_s && el.slug.to_s == slug.to_s
- end
- end
-
-
- # Set the source of the page without any pre-rendering. Used by the API reader.
- #
- # @param [ String ] content The HTML raw template
- #
- def raw_template=(content, locale)
- @source ||= {}
- @source[locale] = content
- end
- end
- end
- end
- end
locomotive/steam/entities/site.rb b/lib/locomotive/steam/entities/site.rb +0 -30
@@ @@ -1,30 +0,0 @@
- module Locomotive
- module Steam
- module Entities
- class Site
- class NullObject
- def method_missing *args
- nil
- end
- end
- include Locomotive::Entity
-
- attributes :name, :locales, :subdomain, :domains, :seo_title,
- :meta_keywords, :meta_description, :robots_txt, :timezone
- ## methods ##
-
- def default_locale
- locales.first
- end
-
- def to_s
- self.name
- end
-
- def to_liquid
- ::Locomotive::Steam::Liquid::Drops::Site.new(self)
- end
- end
- end
- end
- end
locomotive/steam/liquid/filters/base.rb b/lib/locomotive/steam/liquid/filters/base.rb +13 -0
@@ @@ -31,6 +31,19 @@ module Locomotive
input.respond_to?(:url) ? input.url : input
end
+ def css_js_asset_url(input, extension, folder)
+ return '' if input.nil?
+
+ if input =~ /^(\/|https?:)/
+ uri = URI(input)
+ else
+ uri = URI(asset_url("#{folder}/#{input}"))
+ end
+
+ uri.path = "#{uri.path}#{extension}" unless uri.path.ends_with?(extension)
+ uri.to_s
+ end
+
def asset_url(path)
@context.registers[:services].theme_asset_url.build(path)
end
locomotive/steam/liquid/filters/html.rb b/lib/locomotive/steam/liquid/filters/html.rb +2 -20
@@ @@ -21,16 +21,7 @@ module Locomotive
# Write the url of a theme stylesheet
# input: name of the css file
def stylesheet_url(input)
- return '' if input.nil?
-
- if input =~ /^(\/|https?:)/
- uri = URI(input)
- else
- uri = URI(asset_url("stylesheets/#{input}"))
- end
-
- uri.path = "#{uri.path}.css" unless uri.path.ends_with?('.css')
- uri.to_s
+ css_js_asset_url(input, '.css', 'stylesheets')
end
# Write the link tag of a theme stylesheet
@@ @@ -46,16 +37,7 @@ module Locomotive
# Write the url to javascript resource
# input: name of the javascript file
def javascript_url(input)
- return '' if input.nil?
-
- if input =~ /^(\/|https?:)/
- uri = URI(input)
- else
- uri = URI(asset_url("javascripts/#{input}"))
- end
-
- uri.path = "#{uri.path}.js" unless uri.path.ends_with?('.js')
- uri.to_s
+ css_js_asset_url(input, '.js', 'javascripts')
end
# Write the link to javascript resource
locomotive/steam/liquid/filters/misc.rb b/lib/locomotive/steam/liquid/filters/misc.rb +0 -6
@@ @@ -18,12 +18,6 @@ module Locomotive
input.blank? ? value : input
end
- # FIXME: to be removed once we use liquid > 2.6
- # https://github.com/Shopify/liquid/blob/master/lib/liquid/standardfilters.rb#L81
- def split(input, pattern)
- input.to_s.split(pattern)
- end
-
# Render the navigation for a paginated collection
def default_pagination(paginate, *args)
return '' if paginate['parts'].empty?
locomotive/steam/liquid/filters/pagination.rb b/lib/locomotive/steam/liquid/filters/pagination.rb +55 -0
@@ @@ -0,0 +1,55 @@
+ module Locomotive
+ module Steam
+ module Liquid
+ module Filters
+ module Pagination
+
+ # Render the navigation for a paginated collection
+ def default_pagination(paginate, *args)
+ return '' if paginate['parts'].empty?
+
+ options = args_to_options(args)
+
+ previous_link = default_pagination_next_or_previous_link(:previous, paginate, options, 'prev')
+ next_link = default_pagination_next_or_previous_link(:next, paginate, options, 'next')
+ links = default_pagination_links(paginate)
+
+ %{<div class="pagination #{options[:css]}">
+ #{previous_link}
+ #{links}
+ #{next_link}
+ </div>}
+ end
+
+ private
+
+ def default_pagination_links(paginate)
+ paginate['parts'].map do |part|
+ if part['is_link']
+ "<a href=\"#{absolute_url(part['url'])}\">#{part['title']}</a>"
+ elsif part['hellip_break']
+ "<span class=\"gap\">#{part['title']}</span>"
+ else
+ "<span class=\"current\">#{part['title']}</span>"
+ end
+ end.join
+ end
+
+ def default_pagination_next_or_previous_link(type, paginate, options, css)
+ label = options[:"#{type}_label"] || I18n.t("pagination.#{type}")
+
+ if paginate[type.to_s].blank?
+ "<span class=\"disabled #{css}_page\">#{label}</span>"
+ else
+ "<a href=\"#{absolute_url(paginate[type.to_s]['url'])}\" class=\"#{css}_page\">#{label}</a>"
+ end
+ end
+
+ end
+
+ ::Liquid::Template.register_filter(Misc)
+
+ end
+ end
+ end
+ end
locomotive/steam/loaders/yml/pages_loader.rb b/lib/locomotive/steam/loaders/yml/pages_loader.rb +0 -193
@@ @@ -1,193 +0,0 @@
- module Locomotive
- module Steam
- module Loader
- module Yml
- class PagesLoader
- def initialize(path, mapper)
- @root_path = path
- @path = File.join(path, 'app', 'views', 'pages')
- @mapper = mapper
- end
-
-
- # Build the tree of pages based on the filesystem structure
- #
- # @return [ Hash ] The pages organized as a Hash (using the fullpath as the key)
- #
- def load!
- entity_class = @mapper.collection(:pages).entity
- repository = @mapper.collection(:pages).repository
- all.each do |record|
- page = entity_class.new(record)
- repository.create page
- end
- end
-
- protected
-
- def build_relationships(parent, list)
- # do not use an empty template for other locales than the default one
- parent.set_default_template_for_each_locale(self.default_locale)
-
- list.dup.each do |page|
- next unless self.is_subpage_of?(page.fullpath, parent.fullpath)
-
- # attach the page to the parent (order by position), also set the parent
- parent.add_child(page)
-
- # localize the fullpath in all the locales
- page.localize_fullpath
-
- # remove the page from the list
- list.delete(page)
-
- # go under
- self.build_relationships(page, list)
- end
- end
-
- # Record pages found in file system
- def all
- [].tap do |page_records|
- position, last_dirname = nil, nil
- tree.each do |pagename, localizations|
- filepath = localizations.delete(:default)
- #next unless File.directory?(filepath) || filepath =~ /\.(#{Locomotive::Steam::TEMPLATE_EXTENSIONS.join('|')})$/
- if last_dirname != File.dirname(filepath)
- position, last_dirname = 100, File.dirname(filepath)
- end
- page = page_attributes(filepath, localizations)
- page[:position] = position
-
- page_records << page
- position += 1
- end
- end
- end
-
- def tree
- Locomotive::Steam::Utils::LocalizedTree
- .new(all_files, Locomotive::Steam::TEMPLATE_EXTENSIONS)
- .to_hash
- end
-
- def all_files
- Dir.glob(File.join(root_dir, '**/*')).sort
- end
-
- def page_attributes(filepath, localizations)
- {}.tap do |attributes|
- add_base_attributes(attributes, filepath)
- add_localized_attributes(attributes, filepath, :en)
- localizations.each { |locale, locale_file| add_localized_attributes(attributes, locale_file, locale) }
- end
- end
-
- def add_base_attributes(attributes, filepath)
- attributes.merge! _base_attributes(filepath)
- end
-
- def add_localized_attributes(attributes, filepath, locale)
- attributes.deep_merge! _localized_attributes(filepath, locale)
- end
-
- def _localized_attributes(filepath, locale)
- fetch_raw_attrs(filepath).dup.select do |key, value|
- %i{title slug fullpath redirect_url template
- seo_title meta_keywords meta_description editable_elements}
- .include? key
-
- end.map { |key, item| {key => { "#{locale}".to_sym => item }} }.reduce(:merge)
- end
-
- def _base_attributes(filepath)
- fetch_raw_attrs(filepath).dup.select do |key, value|
- %i{content_type redirect_type handle listed searchable
- templatized content_type published cache_strategy response_type
- position}
- .include? key
- end
- end
-
- def fetch_raw_attrs(filepath)
- raw_attrs[filepath]
- end
-
- def raw_attrs
- @raw_attrs ||= Hash.new do |hsh, filepath|
- attributes = {}
- fullpath = self.filepath_to_fullpath(filepath)
- attributes[:title] = File.basename(fullpath).humanize
- attributes[:fullpath] = fullpath
- attributes[:template] = OpenStruct.new(raw_source: '') if File.directory?(filepath)
- attributes.merge!(get_attributes_from_header(filepath)) unless File.directory?(filepath)
- if content_type_slug = attributes.delete('content_type')
- attributes[:templatized] = true
- attributes[:content_type] = Locomotive::Models[:content_types][content_type_slug]
- end
- hsh[filepath] = attributes
- end
- end
- # Set attributes of a page from the information
- # stored in the header of the template (YAML matters).
- # It also stores the template.
- #
- # @param [ Object ] page The page
- # @param [ String ] filepath The path of the template
- #
- def get_attributes_from_header(filepath)
- {}.tap do |attributes|
- template = Locomotive::Steam::Utils::YAMLFrontMattersTemplate.new(filepath)
- attributes[:template] = template
- if template.attributes
- attributes.merge! template.attributes.symbolize_keys
- end
- end
- end
-
- # Return the directory where all the templates of
- # pages are stored in the filesystem.
- #
- # @return [ String ] The root directory
- #
- def root_dir
- @path
- end
-
- # Take the path to a file on the filesystem
- # and return its matching value for a Page.
- #
- # @param [ String ] filepath The path to the file
- #
- # @return [ String ] The fullpath of the page
- #
- def filepath_to_fullpath(filepath)
- fullpath = filepath.gsub(File.join(self.root_dir, '/'), '')
-
- fullpath.gsub!(/^\.\//, '')
-
- fullpath.split('.').first.dasherize
- end
-
- # Tell is a page described by its fullpath is a sub page of a parent page
- # also described by its fullpath
- #
- # @param [ String ] fullpath The full path of the page to test
- # @param [ String ] parent_fullpath The full path of the parent page
- #
- # @return [ Boolean] True if the page is a sub page of the parent one
- #
- def is_subpage_of?(fullpath, parent_fullpath)
- return false if %w(index 404).include?(fullpath)
-
- if parent_fullpath == 'index' && fullpath.split('/').size == 1
- return true
- end
-
- File.dirname(fullpath.dasherize) == parent_fullpath.dasherize
- end
- end
- end
- end
- end
- end
locomotive/steam/loaders/yml/site_loader.rb b/lib/locomotive/steam/loaders/yml/site_loader.rb +0 -49
@@ @@ -1,49 +0,0 @@
- module Locomotive
- module Steam
- module Loader
- module Yml
- class SiteLoader
- def initialize(path, mapper)
- @root_path = path
- @path = File.join(@root_path, 'config', 'site.yml')
- @mapper = mapper
- end
-
- def load!
- entity_class = @mapper.collection(:sites).entity
- repository = @mapper.collection(:sites).repository
- all.each do |site_hash|
- site = entity_class.new(site_hash)
- repository.create site
- end
- end
-
- private
-
- def all
- attributes = load_attributes
- (attributes['domains'] ||= []) << '0.0.0.0'
- %w{seo_title meta_keywords meta_description}.each do |field|
- attributes[field] = to_locale(attributes[field], attributes['locales'].first)
- end
- [attributes]
- end
-
- def to_locale(field, default)
- return field if field.respond_to?(:[]) && field[default]
- { "#{default}" => field }
- end
-
- def load_attributes
- if File.exists?(@path)
- file = File.read(@path).force_encoding('utf-8')
- YAML::load(file)
- else
- raise "#{@path} was not found"
- end
- end
- end
- end
- end
- end
- end
locomotive/steam/loaders/yml/utils/localized_tree.rb b/lib/locomotive/steam/loaders/yml/utils/localized_tree.rb +0 -33
@@ @@ -1,33 +0,0 @@
- module Locomotive
- module Steam
- module Utils
- class LocalizedTree
-
- def initialize(entries, extensions)
- @entries = entries
- @extensions = extensions
- end
-
- def to_hash
- group_by(locale_regexp)
- end
-
-
- private
-
- def group_by(regexp)
- @entries.each_with_object({}) do |entry, hsh|
- file, key, subkey, *_ = regexp.match(entry).to_a
- next unless file
- (hsh[key] ||= {})[subkey.try(:to_sym) || :default] = file
- end
- end
-
- def locale_regexp
- /\A(.+?)(?:\.(.{2})){0,1}\.(?:(#{@extensions.join('|')})\.*)+\Z/
- end
-
- end
- end
- end
- end
locomotive/steam/loaders/yml/utils/yaml_front_matters_template.rb b/lib/locomotive/steam/loaders/yml/utils/yaml_front_matters_template.rb +0 -66
@@ @@ -1,66 +0,0 @@
- module Locomotive
- module Steam
- module Utils
-
- # YAML Front-matters for HAML/Liquid templates
- class YAMLFrontMattersTemplate
-
- attr_reader :filepath
-
- def initialize(filepath)
- @filepath = filepath
- @line_offset = 0
- @parsed = false
- end
-
- def attributes
- self.fetch_attributes_and_raw_source
- @attributes
- end
-
- def raw_source
- self.fetch_attributes_and_raw_source
- @raw_source
- end
-
- def line_offset
- self.fetch_attributes_and_raw_source
- @line_offset
- end
-
- def source
- self.fetch_attributes_and_raw_source
- return @source if @source
-
- @source = if self.filepath.ends_with?('.haml')
- Haml::Engine.new(self.raw_source).render
- else
- self.raw_source
- end
- end
-
- def data
- @data ||= File.read(filepath)
- end
-
- protected
- def parsed?
- @parsed
- end
- def fetch_attributes_and_raw_source
- return if @parsed
- if data =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)(.*)/m
- @line_offset = $1.count("\n") + 1
- @attributes = YAML.load($1)
- @raw_source = $3
- else
- @attributes = {}
- @raw_source = data
- end
- @raw_source.force_encoding('utf-8')
- @parsed = true
- end
- end
- end
- end
- end
locomotive/steam/loaders/yml_loader.rb b/lib/locomotive/steam/loaders/yml_loader.rb +0 -33
@@ @@ -1,33 +0,0 @@
- require_relative 'yml/site_loader'
- require_relative 'yml/pages_loader'
- require_relative 'yml/utils/yaml_front_matters_template'
- require_relative 'yml/utils/localized_tree'
-
- module Locomotive
- module Steam
- module Loader
- class YmlLoader
-
- MODELS = %W[site]
-
- def initialize path, mapper
- @root_path, @mapper = path, mapper
- end
-
- def load!
- load_site!
- load_pages!
- end
-
- def load_site!
- Locomotive::Steam::Loader::Yml::SiteLoader.new(@root_path, @mapper).load!
- end
-
- def load_pages!
- Locomotive::Steam::Loader::Yml::PagesLoader.new(@root_path, @mapper).load!
- end
-
- end
- end
- end
- end
locomotive/steam/mapper.rb b/lib/locomotive/steam/mapper.rb +0 -86
@@ @@ -1,86 +0,0 @@
- # Dir[File.dirname(__FILE__) + '/entities/*.rb'].each { |file| require file }
- # Dir[File.dirname(__FILE__) + '/repositories/*.rb'].each { |file| require file }
-
- # collection :sites do
- # entity Locomotive::Steam::Entities::Site
- # repository Locomotive::Steam::Repositories::SitesRepository
-
- # attribute :name
- # attribute :locales
- # attribute :subdomain
- # attribute :domains
- # attribute :seo_title, localized: true
- # attribute :meta_keywords, localized: true
- # attribute :meta_description, localized: true
- # attribute :robots_txt
- # attribute :timezone
-
-
- # end
-
- # collection :pages do
- # entity Locomotive::Steam::Entities::Page
- # repository Locomotive::Steam::Repositories::PagesRepository
-
- # attribute :site, association: {type: :belongs_to, key: :site_id, name: :sites}
- # attribute :content_type, association: {type: :belongs_to, key: :content_type_id, name: :content_types}
- # attribute :parent, association: {type: :belongs_to, key: :parent_id, name: :pages}
- # attribute :children, association: {type: :has_many, key: :parent_id, name: :pages}
- # attribute :title, localized: true
- # attribute :slug, localized: true
- # attribute :fullpath, localized: true
- # attribute :redirect_url, localized: true
- # attribute :redirect_type, default: 301
- # attribute :template, localized: true
- # attribute :handle
- # attribute :listed, default: false
- # attribute :searchable
- # attribute :templatized, default: false
- # attribute :content_type
- # attribute :published, default: true
- # attribute :cache_strategy
- # attribute :response_type
- # attribute :position
-
- # attribute :seo_title, localized: true
- # attribute :meta_keywords, localized: true
- # attribute :meta_description, localized: true
-
- # attribute :editable_elements, type: :array, class_name: 'Locomotive::Mounter::Models::EditableElement'
-
- # end
-
- # collection :content_types do
- # entity Locomotive::Steam::Entities::ContentType
- # repository Locomotive::Steam::Repositories::ContentTypesRepository
- # attribute :slug
- # attribute :site, association: {type: :belongs_to, key: :site_id, name: :sites}
- # end
-
- # collection :content_entries do
-
- # end
-
- # collection :content_fields do
-
- # end
-
- # collection :content_select_options do
-
- # end
-
- # collection :editable_elements do
-
- # end
-
- # collection :snippets do
-
- # end
-
- # collection :theme_assets do
-
- # end
-
- # collection :translations do
-
- # end
locomotive/steam/morphine.rb b/lib/locomotive/steam/morphine.rb +0 -26
@@ @@ -1,26 +0,0 @@
- # Morphine is a lightweight dependency injection framework for Ruby. It uses a simple Ruby DSL to ease the pain of wiring your dependencies together.
- # We do not use the offical gem but rather the single file from here:
- # https://github.com/bkeepers/morphine
- #
-
- module Morphine
- def self.included(base)
- base.extend ClassMethods
- end
-
- def dependencies
- @dependencies ||= {}
- end
-
- module ClassMethods
- def register(name, &block)
- define_method name do |*args|
- dependencies[name] ||= instance_exec(*args,&block)
- end
-
- define_method "#{name}=" do |service|
- dependencies[name] = service
- end
- end
- end
- end
locomotive/steam/repositories.rb b/lib/locomotive/steam/repositories.rb +2 -0
@@ @@ -1,5 +1,7 @@
Dir[File.join(File.dirname(__FILE__), 'repositories', '*.rb')].each { |lib| require lib }
+ require 'morphine'
+
module Locomotive
module Steam
module Repositories
locomotive/steam/server.rb b/lib/locomotive/steam/server.rb +0 -1
@@ @@ -1,7 +1,6 @@
require_relative 'core_ext'
require_relative 'monkey_patches'
- require_relative 'morphine'
require_relative 'repositories'
require_relative 'services'
locomotive/steam/services.rb b/lib/locomotive/steam/services.rb +2 -0
@@ @@ -1,5 +1,7 @@
Dir[File.join(File.dirname(__FILE__), 'services', '*.rb')].each { |lib| require lib }
+ require 'morphine'
+
module Locomotive
module Steam
module Services
locomotive/steam/standalone_server.rb b/lib/locomotive/steam/standalone_server.rb +0 -30
@@ @@ -1,30 +0,0 @@
- require 'rubygems'
- require 'bundler/setup'
-
- require_relative 'version'
- require_relative 'exceptions'
- require_relative 'server'
-
- # require 'locomotive/models'
-
- module Locomotive
- module Steam
- class StandaloneServer < Server
-
- def initialize(path)
- Locomotive::Common::Logger.setup(path, false)
-
- # get the reader
- reader = Locomotive::Mounter::Reader::FileSystem.instance
- reader.run!(path: path)
- reader
-
- Bundler.require 'monkey_patches'
- Bundler.require 'initializers'
-
- # run the rack app
- super(reader, serve_assets: true)
- end
- end
- end
- end
locomotive/steam/version.rb b/lib/locomotive/steam/version.rb +1 -1
@@ @@ -3,6 +3,6 @@
# 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
module Locomotive
module Steam
- VERSION = '0.1.2-beta'
+ VERSION = '0.2.0-beta'
end
end
locomotivecms_steam.gemspec +1 -0
@@ @@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
# spec.add_development_dependency 'i18n-spec', '~> 0.6.0'
spec.add_dependency 'activesupport', '~> 4.2.0'
+ spec.add_dependency 'morphine', '~> 0.1.1'
spec.add_dependency 'httparty', '~> 0.13.3'
# spec.add_dependency 'httmultiparty', '~> 0.3.10'
spec.add_dependency 'rack-cache', '~> 1.2'
spec/spec_helper.rb +0 -1
@@ @@ -27,7 +27,6 @@ RSpec.configure do |config|
config.before(:all) { remove_logs }
config.before do
reset!
- bootstrap_models
end
config.after { reset! }
end
spec/support/helpers.rb +0 -15
@@ @@ -2,25 +2,10 @@ require 'locomotive/common'
# require 'locomotive/models'
# require 'locomotive/adapters/memory_adapter'
require_relative '../../lib/locomotive/steam/initializers'
- require_relative '../../lib/locomotive/steam/loaders/yml_loader'
module Spec
module Helpers
- def bootstrap_site_content
- Locomotive::Steam::Loader::YmlLoader.new(default_fixture_site_path, mapper).load!
- end
-
- def mapper
- # TODO
- # @mapper ||= begin
- # adapter = Locomotive::Adapters::MemoryAdapter
- # Locomotive::Mapper.load_from_file! adapter, File.join(File.expand_path('lib/locomotive/steam/mapper.rb'))
- # end
- end
-
- alias :bootstrap_models :mapper
-
def reset!
FileUtils.rm_rf(File.expand_path('../../../site', __FILE__))
end
spec/unit/entities/page_spec.rb +0 -52
@@ @@ -1,52 +0,0 @@
- require 'spec_helper'
-
- describe 'Locomotive::Steam::Entities::Page' do
-
- before { skip }
-
- it 'builds an empty page' do
- build_page.should_not be_nil
- end
-
- describe '#index?' do
- it { build_page(fullpath: {en: 'index'}).should be_index }
- it { build_page(fullpath: {en: 'about'}).should_not be_index }
- it { build_page(fullpath: {en: 'products/index'}).should_not be_index }
- end
-
- describe '#index_or_404?' do
- it { build_page(fullpath: {en: 'index'}).should be_index_or_404 }
- it { build_page(fullpath: {en: 'about'}).should_not be_index_or_404 }
- it { build_page(fullpath: {en: 'products/index'}).should_not be_index_or_404 }
- it { build_page(fullpath: {en: 'products/404'}).should_not be_index_or_404 }
- it { build_page(fullpath: {en: '404'}).should be_index_or_404 }
- end
-
- describe '#depth' do
- it { build_page(fullpath: {en: 'index'}).depth.should eq 0 }
- it { build_page(fullpath: {en: '404'}).depth.should eq 0 }
- it { build_page(fullpath: {en: 'about'}).depth.should eq 1 }
- it { build_page(fullpath: {en: 'about/me'}).depth.should eq 2 }
- it { build_page(fullpath: {en: 'about/index'}).depth.should eq 2 }
- it { build_page(fullpath: {en: 'about/the/team'}).depth.should eq 3 }
- end
-
- describe '#fullpath=' do
- context 'when the page has no slug yet' do
- it 'also sets the slug' do
- build_page(fullpath: {en: 'this/is/the/page_full_path'}).slug[:en].should eq 'page_full_path'
- end
- end
-
- context 'when the slug is already set' do
- it 'keeps the original slug' do
- build_page(fullpath: {en: 'this/is/the/page_full_path'}, slug: {en: 'the_slug'}).slug[:en].should eq 'the_slug'
- end
- end
- end
-
- def build_page(attributes = {})
- Locomotive::Steam::Entities::Page.new(attributes)
- end
-
- end
spec/unit/entities/site_spec.rb +0 -14
@@ @@ -1,14 +0,0 @@
- require 'spec_helper'
-
- describe 'Locomotive::Steam::Entities::Site' do
-
- before { skip }
-
- describe '#default_locale' do
- subject { Locomotive::Steam::Entities::Site.new attributes }
- let(:attributes) { { locales: [:wk, :fr, :es] } }
- it 'uses the first locale as default locale' do
- expect(subject.default_locale).to eq :wk
- end
- end
- end
spec/unit/liquid/filters/pagination_spec.rb +42 -0
@@ @@ -0,0 +1,42 @@
+ require 'spec_helper'
+
+ describe Locomotive::Steam::Liquid::Filters::Pagination do
+
+ include ::Liquid::StandardFilters
+ include Locomotive::Steam::Liquid::Filters::Base
+ include Locomotive::Steam::Liquid::Filters::Pagination
+
+ it 'returns a navigation block for the pagination' do
+ pagination = {
+ "previous" => nil,
+ "parts" => [
+ { 'title' => '1', 'is_link' => false },
+ { 'title' => '2', 'is_link' => true, 'url' => '/?page=2' },
+ { 'title' => '&hellip;', 'is_link' => false, 'hellip_break' => true },
+ { 'title' => '5', 'is_link' => true, 'url' => '/?page=5' }
+ ],
+ "next" => { 'title' => 'next', 'is_link' => true, 'url' => '/?page=2' }
+ }
+ html = default_pagination(pagination, 'css:flickr_pagination')
+ expect(html).to match(/<div class="pagination flickr_pagination">/)
+ expect(html).to match(/<span class="disabled prev_page">&laquo; Previous<\/span>/)
+ expect(html).to match(/<a href="\/\?page=2">2<\/a>/)
+ expect(html).to match(/<span class=\"gap\">\&hellip;<\/span>/)
+ expect(html).to match(/<a href="\/\?page=2" class="next_page">Next &raquo;<\/a>/)
+
+ pagination.merge!({
+ 'previous' => { 'title' => 'previous', 'is_link' => true, 'url' => '/?page=4' },
+ 'next' => nil
+ })
+
+ html = default_pagination(pagination, 'css:flickr_pagination')
+ expect(html).to_not match(/<span class="disabled prev_page">&laquo; Previous<\/span>/)
+ expect(html).to match(/<a href="\/\?page=4" class="prev_page">&laquo; Previous<\/a>/)
+ expect(html).to match(/<span class="disabled next_page">Next &raquo;<\/span>/)
+
+ pagination.merge!({ 'parts' => [] })
+ html = default_pagination(pagination, 'css:flickr_pagination')
+ expect(html).to eq ''
+ end
+
+ end
spec/unit/loaders/pages_loader_spec.rb +0 -43
@@ @@ -1,43 +0,0 @@
- require 'spec_helper'
-
- describe Locomotive::Steam::Loader::Yml::PagesLoader do
-
- before { skip }
-
- let(:path) { default_fixture_site_path }
- let(:loader) { Locomotive::Steam::Loader::Yml::PagesLoader.new path, mapper }
- subject { loader }
- before { Locomotive::Models[:pages].current_locale = :en }
-
- describe '#initialize' do
- it { should be_kind_of Object }
- end
-
- describe '#load!' do
- before { loader.load! }
- it 'loads pages in the pages Repository' do
- Locomotive::Models[:pages].all.size.should > 0
- end
-
- it 'creates only one Entity for all locales' do
- Locomotive::Models[:pages].matching_paths(['index']).all.size.should eq 1
- end
-
- context 'records content' do
- subject { Locomotive::Models[:pages]['index'] }
- it { subject.title[:en].should eql 'Home page' }
- it { subject.title[:fr].should eql 'Page d\'accueil' }
- end
-
- context 'records template' do
- subject { Locomotive::Models[:pages]['basic'] }
- it { subject.template[:en].source.should =~ /<title>{{ page.title }}<\/title>/ }
- it { subject.template[:en].raw_source.should =~ /%title {{ page.title }}/ }
- end
-
- context 'fills in non localized data with default locale values', pending: 'not sure if the right behaviour' do
- subject { Locomotive::Models[:pages]['basic'] }
- it { subject.title[:fr].should eql 'Basic page' }
- end
- end
- end
spec/unit/loaders/site_loader_spec.rb +0 -23
@@ @@ -1,23 +0,0 @@
- require 'spec_helper'
-
- describe Locomotive::Steam::Loader::Yml::SiteLoader do
-
- before { skip }
-
- let(:path) { default_fixture_site_path }
- let(:loader) { Locomotive::Steam::Loader::Yml::SiteLoader.new path, mapper }
-
- before { loader.load! }
-
- subject { Locomotive::Models[:sites].all.first }
-
- it { should be_kind_of Locomotive::Steam::Entities::Site }
- # its(:name) { should eql 'Sample website' }
- # its(:domains) { should eql ['example.org', 'sample.example.com', '0.0.0.0'] }
- context 'localized fields' do
- it do
- subject.seo_title[:en].should eq 'A simple LocomotiveCMS website'
- subject.seo_title[:fr].should eq 'Un simple LocomotiveCMS site web'
- end
- end
- end
spec/unit/loaders/utils/localized_tree_spec.rb +0 -34
@@ @@ -1,34 +0,0 @@
- require 'spec_helper'
-
- describe Locomotive::Steam::Utils::LocalizedTree do
-
- describe '#to_hash' do
-
- let(:tree) { [ 'a.fr.haml', 'a.haml', 'b.xml', 'b.fr.haml', 'z.txt' ] }
- let(:extensions) { ['haml','xml'] }
-
- subject { Locomotive::Steam::Utils::LocalizedTree.new(tree, extensions).to_hash }
-
- it { is_expected.to be_kind_of Hash }
-
- it 'has root as key' do
- expect(subject.keys).to eq ['a', 'b']
- end
-
- it { is_expected.to eql ({
- 'a' => {fr: 'a.fr.haml', default: 'a.haml'},
- 'b' => {default: 'b.xml', fr: 'b.fr.haml'}
- })
- }
-
- context 'multiple extensions' do
- let(:tree) { [ 'a.fr.haml.xml', 'a.haml', 'b.xml.haml', 'b.fr.haml'] }
- it { is_expected.to eql ({
- 'a' => {fr: 'a.fr.haml.xml', default: 'a.haml'},
- 'b' => {default: 'b.xml.haml', fr: 'b.fr.haml'}
- })
- }
-
- end
- end
- end
spec/unit/loaders/utils/yaml_front_matters_template_spec.rb +0 -39
@@ @@ -1,39 +0,0 @@
- require 'spec_helper'
-
- describe Locomotive::Steam::Utils::YAMLFrontMattersTemplate do
-
- let(:regular_content) do
- <<YAMLRAW
- %p Content
- YAMLRAW
- end
-
- let(:attributes_content) do
- <<YAMLRAW
- ---
- data: value 1
- other: value 2
- ---
- %p Content
- YAMLRAW
- end
-
- subject { Locomotive::Steam::Utils::YAMLFrontMattersTemplate.new('dummy_path.haml') }
- before { subject.stub(data: content) }
-
- context 'regular data' do
- let(:content) { regular_content }
- # its(:source) { should eql "<p>Content</p>\n" }
- # its(:line_offset) { should eql 0 }
- # its(:attributes) { should eql({}) }
- end
-
- context 'data with attributes' do
- let(:content) { attributes_content }
- # its(:source) { should eql "<p>Content</p>\n" }
- # its(:line_offset) { should eql 4 }
- # its(:attributes) { should eql 'data' => 'value 1', 'other' => 'value 2' }
- end
-
-
- end