From a09329c030aa96c38e3603b49cdc7c5b61ba5720 Mon Sep 17 00:00:00 2001 From: Jacques Crocker Date: Fri, 23 Jul 2010 13:09:54 -0700 Subject: [PATCH] Cleaning whitespace on all .rb files so commit diffs from now on will be a bit more readable --- Rakefile | 8 +- app/controllers/admin/accounts_controller.rb | 12 +- .../admin/api_contents_controller.rb | 18 +- .../admin/asset_collections_controller.rb | 16 +- app/controllers/admin/assets_controller.rb | 22 +-- app/controllers/admin/base_controller.rb | 42 ++-- .../admin/content_types_controller.rb | 6 +- app/controllers/admin/contents_controller.rb | 32 ++-- .../admin/current_sites_controller.rb | 18 +- .../admin/custom_fields_controller.rb | 22 +-- app/controllers/admin/layouts_controller.rb | 10 +- .../admin/memberships_controller.rb | 8 +- .../admin/my_accounts_controller.rb | 18 +- .../admin/page_parts_controller.rb | 2 +- app/controllers/admin/pages_controller.rb | 2 +- app/controllers/admin/passwords_controller.rb | 10 +- app/controllers/admin/rendering_controller.rb | 12 +- app/controllers/admin/sessions_controller.rb | 14 +- app/controllers/admin/sitemaps_controller.rb | 12 +- app/controllers/admin/sites_controller.rb | 18 +- app/controllers/admin/snippets_controller.rb | 10 +- .../admin/theme_assets_controller.rb | 2 +- app/controllers/application_controller.rb | 2 +- app/controllers/home_controller.rb | 8 +- app/helpers/admin/accounts_helper.rb | 6 +- app/helpers/admin/assets_helper.rb | 10 +- app/helpers/admin/base_helper.rb | 18 +- app/helpers/admin/custom_fields_helper.rb | 16 +- app/helpers/admin/login_helper.rb | 14 +- app/helpers/admin/pages_helper.rb | 32 ++-- app/helpers/admin/sites_helper.rb | 10 +- app/models/account.rb | 30 +-- app/models/asset.rb | 28 +-- app/models/asset_collection.rb | 36 ++-- app/models/content_instance.rb | 38 ++-- app/models/content_type.rb | 38 ++-- app/models/extensions/asset/vignette.rb | 22 +-- app/models/extensions/page/parts.rb | 38 ++-- app/models/extensions/page/render.rb | 16 +- app/models/extensions/page/templatized.rb | 28 +-- app/models/extensions/page/tree.rb | 46 ++--- app/models/layout.rb | 28 +-- app/models/liquid_template.rb | 22 +-- app/models/membership.rb | 20 +- app/models/page.rb | 2 +- app/models/page_part.rb | 22 +-- app/models/site.rb | 2 +- app/models/snippet.rb | 2 +- app/models/theme_asset.rb | 2 +- app/uploaders/asset_uploader.rb | 28 +-- app/uploaders/theme_asset_uploader.rb | 18 +- config/application.rb | 2 +- config/environments/development.rb | 2 +- config/environments/production.rb | 2 +- config/environments/test.rb | 2 +- config/initializers/devise.rb | 2 +- config/initializers/inflections.rb | 2 +- config/initializers/locomotive.rb | 16 +- config/initializers/rspec_generator.rb | 2 +- config/initializers/secret_token.rb | 2 +- db/seeds.rb | 2 +- features/step_definitions/admin_steps.rb | 6 +- features/step_definitions/web_steps.rb | 10 +- features/support/env.rb | 8 +- lib/core_ext.rb | 22 +-- .../copy_assets/copy_assets_generator.rb | 10 +- .../locomotive/install/install_generator.rb | 6 +- .../install/templates/locomotive.rb | 16 +- lib/locomotive.rb | 22 +-- lib/locomotive/admin_responder.rb | 10 +- lib/locomotive/carrierwave/base.rb | 6 +- lib/locomotive/carrierwave/patches.rb | 18 +- lib/locomotive/configuration.rb | 14 +- lib/locomotive/custom_fields.rb | 8 +- lib/locomotive/engine.rb | 2 +- lib/locomotive/heroku.rb | 32 ++-- lib/locomotive/heroku/custom_domain.rb | 28 +-- lib/locomotive/httparty.rb | 2 +- lib/locomotive/httparty/patches.rb | 8 +- lib/locomotive/httparty/webservice.rb | 6 +- lib/locomotive/inherited_resources.rb | 8 +- lib/locomotive/liquid.rb | 2 +- lib/locomotive/liquid/db_file_system.rb | 26 +-- .../liquid/drops/asset_collections.rb | 18 +- lib/locomotive/liquid/drops/base.rb | 24 +-- lib/locomotive/liquid/drops/content.rb | 20 +- lib/locomotive/liquid/drops/contents.rb | 26 +-- lib/locomotive/liquid/drops/javascripts.rb | 14 +- lib/locomotive/liquid/drops/page.rb | 2 +- lib/locomotive/liquid/drops/site.rb | 2 +- lib/locomotive/liquid/drops/stylesheets.rb | 22 +-- lib/locomotive/liquid/drops/theme_images.rb | 2 +- lib/locomotive/liquid/filters/date.rb | 28 +-- lib/locomotive/liquid/filters/html.rb | 40 ++-- lib/locomotive/liquid/filters/misc.rb | 22 +-- lib/locomotive/liquid/filters/text.rb | 14 +- lib/locomotive/liquid/liquify_template.rb | 32 ++-- lib/locomotive/liquid/tags/blueprint.rb | 26 +-- lib/locomotive/liquid/tags/consume.rb | 16 +- lib/locomotive/liquid/tags/jquery.rb | 16 +- lib/locomotive/liquid/tags/nav.rb | 30 +-- lib/locomotive/liquid/tags/paginate.rb | 44 ++--- lib/locomotive/liquid/tags/snippet.rb | 20 +- lib/locomotive/liquid/tags/with_scope.rb | 20 +- lib/locomotive/logger.rb | 8 +- lib/locomotive/mongoid.rb | 2 +- lib/locomotive/mongoid/document.rb | 14 +- lib/locomotive/mongoid/model_extensions.rb | 2 +- lib/locomotive/mongoid/patches.rb | 10 +- lib/locomotive/regexps.rb | 12 +- lib/locomotive/render.rb | 2 +- lib/locomotive/routing/default_constraint.rb | 24 +-- lib/locomotive/routing/site_dispatcher.rb | 2 +- lib/misc_form_builder.rb | 20 +- lib/tasks/cucumber.rake | 4 +- lib/tasks/rspec.rake | 2 +- spec/lib/core_ext_spec.rb | 28 +-- spec/lib/locomotive/heroku_spec.rb | 90 ++++----- spec/lib/locomotive/httparty/patches_spec.rb | 10 +- .../locomotive/httparty/webservice_spec.rb | 14 +- .../locomotive/liquid/drops/contents_spec.rb | 20 +- spec/lib/locomotive/liquid/drops/page_spec.rb | 30 +-- .../locomotive/liquid/filters/html_spec.rb | 34 ++-- .../locomotive/liquid/filters/misc_spec.rb | 16 +- .../locomotive/liquid/filters/text_spec.rb | 10 +- .../locomotive/liquid/tags/consume_spec.rb | 18 +- spec/lib/locomotive/liquid/tags/nav_spec.rb | 26 +-- .../locomotive/liquid/tags/paginate_spec.rb | 46 ++--- .../locomotive/liquid/tags/snippet_spec.rb | 10 +- .../locomotive/liquid/tags/with_scope_spec.rb | 12 +- spec/lib/locomotive/render_spec.rb | 60 +++--- spec/models/account_spec.rb | 30 +-- spec/models/asset_collections_spec.rb | 90 ++++----- spec/models/content_instance_spec.rb | 30 +-- spec/models/content_type_spec.rb | 24 +-- spec/models/layout_spec.rb | 38 ++-- spec/models/liquid_template_spec.rb | 10 +- spec/models/membership_spec.rb | 26 +-- spec/models/page_spec.rb | 180 +++++++++--------- spec/models/site_spec.rb | 80 ++++---- spec/models/snippet_spec.rb | 8 +- spec/models/theme_asset_spec.rb | 54 +++--- spec/spec_helper.rb | 2 +- spec/support/be_valid.rb | 4 +- spec/support/carrierwave.rb | 8 +- spec/support/locomotive.rb | 22 +-- 146 files changed, 1385 insertions(+), 1385 deletions(-) diff --git a/Rakefile b/Rakefile index b22574f1..54ee4bee 100644 --- a/Rakefile +++ b/Rakefile @@ -20,11 +20,11 @@ begin gem.description = "a brand new CMS system with super sexy UI and cool features (alpha version for now)" gem.homepage = %q{http://www.locomotiveapp.org} gem.files = Dir[ - "Gemfile", - "{app}/**/*", + "Gemfile", + "{app}/**/*", "{config}/**/*", "{lib}/**/*", - "{public}/stylesheets/admin/**/*", "{public}/javascripts/admin/**/*", "{public}/images/admin/**/*", + "{public}/stylesheets/admin/**/*", "{public}/javascripts/admin/**/*", "{public}/images/admin/**/*", "{vendor}/**/*"] # other fields that would normally go in your gemspec # like authors, email and has_rdoc can also be included here @@ -33,7 +33,7 @@ begin if dep.groups.include?(:default) gem.add_dependency(dep.name, dep.requirement.to_s) end - end + end end Jeweler::GemcutterTasks.new rescue Exception => e diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index c2f83edf..1bd2d58f 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -1,18 +1,18 @@ module Admin class AccountsController < BaseController - + sections 'settings' - + def new @account = Account.new(:email => params[:email]) end - + def create @account = Account.create(params[:account]) current_site.memberships.create(:account => @account) if @account.errors.empty? - + respond_with @account, :location => edit_admin_current_site_url end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/api_contents_controller.rb b/app/controllers/admin/api_contents_controller.rb index fdb2600f..1bbcdc14 100644 --- a/app/controllers/admin/api_contents_controller.rb +++ b/app/controllers/admin/api_contents_controller.rb @@ -1,12 +1,12 @@ module Admin class ApiContentsController < ActionController::Base - + include Locomotive::Routing::SiteDispatcher - + before_filter :require_site - + before_filter :set_content_type - + def create @content = @content_type.contents.build(params[:content]) @@ -18,13 +18,13 @@ module Admin end end end - + protected - + def set_content_type - @content_type = current_site.content_types.where(:slug => params[:slug]).first + @content_type = current_site.content_types.where(:slug => params[:slug]).first render :json => { :error => 'Api not enabled'} and return false unless @content_type.api_enabled end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/asset_collections_controller.rb b/app/controllers/admin/asset_collections_controller.rb index e71d3e33..ff6f9d88 100644 --- a/app/controllers/admin/asset_collections_controller.rb +++ b/app/controllers/admin/asset_collections_controller.rb @@ -1,23 +1,23 @@ module Admin class AssetCollectionsController < BaseController - - sections 'assets' - + + sections 'assets' + before_filter :set_collections - + def index if not @asset_collections.empty? redirect_to(edit_admin_asset_collection_url(@asset_collections.first)) and return end end - + def show @asset_collection = current_site.asset_collections.find(params[:id]) render :action => 'edit' end - - protected - + + protected + def set_collections @asset_collections = current_site.asset_collections.order_by([[:name, :asc]]) end diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 1c8c6a69..2a7ad567 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -1,30 +1,30 @@ module Admin class AssetsController < BaseController - - sections 'assets' - + + sections 'assets' + before_filter :set_collections_and_current_collection - + respond_to :json, :only => :update - + def create create! { edit_admin_asset_collection_url(@asset_collection) } end - + def update update! { edit_admin_asset_collection_url(@asset_collection) } end - - protected - + + protected + def begin_of_association_chain @asset_collection end - + def set_collections_and_current_collection @asset_collections = current_site.asset_collections @asset_collection = @asset_collections.find(params[:collection_id]) end - + end end diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 13a44315..2bb86c14 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,37 +1,37 @@ module Admin class BaseController < InheritedResources::Base - + include Locomotive::Routing::SiteDispatcher - + layout 'admin/application' - + before_filter :authenticate_admin! - + before_filter :require_site - + before_filter :validate_site_membership - + before_filter :set_locale - + helper_method :sections - + # https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in Dir[File.dirname(__FILE__) + "/../../helpers/**/*_helper.rb"].each do |file| helper "admin/#{File.basename(file, '.rb').gsub(/_helper$/, '')}" end - + self.responder = Locomotive::AdminResponder # custom responder - + defaults :route_prefix => 'admin' - + respond_to :html - + protected - + def begin_of_association_chain current_site - end - + end + def self.sections(main, sub = nil) before_filter do |c| sub = sub.call(c) if sub.respond_to?(:call) @@ -39,18 +39,18 @@ module Admin c.instance_variable_set(:@admin_sections, sections) end end - + def sections(key = nil) if !key.nil? && key.to_sym == :sub @admin_sections[:sub] || self.controller_name.dasherize - else + else @admin_sections[:main] - end + end end - + def set_locale I18n.locale = current_admin.locale end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/content_types_controller.rb b/app/controllers/admin/content_types_controller.rb index a923f21c..09627739 100644 --- a/app/controllers/admin/content_types_controller.rb +++ b/app/controllers/admin/content_types_controller.rb @@ -1,7 +1,7 @@ module Admin class ContentTypesController < BaseController - + sections 'contents' - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 3759a27f..75f076b5 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,45 +1,45 @@ module Admin class ContentsController < BaseController - + sections 'contents' - + before_filter :set_content_type - + respond_to :json, :only => :update - + def index @contents = @content_type.list_or_group_contents end - + def create create! do |success, failure| success.html { redirect_to edit_admin_content_url(@content_type.slug, @content) } end end - + def update update! { edit_admin_content_url(@content_type.slug, @content) } end - + def sort @content_type.sort_contents!(params[:order]) - + respond_with(@content_type, :location => admin_contents_url(@content_type.slug)) - end - + end + def destroy destroy! { admin_contents_url(@content_type.slug) } end - + protected - + def set_content_type @content_type ||= current_site.content_types.where(:slug => params[:slug]).first end - + def begin_of_association_chain set_content_type - end - + end + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/current_sites_controller.rb b/app/controllers/admin/current_sites_controller.rb index 5ad2d3c3..e9bfc081 100644 --- a/app/controllers/admin/current_sites_controller.rb +++ b/app/controllers/admin/current_sites_controller.rb @@ -1,24 +1,24 @@ module Admin class CurrentSitesController < BaseController - + sections 'settings', 'site' - + actions :edit, :update - + respond_to :json, :only => :update - + def update update! do |success, failure| success.html { redirect_to edit_admin_current_site_url(new_host_if_subdomain_changed) } end end - + protected - + def resource @site = current_site end - + def new_host_if_subdomain_changed if @site.domains.include?(request.host) {} @@ -26,6 +26,6 @@ module Admin { :host => "#{@site.subdomain}.#{Locomotive.config.default_domain}:#{request.port}" } end end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/custom_fields_controller.rb b/app/controllers/admin/custom_fields_controller.rb index f44c8856..b5784972 100644 --- a/app/controllers/admin/custom_fields_controller.rb +++ b/app/controllers/admin/custom_fields_controller.rb @@ -1,39 +1,39 @@ module Admin class CustomFieldsController < BaseController - + layout false - + before_filter :set_parent_and_fields - + def edit @field = @fields.find(params[:id]) render :action => "edit_#{@field.kind.downcase}" end - + def update @field = @fields.find(params[:id]) @field.updated_at = Time.now # forces mongoid to save the object - + params[:custom_field][:category_items_attributes].delete('-1') - + if @field.update_attributes(params[:custom_field]) render :json => @field.attributes else render :json => { :error => t('flash.admin.custom_fields.update.alert') } end end - + protected - + def set_parent_and_fields if params[:parent] == 'asset_collection' @parent = current_site.asset_collections.where(:slug => params[:slug]).first - @fields = @parent.asset_custom_fields + @fields = @parent.asset_custom_fields else @parent = current_site.content_types.where(:slug => params[:slug]).first @fields = @parent.content_custom_fields end end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/layouts_controller.rb b/app/controllers/admin/layouts_controller.rb index 868b0dd0..de79835b 100644 --- a/app/controllers/admin/layouts_controller.rb +++ b/app/controllers/admin/layouts_controller.rb @@ -1,13 +1,13 @@ module Admin class LayoutsController < BaseController - + sections 'settings' - + respond_to :json, :only => :update - + def index @layouts = current_site.layouts.order_by([[:name, :asc]]) end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/memberships_controller.rb b/app/controllers/admin/memberships_controller.rb index 29a4bfe2..43c28fb1 100644 --- a/app/controllers/admin/memberships_controller.rb +++ b/app/controllers/admin/memberships_controller.rb @@ -1,8 +1,8 @@ module Admin class MembershipsController < BaseController - + sections 'settings' - + def create @membership = current_site.memberships.build(params[:membership]) @@ -21,6 +21,6 @@ module Admin def destroy destroy! { edit_admin_current_site_url } end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/my_accounts_controller.rb b/app/controllers/admin/my_accounts_controller.rb index 1eb9e567..0036647a 100644 --- a/app/controllers/admin/my_accounts_controller.rb +++ b/app/controllers/admin/my_accounts_controller.rb @@ -1,23 +1,23 @@ module Admin class MyAccountsController < BaseController - + sections 'settings', 'account' - + actions :edit, :update - + respond_to :json, :only => :update - + def update update! { edit_admin_my_account_url } end - + protected - + def resource @account = current_admin end - + def begin_of_association_chain; nil; end # not related directly to current_site - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index 59a44d50..d2bec19b 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -12,4 +12,4 @@ module Admin end end -end \ No newline at end of file +end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index b1d8f06c..208cacdb 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -28,4 +28,4 @@ module Admin end end -end \ No newline at end of file +end diff --git a/app/controllers/admin/passwords_controller.rb b/app/controllers/admin/passwords_controller.rb index 03e2348d..b185d235 100644 --- a/app/controllers/admin/passwords_controller.rb +++ b/app/controllers/admin/passwords_controller.rb @@ -1,13 +1,13 @@ module Admin class PasswordsController < Devise::PasswordsController - + include Locomotive::Routing::SiteDispatcher layout 'admin/login' - + before_filter :require_site - + helper 'admin/base', 'admin/login' - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/rendering_controller.rb b/app/controllers/admin/rendering_controller.rb index 76b4dc2a..5c21a359 100644 --- a/app/controllers/admin/rendering_controller.rb +++ b/app/controllers/admin/rendering_controller.rb @@ -1,15 +1,15 @@ module Admin class RenderingController < ActionController::Base - + include Locomotive::Routing::SiteDispatcher - + include Locomotive::Render - + before_filter :require_site - + def show render_locomotive_page end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 79911a96..c6e1a3c4 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,19 +1,19 @@ module Admin class SessionsController < Devise::SessionsController - + include Locomotive::Routing::SiteDispatcher layout 'admin/login' - + before_filter :require_site - + helper 'admin/base', 'admin/login' - + protected - + def after_sign_in_path_for(resource) admin_pages_url end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/sitemaps_controller.rb b/app/controllers/admin/sitemaps_controller.rb index b96356aa..01f5b4a7 100644 --- a/app/controllers/admin/sitemaps_controller.rb +++ b/app/controllers/admin/sitemaps_controller.rb @@ -1,16 +1,16 @@ module Admin class SitemapsController < ActionController::Base - + include Locomotive::Routing::SiteDispatcher - + before_filter :require_site - + respond_to :xml - + def show @pages = current_site.pages.published @host = request.host end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index a14f8a18..c8df2c32 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,15 +1,15 @@ module Admin class SitesController < BaseController - + sections 'settings' - + def create @site = Site.new(params[:site]) @site.memberships.build :account => @current_admin, :admin => true - + create! { edit_admin_my_account_url } end - + def destroy @site = current_admin.sites.detect { |s| s._id == params[:id] } @@ -18,13 +18,13 @@ module Admin else @site.errors.add(:base, 'Can not destroy the site you are logging in now') end - + respond_with @site, :location => edit_admin_my_account_url end - + protected - + def begin_of_association_chain; nil; end # not related directly to current_site - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/snippets_controller.rb b/app/controllers/admin/snippets_controller.rb index 7f4dad16..efab2e74 100644 --- a/app/controllers/admin/snippets_controller.rb +++ b/app/controllers/admin/snippets_controller.rb @@ -1,13 +1,13 @@ module Admin class SnippetsController < BaseController - + sections 'settings' - + respond_to :json, :only => :update - + def index @snippets = current_site.snippets.order_by([[:name, :asc]]) end - + end -end \ No newline at end of file +end diff --git a/app/controllers/admin/theme_assets_controller.rb b/app/controllers/admin/theme_assets_controller.rb index ec730cd0..9a9d614b 100644 --- a/app/controllers/admin/theme_assets_controller.rb +++ b/app/controllers/admin/theme_assets_controller.rb @@ -40,4 +40,4 @@ module Admin end -end \ No newline at end of file +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0dd56566..e8065d95 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,3 @@ -class ApplicationController < ActionController::Base +class ApplicationController < ActionController::Base protect_from_forgery end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index ce5967fa..594b2ea5 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,7 +1,7 @@ class HomeController < ApplicationController - + def show; end - + def unknown; end - -end \ No newline at end of file + +end diff --git a/app/helpers/admin/accounts_helper.rb b/app/helpers/admin/accounts_helper.rb index 36409cf0..8982592d 100644 --- a/app/helpers/admin/accounts_helper.rb +++ b/app/helpers/admin/accounts_helper.rb @@ -1,8 +1,8 @@ module Admin::AccountsHelper - + def admin_on?(site = current_site) site.memberships.detect { |a| a.admin? && a.account == current_admin } end - + end - \ No newline at end of file + diff --git a/app/helpers/admin/assets_helper.rb b/app/helpers/admin/assets_helper.rb index b71cfdad..83f44b52 100644 --- a/app/helpers/admin/assets_helper.rb +++ b/app/helpers/admin/assets_helper.rb @@ -1,21 +1,21 @@ module Admin::AssetsHelper - + def vignette_tag(asset) image_tag(asset.vignette_url) end - + def image_dimensions_and_size(asset) content_tag(:small, "#{asset.width}px x #{asset.height}px | #{number_to_human_size(asset.size)}") end - + def allow_plain_text_editing?(asset) asset.new_record? || asset.stylesheet? || asset.javascript? end - + def image_picker_include_tags html = javascript_include_tag 'admin/plugins/json2', 'admin/plugins/scrollTo', 'admin/plugins/codemirror/codemirror', 'admin/plugins/fancybox', 'admin/plugins/plupload/plupload.full', 'admin/plugins/imagepicker' html += stylesheet_link_tag 'admin/plugins/fancybox', 'admin/box' html end -end \ No newline at end of file +end diff --git a/app/helpers/admin/base_helper.rb b/app/helpers/admin/base_helper.rb index 36c774d7..33b5cc09 100644 --- a/app/helpers/admin/base_helper.rb +++ b/app/helpers/admin/base_helper.rb @@ -1,5 +1,5 @@ module Admin::BaseHelper - + def title(title = nil) if title.nil? @content_for_title @@ -8,25 +8,25 @@ module Admin::BaseHelper '' end end - + def admin_menu_item(name, url) label = content_tag(:em) + escape_once(' ') + t("admin.shared.menu.#{name}") content_tag(:li, link_to(label, url), :class => name.dasherize) end - + def admin_button_tag(text, url, options = {}) text = text.is_a?(Symbol) ? t(".#{text}") : text link_to(url, options) do content_tag(:em, escape_once(' ')) + text end end - + def admin_submenu_item(name, url, options = {}, &block) default_options = { :i18n => true, :css => name.dasherize.downcase } default_options.merge!(options) - + css = "#{'on' if name == sections(:sub)} #{'links' if block_given?} #{options[:css]}" - + label_link = default_options[:i18n] ? t("admin.shared.menu.#{name}") : name if block_given? popup = content_tag(:div, capture(&block), :class => 'popup', :style => 'display: none') @@ -36,7 +36,7 @@ module Admin::BaseHelper content_tag(:li, link_to(content_tag(:span, label_link), url), :class => css) end end - + def growl_message if not flash.empty? %{ @@ -50,5 +50,5 @@ module Admin::BaseHelper def nocoffee_tag link_to 'noCoffee', 'http://www.nocoffee.fr', :id => 'nocoffee' end - -end \ No newline at end of file + +end diff --git a/app/helpers/admin/custom_fields_helper.rb b/app/helpers/admin/custom_fields_helper.rb index 94abfc77..4c541d76 100644 --- a/app/helpers/admin/custom_fields_helper.rb +++ b/app/helpers/admin/custom_fields_helper.rb @@ -1,36 +1,36 @@ module Admin::CustomFieldsHelper - + def options_for_field_kind(selected = nil) options = %w{String Text Category Boolean Date File}.map do |kind| [t("admin.custom_fields.kind.#{kind.downcase}"), kind] - end + end end - + def options_for_order_by(content_type, collection_name) options = %w{updated_at _position_in_list}.map do |type| [t("admin.content_types.form.order_by.#{type.gsub(/^_/, '')}"), type] end options + options_for_highlighted_field(content_type, collection_name) end - + def options_for_highlighted_field(content_type, collection_name) custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym collection = content_type.send(custom_fields_collection_name) collection.delete_if { |f| f.label == 'field name' } collection.map { |field| [field.label, field._name] } end - + def options_for_group_by_field(content_type, collection_name) custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym collection = content_type.send(custom_fields_collection_name) collection.delete_if { |f| not f.category? } collection.map { |field| [field.label, field._name] } end - + def options_for_text_formatting options = %w{none html}.map do |option| [t("admin.custom_fields.text_formatting.#{option}"), option] end end - -end \ No newline at end of file + +end diff --git a/app/helpers/admin/login_helper.rb b/app/helpers/admin/login_helper.rb index 85db3a10..13217b06 100644 --- a/app/helpers/admin/login_helper.rb +++ b/app/helpers/admin/login_helper.rb @@ -1,17 +1,17 @@ module Admin::LoginHelper - + def login_flash_message if not flash.empty? - content_tag :div, flash.values.first, - :id => "flash-#{flash.keys.first}", + content_tag :div, flash.values.first, + :id => "flash-#{flash.keys.first}", :class => 'application-message' else '' - end + end end - + def login_button_tag(label) content_tag(:button, content_tag(:span, label), :type => 'submit', :class => 'button') end - -end \ No newline at end of file + +end diff --git a/app/helpers/admin/pages_helper.rb b/app/helpers/admin/pages_helper.rb index 9c98ad06..e1b5f6ae 100644 --- a/app/helpers/admin/pages_helper.rb +++ b/app/helpers/admin/pages_helper.rb @@ -1,45 +1,45 @@ module Admin::PagesHelper - + def page_main_url(page, content = nil) - url = '' - - if page.site.domains.empty? + url = '' + + if page.site.domains.empty? url = main_site_url(page.site) else url = "http://#{current_site.domains.first}" url += ":#{request.port}" if request.port != 80 end - + if content.nil? File.join(url, page.fullpath) else - File.join(url, page.fullpath.gsub('/content_type_template', ''), content._slug) + File.join(url, page.fullpath.gsub('/content_type_template', ''), content._slug) end - end - + end + def parent_pages_options roots = current_site.pages.roots.where(:slug.ne => '404').and(:_id.ne => @page.id) - + returning [] do |list| roots.each do |page| list = add_children_to_options(page, list) end end end - + def add_children_to_options(page, list) return list if page.path.include?(@page.id) || page == @page - + offset = '- ' * (page.depth || 0) * 2 - + list << ["#{offset}#{page.title}", page.id] page.children.each { |child| add_children_to_options(child, list) } list end - + def options_for_page_cache_strategy [ - [t('.cache_strategy.none'), 'none'], + [t('.cache_strategy.none'), 'none'], [t('.cache_strategy.simple'), 'simple'], [t('.cache_strategy.hour'), 1.hour.to_s], [t('.cache_strategy.day'), 1.day.to_s], @@ -47,5 +47,5 @@ module Admin::PagesHelper [t('.cache_strategy.month'), 1.month.to_s] ] end - -end \ No newline at end of file + +end diff --git a/app/helpers/admin/sites_helper.rb b/app/helpers/admin/sites_helper.rb index 4369768e..a4c53bdf 100644 --- a/app/helpers/admin/sites_helper.rb +++ b/app/helpers/admin/sites_helper.rb @@ -1,18 +1,18 @@ module Admin::SitesHelper - + def application_domain domain = Locomotive.config.default_domain domain += ":#{request.port}" if request.port != 80 domain end - + def main_site_url(site = current_site, options = {}) url = "http://#{site.subdomain}.#{Locomotive.config.default_domain}" url += ":#{request.port}" if request.port != 80 url = File.join(url, controller.request.fullpath) if options.has_key?(:uri) && options[:uri] url end - + def error_on_domain(site, name) if (error = (site.errors[:domains] || []).detect { |n| n.include?(name) }) content_tag(:span, error, :class => 'inline-errors') @@ -20,5 +20,5 @@ module Admin::SitesHelper '' end end - -end \ No newline at end of file + +end diff --git a/app/models/account.rb b/app/models/account.rb index 1c6721ea..81836dac 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,46 +1,46 @@ class Account - + include Locomotive::Mongoid::Document - + # devise modules devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable # attr_accessible :email, :password, :password_confirmation # TODO - + ## attributes ## field :name field :locale, :default => 'en' - + ## validations ## validates_presence_of :name - + ## associations ## - - ## callbacks ## + + ## callbacks ## before_destroy :remove_memberships! - + ## methods ## - + def sites Site.where({ 'memberships.account_id' => self._id }) end - + protected - + def password_required? !persisted? || !password.blank? || !password_confirmation.blank? end - + def remove_memberships! self.sites.each do |site| site.memberships.delete_if { |m| m.account_id == self._id } - + if site.admin_memberships.empty? - raise I18n.t('errors.messages.needs_admin_account') + raise I18n.t('errors.messages.needs_admin_account') else site.save end end end - + end diff --git a/app/models/asset.rb b/app/models/asset.rb index 8ace9218..ecf91905 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -1,12 +1,12 @@ -class Asset - +class Asset + include Mongoid::Document - include Mongoid::Timestamps - - ## Extensions ## + include Mongoid::Timestamps + + ## Extensions ## include Models::Extensions::Asset::Vignette include CustomFields::ProxyClassEnabler - + ## fields ## field :name, :type => String field :content_type, :type => String @@ -15,25 +15,25 @@ class Asset field :size, :type => Integer field :position, :type => Integer, :default => 0 mount_uploader :source, AssetUploader - + ## associations ## embedded_in :collection, :class_name => 'AssetCollection', :inverse_of => :assets - + ## validations ## validates_presence_of :name, :source - + ## behaviours ## ## methods ## - + %w{image stylesheet javascript pdf video audio}.each do |type| define_method("#{type}?") do self.content_type == type - end + end end - + def to_liquid { :url => self.source.url }.merge(self.attributes) end - -end \ No newline at end of file + +end diff --git a/app/models/asset_collection.rb b/app/models/asset_collection.rb index ca0bc48d..ab4d6171 100644 --- a/app/models/asset_collection.rb +++ b/app/models/asset_collection.rb @@ -1,60 +1,60 @@ class AssetCollection - + include Locomotive::Mongoid::Document - + ## fields ## field :name field :slug - + ## associations ## belongs_to_related :site embeds_many :assets - + ## behaviours ## custom_fields_for :assets liquid_methods :name, :ordered_assets - + ## callbacks ## before_validation :normalize_slug before_save :store_asset_positions! - + ## validations ## validates_presence_of :site, :name, :slug validates_uniqueness_of :slug, :scope => :site_id - + ## methods ## - + def ordered_assets self.assets.sort { |a, b| (a.position || 0) <=> (b.position || 0) } end - + def assets_order self.ordered_assets.collect(&:id).join(',') end - + def assets_order=(order) @assets_order = order end - + protected - + def normalize_slug - self.slug = self.name.clone if self.slug.blank? && self.name.present? + self.slug = self.name.clone if self.slug.blank? && self.name.present? self.slug.slugify! if self.slug.present? end - + def store_asset_positions! return if @assets_order.nil? - + @assets_order.split(',').each_with_index do |asset_id, index| self.assets.find(asset_id).position = index end - + self.assets.clone.each do |asset| if !@assets_order.split(',').include?(asset._id) - self.assets.delete(asset) + self.assets.delete(asset) asset.send(:delete) end end end -end \ No newline at end of file +end diff --git a/app/models/content_instance.rb b/app/models/content_instance.rb index 9728bdb2..d4f4a1c8 100644 --- a/app/models/content_instance.rb +++ b/app/models/content_instance.rb @@ -2,71 +2,71 @@ class ContentInstance include Mongoid::Document include Mongoid::Timestamps - + ## extensions ## include CustomFields::ProxyClassEnabler - + ## fields (dynamic fields) ## field :_slug field :_position_in_list, :type => Integer, :default => 0 field :_visible, :type => Boolean, :default => true - + ## validations ## validate :require_highlighted_field - + ## associations ## embedded_in :content_type, :inverse_of => :contents - + ## callbacks ## before_save :set_slug before_save :set_visibility before_create :add_to_list_bottom - + ## named scopes ## named_scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_items_nb - + ## methods ## - + alias :visible? :_visible? - + def visible? self._visible || self._visible.nil? end - + def to_liquid Locomotive::Liquid::Drops::Content.new(self) end - + protected - + def set_slug _alias = self.highlighted_field_alias self._slug = self.send(_alias).parameterize('_') end - + def set_visibility field = self.content_type.content_custom_fields.detect { |f| %w{visible active}.include?(f._alias) } self._visible = self.send(field._name) rescue true end - + def add_to_list_bottom Rails.logger.debug "add_to_list_bottom" self._position_in_list = self.content_type.contents.size end - + def require_highlighted_field _alias = self.highlighted_field_alias if self.send(_alias).blank? self.errors.add(_alias, :blank) end end - + def highlighted_field_value self.send(self.content_type.highlighted_field._name) end - + def highlighted_field_alias self.content_type.highlighted_field._alias.to_sym end - -end \ No newline at end of file + +end diff --git a/app/models/content_type.rb b/app/models/content_type.rb index ded3fbdd..99b9f355 100644 --- a/app/models/content_type.rb +++ b/app/models/content_type.rb @@ -1,7 +1,7 @@ class ContentType - + include Locomotive::Mongoid::Document - + ## fields ## field :name field :description @@ -10,7 +10,7 @@ class ContentType field :highlighted_field_name field :group_by_field_name field :api_enabled, :type => Boolean, :default => false - + ## associations ## belongs_to_related :site embeds_many :contents, :class_name => 'ContentInstance' do @@ -22,21 +22,21 @@ class ContentType ## callbacks ## before_validation :normalize_slug before_save :set_default_values - + ## validations ## validates_presence_of :site, :name, :slug validates_uniqueness_of :slug, :scope => :site_id validates_size_of :content_custom_fields, :minimum => 1, :message => :array_too_short - + ## behaviours ## custom_fields_for :contents - + ## methods ## - + def groupable? self.group_by_field && group_by_field.category? end - + def list_or_group_contents if self.groupable? groups = self.contents.klass.send(:"group_by_#{self.group_by_field._alias}", :ordered_contents) @@ -52,42 +52,42 @@ class ContentType self.ordered_contents end end - + def ordered_contents(conditions = {}) column = self.order_by.to_sym - + (if conditions.nil? || conditions.empty? self.contents else self.contents.where(conditions) end).sort { |a, b| (a.send(column) || 0) <=> (b.send(column) || 0) } end - + def sort_contents!(order) order.split(',').each_with_index do |id, position| self.contents.find(id)._position_in_list = position end self.save end - + def highlighted_field self.content_custom_fields.detect { |f| f._name == self.highlighted_field_name } end - + def group_by_field @group_by_field ||= self.content_custom_fields.detect { |f| f._name == self.group_by_field_name } end - + protected - + def set_default_values self.order_by ||= 'updated_at' self.highlighted_field_name ||= self.content_custom_fields.first._name end - + def normalize_slug - self.slug = self.name.clone if self.slug.blank? && self.name.present? + self.slug = self.name.clone if self.slug.blank? && self.name.present? self.slug.slugify! if self.slug.present? end - -end \ No newline at end of file + +end diff --git a/app/models/extensions/asset/vignette.rb b/app/models/extensions/asset/vignette.rb index ed822528..20c22baa 100644 --- a/app/models/extensions/asset/vignette.rb +++ b/app/models/extensions/asset/vignette.rb @@ -1,8 +1,8 @@ -module Models - module Extensions - module Asset +module Models + module Extensions + module Asset module Vignette - + def vignette_url if self.image? if self.width < 80 && self.height < 80 @@ -16,9 +16,9 @@ module Models mime_type_to_url(:medium) end end - + protected - + def mime_type_to_url(size) mime_type = File.mime_type?(self.source_filename) filename = "unknown" @@ -35,8 +35,8 @@ module Models File.join("admin", "icons", "filetype", size.to_s, filename + ".png") end - - end - end - end -end \ No newline at end of file + + end + end + end +end diff --git a/app/models/extensions/page/parts.rb b/app/models/extensions/page/parts.rb index 7b816a25..5151d9dc 100644 --- a/app/models/extensions/page/parts.rb +++ b/app/models/extensions/page/parts.rb @@ -1,28 +1,28 @@ -module Models - module Extensions - module Page - module Parts +module Models + module Extensions + module Page + module Parts extend ActiveSupport::Concern included do - + before_create { |p| p.parts << PagePart.build_body_part if p.parts.empty? } - - end - + + end + module InstanceMethods - - def parts_attributes=(attributes) + + def parts_attributes=(attributes) self.update_parts(attributes.values.map { |attrs| PagePart.new(attrs) }) end - + def joined_parts self.parts.enabled.map(&:template).join('') end - + protected - + def update_parts(parts) performed = [] @@ -46,9 +46,9 @@ module Models self.update_parts(new_parts) self.save end - - end - end - end - end -end \ No newline at end of file + + end + end + end + end +end diff --git a/app/models/extensions/page/render.rb b/app/models/extensions/page/render.rb index 282f8613..4ad2fc2c 100644 --- a/app/models/extensions/page/render.rb +++ b/app/models/extensions/page/render.rb @@ -1,6 +1,6 @@ -module Models - module Extensions - module Page +module Models + module Extensions + module Page module Render def render(context) @@ -12,8 +12,8 @@ module Models ::Liquid::Template.parse("{{ content_for_layout }}").render(context) end end - - end - end - end -end \ No newline at end of file + + end + end + end +end diff --git a/app/models/extensions/page/templatized.rb b/app/models/extensions/page/templatized.rb index 57906454..7ac030f3 100644 --- a/app/models/extensions/page/templatized.rb +++ b/app/models/extensions/page/templatized.rb @@ -1,32 +1,32 @@ -module Models - module Extensions - module Page - module Templatized +module Models + module Extensions + module Page + module Templatized extend ActiveSupport::Concern included do - + belongs_to_related :content_type - + field :templatized, :type => Boolean, :default => false - + field :content_type_visible_column - + before_validation :set_slug_if_templatized end - + module InstanceMethods - + def set_slug_if_templatized self.slug = 'content_type_template' if self.templatized? end - + end - + end end end end - - \ No newline at end of file + + diff --git a/app/models/extensions/page/tree.rb b/app/models/extensions/page/tree.rb index 4a6fc54c..ae593bba 100644 --- a/app/models/extensions/page/tree.rb +++ b/app/models/extensions/page/tree.rb @@ -1,19 +1,19 @@ -module Models - module Extensions - module Page - module Tree +module Models + module Extensions + module Page + module Tree extend ActiveSupport::Concern included do include Mongoid::Acts::Tree - + ## fields ## field :position, :type => Integer - + ## behaviours ## acts_as_tree :order => ['position', 'asc'] - + ## callbacks ## before_validation :reset_parent before_save { |p| p.send(:write_attribute, :parent_id, nil) if p.parent_id.blank? } @@ -24,10 +24,10 @@ module Models # Fixme (Didier L.): Instances methods are defined before the include itself alias :fix_position :hacked_fix_position - end - + end + module InstanceMethods - + def sort_children!(ids) ids.each_with_index do |id, position| child = self.children.detect { |p| p._id == id } @@ -35,15 +35,15 @@ module Models child.save end end - + def parent=(owner) # missing in acts_as_tree @_parent = owner self.fix_position(false) self.instance_variable_set :@_will_move, true end - + protected - + def change_parent if self.parent_id_changed? self.fix_position(false) @@ -63,15 +63,15 @@ module Models self[depth_field] = parent[depth_field] + 1 self.save if perform_save end - end - + end + def reset_parent if self.parent_id_changed? @_parent = nil end end - - def add_to_list_bottom + + def add_to_list_bottom self.position = (::Page.where(:_id.ne => self._id).and(:parent_id => self.parent_id).max(:position) || 0) + 1 end @@ -83,9 +83,9 @@ module Models p.save end end - - end - end - end - end -end \ No newline at end of file + + end + end + end + end +end diff --git a/app/models/layout.rb b/app/models/layout.rb index 9a68d7e8..bf90b9a0 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -3,46 +3,46 @@ class Layout < LiquidTemplate ## associations ## has_many_related :pages embeds_many :parts, :class_name => 'PagePart' - + ## callbacks ## before_save :build_parts_from_value after_save :update_parts_in_pages - + ## validations ## validates_format_of :value, :with => Locomotive::Regexps::CONTENT_FOR_LAYOUT, :message => :missing_content_for_layout - + ## methods ## - + protected - + def build_parts_from_value if self.value_changed? || self.new_record? self.parts.each { |p| p.disabled = true } - + self.value.scan(Locomotive::Regexps::CONTENT_FOR).each do |attributes| slug = attributes[0].strip.downcase name = slug.humanize name = I18n.t('attributes.defaults.page_parts.name') if slug == 'layout' - + if part = self.parts.detect { |p| p.slug == slug } part.name = name if name.present? part.disabled = false else self.parts.build :slug => slug, :name => name || slug - end + end end - + # body always first body = self.parts.detect { |p| p.slug == 'layout' } self.parts.delete(body) self.parts.insert(0, body) - + @_update_pages = true if self.value_changed? end end - + def update_parts_in_pages self.pages.each { |p| p.send(:update_parts!, self.parts) } if @_update_pages - end - -end \ No newline at end of file + end + +end diff --git a/app/models/liquid_template.rb b/app/models/liquid_template.rb index ca234981..d80b8194 100644 --- a/app/models/liquid_template.rb +++ b/app/models/liquid_template.rb @@ -1,32 +1,32 @@ class LiquidTemplate - + include Locomotive::Mongoid::Document - + ## fields ## field :name field :slug field :value - + ## associations ## belongs_to_related :site - + ## callbacks ## before_validation :normalize_slug - + ## validations ## validates_presence_of :site, :name, :slug, :value validates_uniqueness_of :slug, :scope => :site_id - + ## behaviours ## liquify_template :value - + ## methods ## - + protected - + def normalize_slug self.slug = self.name.clone if self.slug.blank? && self.name.present? self.slug.slugify!(:without_extension => true, :downcase => true) if self.slug.present? end - -end \ No newline at end of file + +end diff --git a/app/models/membership.rb b/app/models/membership.rb index 2ce4f12c..706c1409 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -1,26 +1,26 @@ class Membership - + include Locomotive::Mongoid::Document - + ## fields ## field :admin, :type => Boolean, :default => false - + ## associations ## belongs_to_related :account embedded_in :site, :inverse_of => :memberships - + ## validations ## validates_presence_of :account - + ## methods ## - + def email; @email; end - + def email=(email) @email = email self.account = Account.where(:email => email).first end - + def process! if @email.blank? self.errors.add_on_blank(:email) @@ -35,5 +35,5 @@ class Membership :save_it end end - -end \ No newline at end of file + +end diff --git a/app/models/page.rb b/app/models/page.rb index a2a557b5..a91e1118 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -96,4 +96,4 @@ class Page self.slug.slugify!(:without_extension => true) if self.slug.present? end -end \ No newline at end of file +end diff --git a/app/models/page_part.rb b/app/models/page_part.rb index ebec960b..410bcaca 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -1,5 +1,5 @@ class PagePart - + include Mongoid::Document ## fields ## @@ -8,28 +8,28 @@ class PagePart field :value field :disabled, :type => Boolean, :default => false field :value - + ## associations ## embedded_in :page, :inverse_of => :parts - + ## validations ## validates_presence_of :name, :slug - + ## named scopes ## named_scope :enabled, where(:disabled => false) - + ## methods ## - + def template "{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}" end - + def self.build_body_part self.new({ - :name => I18n.t('attributes.defaults.page_parts.name'), - :value => I18n.t('attributes.defaults.pages.other.body'), + :name => I18n.t('attributes.defaults.page_parts.name'), + :value => I18n.t('attributes.defaults.pages.other.body'), :slug => 'layout' }) end - -end \ No newline at end of file + +end diff --git a/app/models/site.rb b/app/models/site.rb index 378c87c7..79839f7f 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -93,4 +93,4 @@ class Site end end -end \ No newline at end of file +end diff --git a/app/models/snippet.rb b/app/models/snippet.rb index b758c47d..d7700f04 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -1,3 +1,3 @@ class Snippet < LiquidTemplate -end \ No newline at end of file +end diff --git a/app/models/theme_asset.rb b/app/models/theme_asset.rb index 08abdb47..feb12932 100644 --- a/app/models/theme_asset.rb +++ b/app/models/theme_asset.rb @@ -117,4 +117,4 @@ class ThemeAsset self.errors.add(:source, :extname_changed) end end -end \ No newline at end of file +end diff --git a/app/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb index 310eadca..41eaae9e 100644 --- a/app/uploaders/asset_uploader.rb +++ b/app/uploaders/asset_uploader.rb @@ -7,16 +7,16 @@ class AssetUploader < CarrierWave::Uploader::Base def store_dir "sites/#{model.collection.site_id}/assets/#{model.id}" end - + def cache_dir "#{Rails.root}/tmp/uploads" end - + version :thumb do process :resize_to_fill => [50, 50] process :convert => 'png' end - + version :medium do process :resize_to_fill => [80, 80] process :convert => 'png' @@ -24,18 +24,18 @@ class AssetUploader < CarrierWave::Uploader::Base version :preview do process :resize_to_fit => [880, 1100] - process :convert => 'png' + process :convert => 'png' end - - process :set_content_type + + process :set_content_type process :set_size process :set_width_and_height def set_content_type value = :other - + content_type = file.content_type == 'application/octet-stream' ? File.mime_type?(original_filename) : file.content_type - + self.class.content_types.each_pair do |type, rules| rules.each do |rule| case rule @@ -44,20 +44,20 @@ class AssetUploader < CarrierWave::Uploader::Base end end end - + model.content_type = value end - + def set_size model.size = file.size end - + def set_width_and_height if model.image? model.width, model.height = `identify -format "%wx%h" #{file.path}`.split(/x/).collect(&:to_i) end end - + def self.content_types { :image => ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], @@ -67,7 +67,7 @@ class AssetUploader < CarrierWave::Uploader::Base :stylesheet => ['text/css'], :javascript => ['text/javascript', 'text/js', 'application/x-javascript', 'application/javascript'], :font => ['application/x-font-ttf', 'application/vnd.ms-fontobject'] - } + } end - + end diff --git a/app/uploaders/theme_asset_uploader.rb b/app/uploaders/theme_asset_uploader.rb index 91d70507..30a7025b 100644 --- a/app/uploaders/theme_asset_uploader.rb +++ b/app/uploaders/theme_asset_uploader.rb @@ -1,16 +1,16 @@ # encoding: utf-8 class ThemeAssetUploader < AssetUploader - - process :set_content_type + + process :set_content_type process :set_size process :set_width_and_height - + version :thumb do process :resize_to_fill => [50, 50] process :convert => 'png' end - + version :medium do process :resize_to_fill => [80, 80] process :convert => 'png' @@ -18,15 +18,15 @@ class ThemeAssetUploader < AssetUploader version :preview do process :resize_to_fit => [880, 1100] - process :convert => 'png' + process :convert => 'png' end - + def store_dir "sites/#{model.site_id}/themes/#{model.id}" end - + def extension_white_list %w(jpg jpeg gif png css js swf flv) end - -end \ No newline at end of file + +end diff --git a/config/application.rb b/config/application.rb index f92fc691..95b268ee 100644 --- a/config/application.rb +++ b/config/application.rb @@ -40,7 +40,7 @@ module Locomotive # g.template_engine :erb # g.test_framework :test_unit, :fixture => true # end - + # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/config/environments/development.rb b/config/environments/development.rb index 8f0b8fa1..59bddb8e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -31,4 +31,4 @@ end CarrierWave.configure do |config| config.storage = :file config.root = File.join(Rails.root, 'public') -end \ No newline at end of file +end diff --git a/config/environments/production.rb b/config/environments/production.rb index df40dde6..1d300072 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -30,4 +30,4 @@ Locomotive::Application.configure do # Enable threaded mode # config.threadsafe! -end \ No newline at end of file +end diff --git a/config/environments/test.rb b/config/environments/test.rb index 84902d73..ac3458bd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -30,4 +30,4 @@ end CarrierWave.configure do |config| config.storage = :file -end \ No newline at end of file +end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index a6d0b89b..a36924a5 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -143,4 +143,4 @@ Devise.setup do |config| # end # manager.default_strategies(:scope => :user).unshift :twitter_oauth # end -end \ No newline at end of file +end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index d531b8bb..9e8b0131 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format +# Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' diff --git a/config/initializers/locomotive.rb b/config/initializers/locomotive.rb index d476087a..2e9e7fe6 100644 --- a/config/initializers/locomotive.rb +++ b/config/initializers/locomotive.rb @@ -6,24 +6,24 @@ Locomotive.configure do |config| # Ex: # config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com' config.default_domain = 'example.com' - - # configure how many items we display in sub menu in the "Contents" section. + + # configure how many items we display in sub menu in the "Contents" section. config.lastest_items_nb = 5 - + # tell if logs are enabled. Useful for debug purpose. config.enable_logs = true - + # tell if the application is hosted on Heroku. # Locomotive uses heroku api to add / remove domains. # there are 2 ways of passing heroku credentials to Locomotive # - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD # - from this file # - # Notes: - # - IMPORTANT: behaviours related to this option will only be applied in production + # Notes: + # - IMPORTANT: behaviours related to this option will only be applied in production # - credentials coming from this file take precedence over ENV variables - # + # # Ex: # config.heroku = { :name => '', :login => 'john@doe.net', :password => 'easy' } config.heroku = false -end \ No newline at end of file +end diff --git a/config/initializers/rspec_generator.rb b/config/initializers/rspec_generator.rb index 646ac896..b5f8d91c 100644 --- a/config/initializers/rspec_generator.rb +++ b/config/initializers/rspec_generator.rb @@ -5,4 +5,4 @@ if Rails.env.test? g.test_framework :rspec end end -end \ No newline at end of file +end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 5dcbc0e9..e131726c 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -2,6 +2,6 @@ # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! -# Make sure the secret is at least 30 characters and all random, +# Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Rails.application.config.secret_token = 'aa84844b97e90edda8e005a686d82c3bef1f8e20a1255301f1d0886fc592a45ef2393d64b0c3d3ea858b1f6406ad6f15305666264716a79fcfa17de93ad0d69d' diff --git a/db/seeds.rb b/db/seeds.rb index 78fc6b53..ce519bc3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,4 +6,4 @@ site.save! puts "Your first website has been created !" puts "Admin url: http://test.example.com:3000/admin" -puts "Crendetials: admin@example.com / locomotive" \ No newline at end of file +puts "Crendetials: admin@example.com / locomotive" diff --git a/features/step_definitions/admin_steps.rb b/features/step_definitions/admin_steps.rb index 3999cb49..358afc48 100644 --- a/features/step_definitions/admin_steps.rb +++ b/features/step_definitions/admin_steps.rb @@ -41,7 +41,7 @@ end ## Common def create_site_and_admin_account - @site = Factory(:site, :name => 'Locomotive test website', :subdomain => 'test') + @site = Factory(:site, :name => 'Locomotive test website', :subdomain => 'test') @admin = Factory(:account, { :name => 'Admin', :email => 'admin@locomotiveapp.org' }) @site.memberships.build :account => @admin, :admin => true @site.save @@ -56,5 +56,5 @@ def create_layout_samples
\{\{ content_for_layout \}\}
}) - Factory(:layout, :site => @site) -end \ No newline at end of file + Factory(:layout, :site => @site) +end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index e5775052..d2523476 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -1,6 +1,6 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. @@ -191,7 +191,7 @@ Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do end end end - + Then /^(?:|I )should be on (.+)$/ do |page_name| current_path = URI.parse(current_url).path if current_path.respond_to? :should @@ -205,8 +205,8 @@ Then /^(?:|I )should have the following query string:$/ do |expected_pairs| query = URI.parse(current_url).query actual_params = query ? CGI.parse(query) : {} expected_params = {} - expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} - + expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} + if actual_params.respond_to? :should actual_params.should == expected_params else diff --git a/features/support/env.rb b/features/support/env.rb index 9c0315ed..9f0525b7 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,6 +1,6 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. @@ -22,7 +22,7 @@ require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links wi # steps to use the XPath syntax. Capybara.default_selector = :css -# If you set this to false, any error raised from within your app will bubble +# If you set this to false, any error raised from within your app will bubble # up to your step definition and out to cucumber unless you catch it somewhere # on the way. You can make Rails rescue errors and render error pages on a # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. @@ -43,4 +43,4 @@ Locomotive.configure do |config| config.default_domain = 'example.com' end -Capybara.default_host = 'test.example.com' \ No newline at end of file +Capybara.default_host = 'test.example.com' diff --git a/lib/core_ext.rb b/lib/core_ext.rb index 61cfc247..4553236a 100644 --- a/lib/core_ext.rb +++ b/lib/core_ext.rb @@ -3,7 +3,7 @@ class String # def perma_string(sep = '_') # ActiveSupport::Inflector.parameterize(self, sep).to_s # end - + def slugify(options = {}) options = { :sep => '_', :without_extension => false, :downcase => false, :underscore => false }.merge(options) # replace accented chars with ther ascii equivalents @@ -24,21 +24,21 @@ class String s.gsub!(/[\-]/i, '_') if options[:underscore] s end - + def slugify!(options = {}) replace(self.slugify(options)) end - + end ## Hash class Hash - + def underscore_keys new_hash = {} - - self.each_pair do |key, value| + + self.each_pair do |key, value| if value.respond_to?(:collect!) # Array value.collect do |item| if item.respond_to?(:each_pair) # Hash item within @@ -50,13 +50,13 @@ class Hash elsif value.respond_to?(:each_pair) # Hash value = value.underscore_keys end - + new_key = key.is_a?(String) ? key.underscore : key # only String keys - + new_hash[new_key] = value end - + self.replace(new_hash) end - -end \ No newline at end of file + +end diff --git a/lib/generators/locomotive/copy_assets/copy_assets_generator.rb b/lib/generators/locomotive/copy_assets/copy_assets_generator.rb index 1be5fe57..5eb058f4 100644 --- a/lib/generators/locomotive/copy_assets/copy_assets_generator.rb +++ b/lib/generators/locomotive/copy_assets/copy_assets_generator.rb @@ -1,14 +1,14 @@ module Locomotive class CopyAssetsGenerator < Rails::Generators::Base - - def self.source_root + + def self.source_root @_locomotive_source_root ||= File.expand_path('../../../../../', __FILE__) @_locomotive_source_root end - + def copy_public_files directory 'public', 'public', :recursive => true end - + end -end \ No newline at end of file +end diff --git a/lib/generators/locomotive/install/install_generator.rb b/lib/generators/locomotive/install/install_generator.rb index 3d68880a..f2443a8a 100644 --- a/lib/generators/locomotive/install/install_generator.rb +++ b/lib/generators/locomotive/install/install_generator.rb @@ -8,7 +8,7 @@ module Locomotive def copy_initializer template 'locomotive.rb', 'config/initializers/locomotive.rb' end - + def seed_db append_file 'db/seeds.rb', %{ # Uncomment the following lines if you want to create the first website / account @@ -17,10 +17,10 @@ module Locomotive #site.memberships.build :account => account, :admin => true #site.save!} end - + def show_readme readme 'README' end end -end \ No newline at end of file +end diff --git a/lib/generators/locomotive/install/templates/locomotive.rb b/lib/generators/locomotive/install/templates/locomotive.rb index a46eedbe..d2127619 100644 --- a/lib/generators/locomotive/install/templates/locomotive.rb +++ b/lib/generators/locomotive/install/templates/locomotive.rb @@ -3,24 +3,24 @@ Locomotive.configure do |config| # Ex: # config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com' config.default_domain = 'mydomain.com' - - # configure how many items we display in sub menu in the "Contents" section. + + # configure how many items we display in sub menu in the "Contents" section. config.lastest_items_nb = 5 - + # tell if logs are enabled. Useful for debug purpose. config.enable_logs = true - + # tell if the application is hosted on Heroku. # Locomotive uses heroku api to add / remove domains. # there are 2 ways of passing heroku credentials to Locomotive # - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD # - from this file # - # Notes: - # - IMPORTANT: behaviours related to this option will only be applied in production + # Notes: + # - IMPORTANT: behaviours related to this option will only be applied in production # - credentials coming from this file take precedence over ENV variables - # + # # Ex: # config.heroku = { :name => '', :login => 'john@doe.net', :password => 'easy' } config.heroku = false -end \ No newline at end of file +end diff --git a/lib/locomotive.rb b/lib/locomotive.rb index 58aa8ca1..254703a4 100644 --- a/lib/locomotive.rb +++ b/lib/locomotive.rb @@ -13,43 +13,43 @@ require 'locomotive/admin_responder' require 'mongo_session_store/mongoid' module Locomotive - + include Locomotive::Heroku - + class << self attr_accessor :config - + def config self.config = Configuration.new unless @config @config end end - + def self.configure self.config ||= Configuration.new yield(self.config) - + after_configure end - + def self.after_configure raise '[Error] Locomotive needs a default domain name' if Locomotive.config.default_domain.blank? - + ActionMailer::Base.default_url_options[:host] = self.config.default_domain + (Rails.env.development? ? ':3000' : '') # cookies stored in mongodb (mongoid_store) Rails.application.config.session_store :mongoid_store, { :key => Locomotive.config.cookie_key } - + # Heroku support self.enable_heroku if self.heroku? end - + def self.logger(message) if Locomotive.config.enable_logs == true Rails.logger.info(message) end end - -end \ No newline at end of file + +end diff --git a/lib/locomotive/admin_responder.rb b/lib/locomotive/admin_responder.rb index d023972b..693044c2 100644 --- a/lib/locomotive/admin_responder.rb +++ b/lib/locomotive/admin_responder.rb @@ -2,9 +2,9 @@ require 'responders' module Locomotive class AdminResponder < ::ActionController::Responder - + include ::Responders::FlashResponder - + def api_behavior(error) raise error unless resourceful? @@ -20,9 +20,9 @@ module Locomotive else display({ :notice => controller.flash[:notice] }) end - + controller.flash.discard # reset flash messages ! end - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/carrierwave/base.rb b/lib/locomotive/carrierwave/base.rb index 4c8a929c..c64a620c 100644 --- a/lib/locomotive/carrierwave/base.rb +++ b/lib/locomotive/carrierwave/base.rb @@ -1,7 +1,7 @@ module CarrierWave module Uploader class Base - + def to_liquid { :url => self.url, @@ -9,7 +9,7 @@ module CarrierWave :size => self.size }.stringify_keys end - + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/carrierwave/patches.rb b/lib/locomotive/carrierwave/patches.rb index d1fd165b..7d852fe8 100644 --- a/lib/locomotive/carrierwave/patches.rb +++ b/lib/locomotive/carrierwave/patches.rb @@ -1,26 +1,26 @@ require 'carrierwave' module CarrierWave - + class SanitizedFile - + def original_filename=(filename) @original_filename = filename end - + def content_type=(content_type) @content_type = content_type end - + # http://github.com/jnicklas/carrierwave/issuesearch?state=closed&q=content+type#issue/48 def copy_to_with_content_type(new_path, permissions=nil) new_file = self.copy_to_without_content_type(new_path, permissions) new_file.content_type = self.content_type new_file end - + alias_method_chain :copy_to, :content_type - + # FIXME (Did) CarrierWave speaks mime type now def content_type return @content_type if @content_type @@ -30,9 +30,9 @@ module CarrierWave File.mime_type?(@file) if @file.is_a?(String) end end - + end - + end module CarrierWave @@ -44,7 +44,7 @@ module CarrierWave record.errors.add attr, options[:message] if record.send("#{attr}_integrity_error") end end - + def validates_processing_of(*attrs) options = attrs.last.is_a?(Hash) ? attrs.last : {} options[:message] ||= I18n.t('carrierwave.errors.processing', :default => 'failed to be processed.') diff --git a/lib/locomotive/configuration.rb b/lib/locomotive/configuration.rb index 5f3a6b7e..fd272fd4 100644 --- a/lib/locomotive/configuration.rb +++ b/lib/locomotive/configuration.rb @@ -1,4 +1,4 @@ -module Locomotive +module Locomotive class Configuration @@defaults = { @@ -18,7 +18,7 @@ module Locomotive def initialize @@settings = self.class.get_from_hash(@@defaults) end - + def self.settings @@settings end @@ -43,7 +43,7 @@ module Locomotive # specialized hash for storing configuration settings class ConfigurationHash < Hash - # ensure that default entries always produce + # ensure that default entries always produce # instances of the ConfigurationHash class def default(key=nil) include?(key) ? self[key] : self[key] = self.class.new @@ -59,11 +59,11 @@ module Locomotive # i.e. params.id === params[:id] # note: all keys are converted to symbols def method_missing(name, *args, &block) - if name.to_s.ends_with? '=' + if name.to_s.ends_with? '=' send :[]=, name.to_s.chomp('=').to_sym, *args else send(:[], name.to_sym, &block) - end - end + end + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/custom_fields.rb b/lib/locomotive/custom_fields.rb index cc48b2f9..f29f7447 100644 --- a/lib/locomotive/custom_fields.rb +++ b/lib/locomotive/custom_fields.rb @@ -3,7 +3,7 @@ module CustomFields module Types module File class FileUploader < ::CarrierWave::Uploader::Base - + def store_dir "sites/#{model.content_type.site_id}/contents/#{model.id}/files" end @@ -11,8 +11,8 @@ module CustomFields def cache_dir "#{Rails.root}/tmp/uploads" end - - end + + end end end -end \ No newline at end of file +end diff --git a/lib/locomotive/engine.rb b/lib/locomotive/engine.rb index 2c9598eb..05f33d6e 100644 --- a/lib/locomotive/engine.rb +++ b/lib/locomotive/engine.rb @@ -18,4 +18,4 @@ module Locomotive class Engine < Rails::Engine end -end \ No newline at end of file +end diff --git a/lib/locomotive/heroku.rb b/lib/locomotive/heroku.rb index 753ffea6..8795aa52 100644 --- a/lib/locomotive/heroku.rb +++ b/lib/locomotive/heroku.rb @@ -2,58 +2,58 @@ require 'heroku' module Locomotive module Heroku - + extend ActiveSupport::Concern - + included do class << self attr_accessor :heroku_connection attr_accessor :heroku_domains end end - + module ClassMethods - + def heroku? !self.config.heroku.nil? && self.config.heroku.respond_to?(:[]) end - + def enable_heroku raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank? - + self.open_heroku_connection self.enhance_site_model - + # "cache" domains for better performance self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] } end - + def open_heroku_connection login = self.config.heroku[:login] || ENV['HEROKU_LOGIN'] password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD'] - + self.heroku_connection = ::Heroku::Client.new(login, password) end - + def enhance_site_model Site.send :include, Locomotive::Heroku::CustomDomain end - + # manage domains - + def add_heroku_domain(name) Locomotive.logger "[add heroku domain] #{name}" self.heroku_connection.add_domain(self.config.heroku[:name], name) self.heroku_domains << name end - + def remove_heroku_domain(name) Locomotive.logger "[remove heroku domain] #{name}" self.heroku_connection.remove_domain(self.config.heroku[:name], name) self.heroku_domains.delete(name) end - + end - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/heroku/custom_domain.rb b/lib/locomotive/heroku/custom_domain.rb index c7a84657..ebd20186 100644 --- a/lib/locomotive/heroku/custom_domain.rb +++ b/lib/locomotive/heroku/custom_domain.rb @@ -1,21 +1,21 @@ module Locomotive module Heroku module CustomDomain - + extend ActiveSupport::Concern - + included do - + after_save :add_heroku_domains after_destroy :remove_heroku_domains - + alias_method_chain :add_subdomain_to_domains, :heroku end - + module InstanceMethods - + protected - + def add_subdomain_to_domains_with_heroku unless self.domains_change.nil? full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}" @@ -24,13 +24,13 @@ module Locomotive :removed => self.domains_change.first - self.domains_change.last - [full_subdomain] } end - + add_subdomain_to_domains_without_heroku end - + def add_heroku_domains return if @heroku_domains_change.nil? - + @heroku_domains_change[:added].each do |name| Locomotive.add_heroku_domain(name) end @@ -38,15 +38,15 @@ module Locomotive Locomotive.remove_heroku_domain(name) end end - + def remove_heroku_domains self.domains_without_subdomain.each do |name| Locomotive.remove_heroku_domain(name) end end - + end - + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/httparty.rb b/lib/locomotive/httparty.rb index c19d7876..4065b8ee 100644 --- a/lib/locomotive/httparty.rb +++ b/lib/locomotive/httparty.rb @@ -1,2 +1,2 @@ require 'locomotive/httparty/webservice' -require 'locomotive/httparty/patches' \ No newline at end of file +require 'locomotive/httparty/patches' diff --git a/lib/locomotive/httparty/patches.rb b/lib/locomotive/httparty/patches.rb index 075e966f..8be6c824 100644 --- a/lib/locomotive/httparty/patches.rb +++ b/lib/locomotive/httparty/patches.rb @@ -2,17 +2,17 @@ require 'crack/json' module Crack class JSON - + def self.parse_with_tumblr(json) cleaned_json = json.gsub(/^var\s+.+\s+=\s+/, '').gsub(/;$/, '') parse_without_tumblr(cleaned_json) rescue ArgumentError => e raise ParseError, "Invalid JSON string #{e.inspect}" end - + class << self alias_method_chain :parse, :tumblr end - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/httparty/webservice.rb b/lib/locomotive/httparty/webservice.rb index 14b370d4..7ab4a59c 100644 --- a/lib/locomotive/httparty/webservice.rb +++ b/lib/locomotive/httparty/webservice.rb @@ -1,7 +1,7 @@ module Locomotive module Httparty class Webservice - + include ::HTTParty def self.consume(url, options = {}) @@ -19,7 +19,7 @@ module Locomotive self.get(path, options).try(:underscore_keys) end - + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/inherited_resources.rb b/lib/locomotive/inherited_resources.rb index aab61f30..edf1366a 100644 --- a/lib/locomotive/inherited_resources.rb +++ b/lib/locomotive/inherited_resources.rb @@ -35,12 +35,12 @@ module InheritedResources options[:location] ||= collection_url rescue nil destroy_resource(object) - + options[:alert] = object.errors.full_messages.first # display the first error if present - + respond_with_dual_blocks(object, options, &block) end alias :destroy! :destroy - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid.rb b/lib/locomotive/liquid.rb index cae42329..a07529a9 100644 --- a/lib/locomotive/liquid.rb +++ b/lib/locomotive/liquid.rb @@ -2,4 +2,4 @@ Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib } end -::Liquid::Template.file_system = Locomotive::Liquid::DbFileSystem.new # enable snippets \ No newline at end of file +::Liquid::Template.file_system = Locomotive::Liquid::DbFileSystem.new # enable snippets diff --git a/lib/locomotive/liquid/db_file_system.rb b/lib/locomotive/liquid/db_file_system.rb index 1defec7b..fddf4d48 100644 --- a/lib/locomotive/liquid/db_file_system.rb +++ b/lib/locomotive/liquid/db_file_system.rb @@ -1,18 +1,18 @@ -module Locomotive - module Liquid - class DbFileSystem - - # Works only with snippets +module Locomotive + module Liquid + class DbFileSystem + + # Works only with snippets def read_template_file(site, template_path) raise FileSystemError, "Illegal snippet name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/ - + snippet = site.snippets.where(:slug => template_path).first - + raise FileSystemError, "No such snippet '#{template_path}'" if snippet.nil? - + snippet.template - end - - end - end -end \ No newline at end of file + end + + end + end +end diff --git a/lib/locomotive/liquid/drops/asset_collections.rb b/lib/locomotive/liquid/drops/asset_collections.rb index 3d4c6d54..27072b79 100644 --- a/lib/locomotive/liquid/drops/asset_collections.rb +++ b/lib/locomotive/liquid/drops/asset_collections.rb @@ -1,19 +1,19 @@ -module Locomotive - module Liquid +module Locomotive + module Liquid module Drops - - class AssetCollections < ::Liquid::Drop - + + class AssetCollections < ::Liquid::Drop + def initialize(site) @site = site end - + def before_method(meth) @site.asset_collections.where(:slug => meth.to_s) end - + end - + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/base.rb b/lib/locomotive/liquid/drops/base.rb index b1cc82e7..731a75a5 100644 --- a/lib/locomotive/liquid/drops/base.rb +++ b/lib/locomotive/liquid/drops/base.rb @@ -1,27 +1,27 @@ # Code taken from Mephisto sources (http://mephistoblog.com/) module Locomotive - module Liquid - module Drops + module Liquid + module Drops class Base < ::Liquid::Drop - + @@forbidden_attributes = %w{_id _version _index} - + class_inheritable_reader :liquid_attributes write_inheritable_attribute :liquid_attributes, [] attr_reader :source delegate :hash, :to => :source - + def initialize(source) unless source.nil? @source = source @liquid = liquid_attributes.flatten.inject({}) { |h, k| h.update k.to_s => @source.send(k) } end end - + def id (@source.respond_to?(:id) ? @source.id : nil) || 'new' end - + def before_method(method) @liquid[method.to_s] end @@ -29,7 +29,7 @@ module Locomotive # converts an array of records to an array of liquid drops def self.liquify(*records, &block) i = -1 - records = + records = records.inject [] do |all, r| i+=1 attrs = (block && block.arity == 1) ? [r] : [r, i] @@ -41,12 +41,12 @@ module Locomotive end protected - + def liquify(*records, &block) self.class.liquify(*records, &block) end - - end + + end end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/content.rb b/lib/locomotive/liquid/drops/content.rb index 7c958fde..19715b41 100644 --- a/lib/locomotive/liquid/drops/content.rb +++ b/lib/locomotive/liquid/drops/content.rb @@ -1,21 +1,21 @@ -module Locomotive - module Liquid - module Drops +module Locomotive + module Liquid + module Drops class Content < Base - + def before_method(meth) return '' if @source.nil? - + if not @@forbidden_attributes.include?(meth.to_s) value = @source.send(meth) end end - + def highlighted_field_value @source.highlighted_field_value end - - end + + end end - end -end \ No newline at end of file + end +end diff --git a/lib/locomotive/liquid/drops/contents.rb b/lib/locomotive/liquid/drops/contents.rb index 01abdfe0..cbf21034 100644 --- a/lib/locomotive/liquid/drops/contents.rb +++ b/lib/locomotive/liquid/drops/contents.rb @@ -2,39 +2,39 @@ module Locomotive module Liquid module Drops class Contents < ::Liquid::Drop - + def initialize(site) @site = site end - + def before_method(meth) type = @site.content_types.where(:slug => meth.to_s).first ProxyCollection.new(@site, type) end - + end - + class ProxyCollection < ::Liquid::Drop - + def initialize(site, content_type) @site = site @content_type = content_type @collection = nil end - + def first content = @content_type.ordered_contents(@context['with_scope']).first end - + def last content = @content_type.ordered_contents(@context['with_scope']).last end - + def each(&block) @collection ||= @content_type.ordered_contents(@context['with_scope']) @collection.each(&block) end - + def paginate(options = {}) @collection ||= @content_type.ordered_contents(@context['with_scope']).paginate(options) { @@ -47,11 +47,11 @@ module Locomotive :per_page => @collection.per_page } end - + def api { 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) } end - + def before_method(meth) klass = @content_type.contents.klass # delegate to the proxy class if (meth.to_s =~ /^group_by_.+$/) == 0 @@ -61,6 +61,6 @@ module Locomotive end end end - end + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/javascripts.rb b/lib/locomotive/liquid/drops/javascripts.rb index 958c5705..a3ecbfb7 100644 --- a/lib/locomotive/liquid/drops/javascripts.rb +++ b/lib/locomotive/liquid/drops/javascripts.rb @@ -1,18 +1,18 @@ -module Locomotive - module Liquid - module Drops +module Locomotive + module Liquid + module Drops class Javascripts < ::Liquid::Drop - + def initialize(site) @site = site end - + def before_method(meth) asset = @site.theme_assets.where(:content_type => 'javascript', :slug => meth.to_s).first !asset.nil? ? asset.source.url : nil end - + end end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/page.rb b/lib/locomotive/liquid/drops/page.rb index 24fada14..f184bdc4 100644 --- a/lib/locomotive/liquid/drops/page.rb +++ b/lib/locomotive/liquid/drops/page.rb @@ -22,4 +22,4 @@ module Locomotive end end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/site.rb b/lib/locomotive/liquid/drops/site.rb index 31c9588d..d1535652 100644 --- a/lib/locomotive/liquid/drops/site.rb +++ b/lib/locomotive/liquid/drops/site.rb @@ -12,4 +12,4 @@ module Locomotive end end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/stylesheets.rb b/lib/locomotive/liquid/drops/stylesheets.rb index 348fd327..f18de59c 100644 --- a/lib/locomotive/liquid/drops/stylesheets.rb +++ b/lib/locomotive/liquid/drops/stylesheets.rb @@ -1,19 +1,19 @@ -module Locomotive - module Liquid - module Drops - class Stylesheets < ::Liquid::Drop - +module Locomotive + module Liquid + module Drops + class Stylesheets < ::Liquid::Drop + def initialize(site) @site = site end - - def before_method(meth) + + def before_method(meth) asset = @site.theme_assets.where(:content_type => 'stylesheet', :slug => meth.to_s).first !asset.nil? ? asset.source.url : nil end - + end - - end + + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/drops/theme_images.rb b/lib/locomotive/liquid/drops/theme_images.rb index fe8ee2f9..738a1be3 100644 --- a/lib/locomotive/liquid/drops/theme_images.rb +++ b/lib/locomotive/liquid/drops/theme_images.rb @@ -16,4 +16,4 @@ module Locomotive end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/filters/date.rb b/lib/locomotive/liquid/filters/date.rb index 2916e3ca..f00b4ce5 100644 --- a/lib/locomotive/liquid/filters/date.rb +++ b/lib/locomotive/liquid/filters/date.rb @@ -1,19 +1,19 @@ -module Locomotive - module Liquid - module Filters +module Locomotive + module Liquid + module Filters module Date - + def localized_date(input, *args) format, locale = args[0], args[1] rescue 'en' - + date = input.is_a?(String) ? Time.parse(input) : input - + if format.to_s.empty? return input.to_s end - + date = input.is_a?(String) ? Time.parse(input) : input - + if date.respond_to?(:strftime) I18n.locale = locale I18n.l date, :format => format @@ -21,10 +21,10 @@ module Locomotive input end end - + end - - ::Liquid::Template.register_filter(Date) - end - end -end \ No newline at end of file + + ::Liquid::Template.register_filter(Date) + end + end +end diff --git a/lib/locomotive/liquid/filters/html.rb b/lib/locomotive/liquid/filters/html.rb index 6d352d95..881a4a35 100644 --- a/lib/locomotive/liquid/filters/html.rb +++ b/lib/locomotive/liquid/filters/html.rb @@ -1,8 +1,8 @@ module Locomotive - module Liquid - module Filters + module Liquid + module Filters module Html - + # Write the link to a stylesheet resource # input: url of the css file def stylesheet_tag(input) @@ -10,7 +10,7 @@ module Locomotive input = "#{input}.css" unless input.ends_with?('.css') %{} end - + # Write the link to javascript resource # input: url of the javascript file def javascript_tag(input) @@ -18,15 +18,15 @@ module Locomotive input = "#{input}.js" unless input.ends_with?('.js') %{} end - - + + # Write an image tag # input: url of the image OR asset drop def image_tag(input, *args) image_options = inline_options(args_to_options(args)) "" end - + # Embed a flash movie into a page # input: url of the flash movie OR asset drop # width: width (in pixel or in %) of the embedded movie @@ -46,15 +46,15 @@ module Locomotive # Render the navigation for a paginated collection def default_pagination(paginate, *args) return '' if paginate['parts'].empty? - + options = args_to_options(args) - + previous_link = (if paginate['previous'].blank? "#{I18n.t('pagination.previous')}" else "#{I18n.t('pagination.previous')}" end) - + links = "" paginate['parts'].each do |part| links << (if part['is_link'] @@ -65,22 +65,22 @@ module Locomotive "#{part['title']}" end) end - + next_link = (if paginate['next'].blank? "#{I18n.t('pagination.next')}" else "#{I18n.t('pagination.next')}" end) - + %{} end - + protected - + # Convert an array of properties ('key:value') into a hash # Ex: ['width:50', 'height:100'] => { :width => '50', :height => '100' } def args_to_options(*args) @@ -92,23 +92,23 @@ module Locomotive end options end - + # Write options (Hash) into a string according to the following pattern: # ="", =" '...some liquid tags' # page.template # Liquid::Template - # + # # module ClassMethods def liquify_template(source = :value) field :serialized_template, :type => Binary before_validation :store_template - + class_eval <<-EOV def liquify_template_source self.send(:#{source.to_s}) end EOV - + include InstanceMethods end end - + module InstanceMethods - + def template Marshal.load(read_attribute(:serialized_template).to_s) rescue nil end - + protected - + def store_template begin template = ::Liquid::Template.parse(self.liquify_template_source) @@ -50,8 +50,8 @@ module Locomotive self.errors.add :template, :liquid_syntax_error end end - - end - end - end -end \ No newline at end of file + + end + end + end +end diff --git a/lib/locomotive/liquid/tags/blueprint.rb b/lib/locomotive/liquid/tags/blueprint.rb index a8081363..fe652238 100644 --- a/lib/locomotive/liquid/tags/blueprint.rb +++ b/lib/locomotive/liquid/tags/blueprint.rb @@ -1,21 +1,21 @@ module Locomotive - module Liquid - module Tags + module Liquid + module Tags class Blueprint < ::Liquid::Tag - + def render(context) %{ - - + + } end - + end - - ::Liquid::Template.register_tag('blueprint_stylesheets', Blueprint) - end - end -end \ No newline at end of file + + ::Liquid::Template.register_tag('blueprint_stylesheets', Blueprint) + end + end +end diff --git a/lib/locomotive/liquid/tags/consume.rb b/lib/locomotive/liquid/tags/consume.rb index a5955b3a..1a20f792 100644 --- a/lib/locomotive/liquid/tags/consume.rb +++ b/lib/locomotive/liquid/tags/consume.rb @@ -1,4 +1,4 @@ -module Locomotive +module Locomotive module Liquid module Tags # Consume web services as easy as pie directly in liquid ! @@ -12,7 +12,7 @@ module Locomotive # {% endconsume %} # class Consume < ::Liquid::Block - + Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}+)/ def initialize(tag_name, markup, tokens) @@ -27,20 +27,20 @@ module Locomotive raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume from \"\" [username: value, password: value]") end - super + super end def render(context) context.stack do context.scopes.last[@target.to_s] = Locomotive::Httparty::Webservice.consume(@url, @options.symbolize_keys) - + render_all(@nodelist, context) end - end - + end + end - + ::Liquid::Template.register_tag('consume', Consume) end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/tags/jquery.rb b/lib/locomotive/liquid/tags/jquery.rb index d29e611f..6f6661a9 100644 --- a/lib/locomotive/liquid/tags/jquery.rb +++ b/lib/locomotive/liquid/tags/jquery.rb @@ -1,6 +1,6 @@ -module Liquid - module Locomotive - module Tags +module Liquid + module Locomotive + module Tags class Jquery < ::Liquid::Tag def render(context) @@ -10,8 +10,8 @@ module Liquid } end end - - ::Liquid::Template.register_tag('jQuery', Jquery) - end - end -end \ No newline at end of file + + ::Liquid::Template.register_tag('jQuery', Jquery) + end + end +end diff --git a/lib/locomotive/liquid/tags/nav.rb b/lib/locomotive/liquid/tags/nav.rb index 04df6c13..d4e76e87 100644 --- a/lib/locomotive/liquid/tags/nav.rb +++ b/lib/locomotive/liquid/tags/nav.rb @@ -1,6 +1,6 @@ module Locomotive - module Liquid - module Tags + module Liquid + module Tags # Display the children pages of the site or the current page. If not precised, nav is applied on the current page. # The html output is based on the ul/li tags. # @@ -9,9 +9,9 @@ module Locomotive # {% nav site %} => # class Nav < ::Liquid::Tag - + Syntax = /(#{::Liquid::Expression}+)?/ - + def initialize(tag_name, markup, tokens) if markup =~ Syntax @site_or_page = $1 || 'page' @@ -20,17 +20,17 @@ module Locomotive else raise ::Liquid::SyntaxError.new("Syntax Error in 'nav' - Valid syntax: nav ") end - + super end - + def render(context) @current_page = context.registers[:page] - + source = context.registers[@site_or_page.to_sym] - + # puts "#{@site_or_page.to_sym} / source = #{source.inspect}" - + if source.respond_to?(:name) # site ? source = source.pages.index.first # start from home page else @@ -42,24 +42,24 @@ module Locomotive output += %{} output end - + private - + def render_child_link(page) selected = @current_page._id == page._id ? ' on' : '' - + icon = @options[:icon] ? '' : '' label = %{#{icon if @options[:icon] != 'after' }#{page.title}#{icon if @options[:icon] == 'after' }} - + %{
  • #{label}
  • }.strip end - + ::Liquid::Template.register_tag('nav', Nav) end end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/tags/paginate.rb b/lib/locomotive/liquid/tags/paginate.rb index 546cdfc6..d4fff034 100644 --- a/lib/locomotive/liquid/tags/paginate.rb +++ b/lib/locomotive/liquid/tags/paginate.rb @@ -1,5 +1,5 @@ module Locomotive - + module Liquid module Tags @@ -14,11 +14,11 @@ module Locomotive # {% endfor %} # {% endpaginate %} # - + class Paginate < ::Liquid::Block - + Syntax = /(#{::Liquid::Expression}+)\s+by\s+([0-9]+)/ - + def initialize(tag_name, markup, tokens) if markup =~ Syntax @collection_name = $1 @@ -26,24 +26,24 @@ module Locomotive else raise ::Liquid::SyntaxError.new("Syntax Error in 'paginate' - Valid syntax: paginate by ") end - + super end - + def render(context) context.stack do collection = context[@collection_name] - + raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil? - + pagination = collection.paginate({ :page => context['current_page'], :per_page => @per_page }).stringify_keys! - + page_count, current_page = pagination['total_pages'], pagination['current_page'] - - path = context['page'].path rescue '/' - + + path = context['page'].path rescue '/' + pagination['previous'] = link(I18n.t('pagination.previous'), current_page - 1, path) if pagination['previous_page'] pagination['next'] = link(I18n.t('pagination.next'), current_page + 1, path) if pagination['next_page'] pagination['parts'] = [] @@ -69,20 +69,20 @@ module Locomotive hellip_break = false end - end - + end + context['paginate'] = pagination - + render_all(@nodelist, context) end end - - private - + + private + def window_size 3 end - + def no_link(title) { 'title' => title, 'is_link' => false, 'hellip_break' => title == '…' } end @@ -94,7 +94,7 @@ module Locomotive ::Liquid::Template.register_tag('paginate', Paginate) end - + end - -end \ No newline at end of file + +end diff --git a/lib/locomotive/liquid/tags/snippet.rb b/lib/locomotive/liquid/tags/snippet.rb index 462cf082..afc85e16 100644 --- a/lib/locomotive/liquid/tags/snippet.rb +++ b/lib/locomotive/liquid/tags/snippet.rb @@ -1,23 +1,23 @@ module Locomotive module Liquid module Tags - + class Snippet < ::Liquid::Include - + def render(context) site = context.registers[:site] - + partial = ::Liquid::Template.file_system.read_template_file(site, context[@template_name]) - + variable = context[@variable_name || @template_name[1..-2]] - + context.stack do @attributes.each do |key, value| context[key] = context[value] end - output = (if variable.is_a?(Array) - variable.collect do |variable| + output = (if variable.is_a?(Array) + variable.collect do |variable| context[@template_name[1..-2]] = variable partial.render(context) end @@ -25,13 +25,13 @@ module Locomotive context[@template_name[1..-2]] = variable partial.render(context) end) - + output end end end ::Liquid::Template.register_tag('include', Snippet) - end + end end -end \ No newline at end of file +end diff --git a/lib/locomotive/liquid/tags/with_scope.rb b/lib/locomotive/liquid/tags/with_scope.rb index af04b5a1..068e67fa 100644 --- a/lib/locomotive/liquid/tags/with_scope.rb +++ b/lib/locomotive/liquid/tags/with_scope.rb @@ -2,24 +2,24 @@ module Locomotive module Liquid module Tags class WithScope < ::Liquid::Block - + def initialize(tag_name, markup, tokens) @attributes = {} markup.scan(::Liquid::TagAttributes) do |key, value| @attributes[key] = value - end + end super end - + def render(context) context.stack do context['with_scope'] = decode(@attributes) render_all(@nodelist, context) end end - + private - + def decode(attributes) attributes.each_pair do |key, value| attributes[key] = (case value @@ -32,8 +32,8 @@ module Locomotive end end end - - ::Liquid::Template.register_tag('with_scope', WithScope) - end - end -end \ No newline at end of file + + ::Liquid::Template.register_tag('with_scope', WithScope) + end + end +end diff --git a/lib/locomotive/logger.rb b/lib/locomotive/logger.rb index 590ce104..3a01f63e 100644 --- a/lib/locomotive/logger.rb +++ b/lib/locomotive/logger.rb @@ -1,11 +1,11 @@ -module Locomotive +module Locomotive module Logger - + def self.method_missing(meth, args, &block) if Locomotive.config.enable_logs == true Rails.logger.send(meth, args) end end - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/mongoid.rb b/lib/locomotive/mongoid.rb index 8aa7ea01..364c3d11 100644 --- a/lib/locomotive/mongoid.rb +++ b/lib/locomotive/mongoid.rb @@ -1,3 +1,3 @@ require 'locomotive/mongoid/document' require 'locomotive/mongoid/model_extensions' -require 'locomotive/mongoid/patches' \ No newline at end of file +require 'locomotive/mongoid/patches' diff --git a/lib/locomotive/mongoid/document.rb b/lib/locomotive/mongoid/document.rb index 814a9e4f..be877494 100644 --- a/lib/locomotive/mongoid/document.rb +++ b/lib/locomotive/mongoid/document.rb @@ -1,9 +1,9 @@ module Locomotive - + module Mongoid - + module Document - + extend ActiveSupport::Concern included do @@ -12,9 +12,9 @@ module Locomotive include ::Mongoid::CustomFields include Locomotive::Liquid::LiquifyTemplate end - + end - + end - -end \ No newline at end of file + +end diff --git a/lib/locomotive/mongoid/model_extensions.rb b/lib/locomotive/mongoid/model_extensions.rb index b23369c6..0510acd9 100644 --- a/lib/locomotive/mongoid/model_extensions.rb +++ b/lib/locomotive/mongoid/model_extensions.rb @@ -1 +1 @@ -Dir[File.join(File.dirname(__FILE__), '..', '..', '..', 'app', 'models', 'extensions', '**', '*.rb')].each { |lib| require lib } \ No newline at end of file +Dir[File.join(File.dirname(__FILE__), '..', '..', '..', 'app', 'models', 'extensions', '**', '*.rb')].each { |lib| require lib } diff --git a/lib/locomotive/mongoid/patches.rb b/lib/locomotive/mongoid/patches.rb index d89338a6..987386a7 100644 --- a/lib/locomotive/mongoid/patches.rb +++ b/lib/locomotive/mongoid/patches.rb @@ -2,16 +2,16 @@ require 'mongoid' ## various patches module Mongoid #:nodoc: - + module Document - + def update_child_with_noname(child, clear = false) name = child.association_name return if name.blank? # fix a weird bug with mongoid-acts-as-tree update_child_without_noname(child, clear) end - + alias_method_chain :update_child, :noname - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/regexps.rb b/lib/locomotive/regexps.rb index 80caff65..6ee60a01 100644 --- a/lib/locomotive/regexps.rb +++ b/lib/locomotive/regexps.rb @@ -1,13 +1,13 @@ module Locomotive module Regexps - + SUBDOMAIN = /^[a-z][a-z0-9]*[a-z0-9]{1}$/ - + DOMAIN = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix - + CONTENT_FOR = /\{\{\s*content_for_([a-zA-Z]{1}[a-zA-Z_0-9]*)(\s+.*)?\s*\}\}/ - + CONTENT_FOR_LAYOUT = /\{\{\s*content_for_layout\s*/ - + end -end \ No newline at end of file +end diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index 8162d515..54a65aa7 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -84,4 +84,4 @@ module Locomotive end end -end \ No newline at end of file +end diff --git a/lib/locomotive/routing/default_constraint.rb b/lib/locomotive/routing/default_constraint.rb index b2908258..2ad5aad8 100644 --- a/lib/locomotive/routing/default_constraint.rb +++ b/lib/locomotive/routing/default_constraint.rb @@ -1,39 +1,39 @@ module Locomotive module Routing class DefaultConstraint - + def self.matches?(request) domain, subdomain = domain_and_subdomain(request) subdomain = 'www' if subdomain.blank? - + domain == Locomotive.config.default_domain && Locomotive.config.reserved_subdomains.include?(subdomain) end - - # see actionpack/lib/action_dispatch/http/url.rb for more information + + # see actionpack/lib/action_dispatch/http/url.rb for more information def self.domain_and_subdomain(request) subdomain = extract_subdomain(request) [extract_domain(request), extract_subdomain(request)] end - + def self.extract_domain(request, tld_length = 1) return nil unless named_host?(request.host) request.host.split('.').last(1 + tld_length).join('.') end - + def self.extract_subdomain(request, tld_length = 1) subdomains(request, tld_length).join('.') end - + def self.named_host?(host) !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host)) end - + def self.subdomains(request, tld_length = 1) return [] unless named_host?(request.host) parts = request.host.split('.') parts[0..-(tld_length+2)] end - - end - end -end \ No newline at end of file + + end + end +end diff --git a/lib/locomotive/routing/site_dispatcher.rb b/lib/locomotive/routing/site_dispatcher.rb index c4338d7e..2ba48eb3 100644 --- a/lib/locomotive/routing/site_dispatcher.rb +++ b/lib/locomotive/routing/site_dispatcher.rb @@ -42,4 +42,4 @@ module Locomotive end end -end \ No newline at end of file +end diff --git a/lib/misc_form_builder.rb b/lib/misc_form_builder.rb index 523c7598..4a098abd 100644 --- a/lib/misc_form_builder.rb +++ b/lib/misc_form_builder.rb @@ -1,21 +1,21 @@ class MiscFormBuilder < Formtastic::SemanticFormBuilder - + @@all_fields_required_by_default = false - + def foldable_inputs(*args, &block) opts = args.extract_options! - + unfolded = !(opts[:class] || '').index('off').nil? || @object.new_record? || !@object.errors.empty? - + opts[:class] = (opts[:class] || '') + " inputs foldable #{'folded' unless unfolded}" args.push(opts) self.inputs(*args, &block) end - + def custom_input(name, options = {}, &block) default_options = { :css => '', :with_label => true, :label => nil } options = default_options.merge(options) - + html = options[:with_label] ? self.label(options[:label] || name) : '' html += template.capture(&block) || '' html += inline_hints_for(name, options) || '' @@ -23,7 +23,7 @@ class MiscFormBuilder < Formtastic::SemanticFormBuilder template.content_tag(:li, template.find_and_preserve(html), :class => "#{options[:css]} #{'error' unless @object.errors[name].empty?}") end - + def inline_errors_on(method, options = nil) if render_inline_errors? errors = @object.errors[method.to_sym] @@ -32,7 +32,7 @@ class MiscFormBuilder < Formtastic::SemanticFormBuilder nil end end - + def normalize_model_name(name) if name =~ /(.+)\/(.+)/ [$1, $2] @@ -40,6 +40,6 @@ class MiscFormBuilder < Formtastic::SemanticFormBuilder super end end - - + + end diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 522aafc8..99f7861d 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -1,6 +1,6 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake index 1571c1d7..b7f59671 100644 --- a/lib/tasks/rspec.rake +++ b/lib/tasks/rspec.rake @@ -1,7 +1,7 @@ begin require 'rspec/core' require 'rspec/core/rake_task' -rescue MissingSourceFile +rescue MissingSourceFile module Rspec module Core class RakeTask diff --git a/spec/lib/core_ext_spec.rb b/spec/lib/core_ext_spec.rb index cd3eec0f..bbbaf09c 100644 --- a/spec/lib/core_ext_spec.rb +++ b/spec/lib/core_ext_spec.rb @@ -1,37 +1,37 @@ require 'spec_helper' - + describe 'Core extensions' do - + describe 'Adding new methods for Hash items' do - + describe 'defining underscore_keys' do - + context 'from simple plain hash' do - + it 'underscores each key' do { 'foo-bar' => 42, :foo => 42, 'foo' => 42 }.underscore_keys.should == { 'foo_bar' => 42, :foo => 42, 'foo' => 42 } end - + end - + context 'from nested hashes' do it 'underscores each key' do { 'foo-bar' => { 'bar-foo' => 42, :test => { 'bar-foo' => 42 } } }.underscore_keys.should == { 'foo_bar' => { 'bar_foo' => 42, :test => { 'bar_foo' => 42 } } } end - + end context 'from hash with arrays of hashes' do - + it 'underscores each key' do { 'foo-bar' => [{ 'bar-foo' => 42 }, 42, { 'bar-foo' => 42 }] }.underscore_keys.should == { 'foo_bar' => [{ 'bar_foo' => 42 }, 42, { 'bar_foo' => 42 }] } end - + end - + end - + end - -end \ No newline at end of file + +end diff --git a/spec/lib/locomotive/heroku_spec.rb b/spec/lib/locomotive/heroku_spec.rb index 61c09661..e0c79ae8 100644 --- a/spec/lib/locomotive/heroku_spec.rb +++ b/spec/lib/locomotive/heroku_spec.rb @@ -1,106 +1,106 @@ require 'spec_helper' - + describe 'Heroku support' do - + before(:each) do ::Heroku::Client.any_instance.stubs(:post).returns(true) ::Heroku::Client.any_instance.stubs(:delete).returns(true) end - + context '#loaded' do - + it 'has method to enable heroku' do - Locomotive.respond_to?(:enable_heroku).should be_true + Locomotive.respond_to?(:enable_heroku).should be_true end - + it 'tells heroku is disabled' do Locomotive.heroku?.should be_false end - + it 'does not add instance methods to Site' do Site.instance_methods.include?(:add_heroku_domains).should be_false - Site.instance_methods.include?(:remove_heroku_domains).should be_false + Site.instance_methods.include?(:remove_heroku_domains).should be_false end - + end - + context '#disabled' do - + before(:each) do Locomotive.configure do |config| config.heroku = false end end - + it 'has a nil connection' do Locomotive.heroku_connection.should be_nil end - + it 'tells heroku is disabled' do Locomotive.heroku?.should be_false end - + it 'does not add methods to Site' do Site.instance_methods.include?(:add_heroku_domains).should be_false - Site.instance_methods.include?(:remove_heroku_domains).should be_false + Site.instance_methods.include?(:remove_heroku_domains).should be_false end - + end - + context '#enabled' do - + it 'tells heroku is disabled' do configure_locomotive_with_heroku Locomotive.heroku?.should be_true end - + it 'raises an exception if no app name is given' do lambda { configure_locomotive_with_heroku(:name => nil) - }.should raise_error + }.should raise_error end - + context 'dealing with heroku connection' do - + it 'opens a heroku connection with provided credentials' do configure_locomotive_with_heroku Locomotive.heroku_connection.user.should == 'john@doe.net' Locomotive.heroku_connection.password.should == 'easyone' end - + it 'opens a heroku connection with env credentials' do ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone' Locomotive.configure { |config| config.heroku = true } Locomotive.heroku_connection.user.should == 'john@doe.net' Locomotive.heroku_connection.password.should == 'easyone' end - + end - + context 'enhancing site' do - + before(:each) do configure_locomotive_with_heroku (@site = Factory.build(:site)).stubs(:valid?).returns(true) end - + it 'calls add_heroku_domains after saving a site' do @site.expects(:add_heroku_domains) - @site.save + @site.save end - - it 'calls remove_heroku_domains after saving a site' do + + it 'calls remove_heroku_domains after saving a site' do @site.expects(:remove_heroku_domains) @site.destroy end - + context 'adding domain' do - - it 'does not add new domain if no delta' do + + it 'does not add new domain if no delta' do Locomotive.heroku_connection.expects(:add_domain).never @site.save end - + it 'adds a new domain if new one' do @site.domains = ['www.acme.fr'] Locomotive.heroku_connection.expects(:add_domain).with('locomotive', 'www.acme.fr') @@ -108,21 +108,21 @@ describe 'Heroku support' do Locomotive.heroku_domains.should include('www.acme.fr') end end - + context 'removing domain' do - + it 'does not remove domain if no delta' do Locomotive.heroku_connection.expects(:remove_domain).never @site.destroy end - + it 'removes domains if we destroy a site' do @site.stubs(:domains_without_subdomain).returns(['www.acme.com']) Locomotive.heroku_connection.expects(:remove_domain).with('locomotive', 'www.acme.com') @site.destroy Locomotive.heroku_domains.should_not include('www.acme.com') end - + it 'removes domain if removed' do @site.domains = ['www.acme.fr']; @site.save @site.domains = ['www.acme.com'] @@ -130,20 +130,20 @@ describe 'Heroku support' do @site.save Locomotive.heroku_domains.should_not include('www.acme.fr') end - + end - + end - + end - + def configure_locomotive_with_heroku(options = {}, domains = nil) ::Heroku::Client.any_instance.stubs(:list_domains).with('locomotive').returns(domains || [ { :domain => "www.acme.com" }, { :domain => "example.com" }, { :domain => "www.example.com" } ]) Locomotive.configure do |config| config.heroku = { :name => 'locomotive', :login => 'john@doe.net', :password => 'easyone' }.merge(options) - end + end end - -end \ No newline at end of file + +end diff --git a/spec/lib/locomotive/httparty/patches_spec.rb b/spec/lib/locomotive/httparty/patches_spec.rb index b27ad1f4..4ad30d6c 100644 --- a/spec/lib/locomotive/httparty/patches_spec.rb +++ b/spec/lib/locomotive/httparty/patches_spec.rb @@ -5,15 +5,15 @@ describe 'Httparty patches' do describe 'Crack patch' do context '#parsing json' do - + it 'fixes an issue about json input beginning by a variable declaration' do lambda { Crack::JSON.parse('var json = { "foo": 42 };') }.should_not raise_error end - + end - + end - -end \ No newline at end of file + +end diff --git a/spec/lib/locomotive/httparty/webservice_spec.rb b/spec/lib/locomotive/httparty/webservice_spec.rb index 2052b459..35e84849 100644 --- a/spec/lib/locomotive/httparty/webservice_spec.rb +++ b/spec/lib/locomotive/httparty/webservice_spec.rb @@ -1,24 +1,24 @@ require 'spec_helper' describe Locomotive::Httparty::Webservice do - + context '#consuming' do - + it 'sets the base uri from a simple url' do Locomotive::Httparty::Webservice.expects(:get).with('/', { :base_uri => 'http://blog.locomotiveapp.org' }) Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org') end - + it 'sets both the base uri and the path from an url with parameters' do Locomotive::Httparty::Webservice.expects(:get).with('/api/read/json?num=3', { :base_uri => 'http://blog.locomotiveapp.org' }) Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org/api/read/json?num=3') end - + it 'sets auth credentials' do Locomotive::Httparty::Webservice.expects(:get).with('/', { :base_uri => 'http://blog.locomotiveapp.org', :basic_auth => { :username => 'john', :password => 'foo' } }) Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org', { :username => 'john', :password => 'foo' }) end - + end - -end \ No newline at end of file + +end diff --git a/spec/lib/locomotive/liquid/drops/contents_spec.rb b/spec/lib/locomotive/liquid/drops/contents_spec.rb index 56839e10..243c0a96 100644 --- a/spec/lib/locomotive/liquid/drops/contents_spec.rb +++ b/spec/lib/locomotive/liquid/drops/contents_spec.rb @@ -1,33 +1,33 @@ require 'spec_helper' - + describe Locomotive::Liquid::Drops::Contents do - + before(:each) do @site = Factory.build(:site) @content_type = Factory.build(:content_type, :site => @site, :slug => 'projects') end - + it 'retrieves a content type from a slug' do @site.content_types.expects(:where).with(:slug => 'projects') render_template '{{ contents.projects }}' end - + context '#group_by' do - + it 'orders contents' do @site.content_types.stubs(:where).returns([@content_type]) @content_type.contents.klass.expects(:group_by_category).with(:ordered_contents) render_template '{% for group in contents.projects.group_by_category %} {{ group.name }} {% endfor %}' end - + end - + def render_template(template = '', assigns = {}) assigns = { 'contents' => Locomotive::Liquid::Drops::Contents.new(@site) }.merge(assigns) - + Liquid::Template.parse(template).render assigns end - -end \ No newline at end of file + +end diff --git a/spec/lib/locomotive/liquid/drops/page_spec.rb b/spec/lib/locomotive/liquid/drops/page_spec.rb index 23fc6a43..94ff72ba 100644 --- a/spec/lib/locomotive/liquid/drops/page_spec.rb +++ b/spec/lib/locomotive/liquid/drops/page_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' - + describe Locomotive::Liquid::Drops::Page do - + before(:each) do @home = Factory.build(:page) @home.stubs(:children).returns([ - Page.new(:title => 'Child #1'), + Page.new(:title => 'Child #1'), Page.new(:title => 'Child #2'), Page.new(:title => 'Child #3') ]) @@ -14,35 +14,35 @@ describe Locomotive::Liquid::Drops::Page do Page.new(:title => 'Child #3.2') ]) end - + context '#rendering' do - + context '#children' do - + it 'renders title of all children pages' do content = render_template '{% for child in home.children %}{{ child.title }},{% endfor %}' content.should == 'Child #1,Child #2,Child #3,' end - + end - + context '#sub children' do - + it 'renders title of all sub children pages' do content = render_template '{% for child in home.children.last.children %}{{ child.title }},{% endfor %}' content.should == 'Child #3.1,Child #3.2,' end - + end - + end - + def render_template(template = '', assigns = {}) assigns = { 'home' => @home }.merge(assigns) - + Liquid::Template.parse(template).render assigns end - -end \ No newline at end of file + +end diff --git a/spec/lib/locomotive/liquid/filters/html_spec.rb b/spec/lib/locomotive/liquid/filters/html_spec.rb index a5d5df58..e4b5c2ad 100644 --- a/spec/lib/locomotive/liquid/filters/html_spec.rb +++ b/spec/lib/locomotive/liquid/filters/html_spec.rb @@ -1,31 +1,31 @@ require 'spec_helper' - + describe Locomotive::Liquid::Filters::Html do - + include Locomotive::Liquid::Filters::Html - + it 'should return a link tag for a stylesheet file' do result = "" stylesheet_tag('main.css').should == result stylesheet_tag('main').should == result stylesheet_tag(nil).should == '' end - + it 'should return a script tag for a javascript file' do result = %{} javascript_tag('main.js').should == result javascript_tag('main').should == result javascript_tag(nil).should == '' end - + it 'should return an image tag without paramaters' do image_tag('foo.jpg').should == "" end - + it 'should return an image tag with size' do image_tag('foo.jpg', 'width:100', 'height:50').should == "" end - + it 'should return a flash tag without parameters' do flash_tag('foo.flv').should == %{ @@ -35,7 +35,7 @@ describe Locomotive::Liquid::Filters::Html do }.strip end - + it 'should return a flash tag with size' do flash_tag('foo.flv', 'width:100', 'height:50').should == %{ @@ -45,10 +45,10 @@ describe Locomotive::Liquid::Filters::Html do }.strip end - + it 'should return a navigation block for the pagination' do - pagination = { - "previous" => nil, + pagination = { + "previous" => nil, "parts" => [ { 'title' => '1', 'is_link' => false }, { 'title' => '2', 'is_link' => true, 'url' => '/?page=2' }, @@ -60,23 +60,23 @@ describe Locomotive::Liquid::Filters::Html do html = default_pagination(pagination, 'css:flickr_pagination') html.should match(/