Cleaning whitespace on all .rb files so commit diffs from now on will be a bit more readable
This commit is contained in:
parent
baf5b87a7d
commit
a09329c030
8
Rakefile
8
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.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.homepage = %q{http://www.locomotiveapp.org}
|
||||||
gem.files = Dir[
|
gem.files = Dir[
|
||||||
"Gemfile",
|
"Gemfile",
|
||||||
"{app}/**/*",
|
"{app}/**/*",
|
||||||
"{config}/**/*",
|
"{config}/**/*",
|
||||||
"{lib}/**/*",
|
"{lib}/**/*",
|
||||||
"{public}/stylesheets/admin/**/*", "{public}/javascripts/admin/**/*", "{public}/images/admin/**/*",
|
"{public}/stylesheets/admin/**/*", "{public}/javascripts/admin/**/*", "{public}/images/admin/**/*",
|
||||||
"{vendor}/**/*"]
|
"{vendor}/**/*"]
|
||||||
# other fields that would normally go in your gemspec
|
# other fields that would normally go in your gemspec
|
||||||
# like authors, email and has_rdoc can also be included here
|
# like authors, email and has_rdoc can also be included here
|
||||||
@ -33,7 +33,7 @@ begin
|
|||||||
if dep.groups.include?(:default)
|
if dep.groups.include?(:default)
|
||||||
gem.add_dependency(dep.name, dep.requirement.to_s)
|
gem.add_dependency(dep.name, dep.requirement.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Jeweler::GemcutterTasks.new
|
Jeweler::GemcutterTasks.new
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class AccountsController < BaseController
|
class AccountsController < BaseController
|
||||||
|
|
||||||
sections 'settings'
|
sections 'settings'
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@account = Account.new(:email => params[:email])
|
@account = Account.new(:email => params[:email])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@account = Account.create(params[:account])
|
@account = Account.create(params[:account])
|
||||||
current_site.memberships.create(:account => @account) if @account.errors.empty?
|
current_site.memberships.create(:account => @account) if @account.errors.empty?
|
||||||
|
|
||||||
respond_with @account, :location => edit_admin_current_site_url
|
respond_with @account, :location => edit_admin_current_site_url
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class ApiContentsController < ActionController::Base
|
class ApiContentsController < ActionController::Base
|
||||||
|
|
||||||
include Locomotive::Routing::SiteDispatcher
|
include Locomotive::Routing::SiteDispatcher
|
||||||
|
|
||||||
before_filter :require_site
|
before_filter :require_site
|
||||||
|
|
||||||
before_filter :set_content_type
|
before_filter :set_content_type
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@content = @content_type.contents.build(params[:content])
|
@content = @content_type.contents.build(params[:content])
|
||||||
|
|
||||||
@ -18,13 +18,13 @@ module Admin
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_content_type
|
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
|
render :json => { :error => 'Api not enabled'} and return false unless @content_type.api_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class AssetCollectionsController < BaseController
|
class AssetCollectionsController < BaseController
|
||||||
|
|
||||||
sections 'assets'
|
sections 'assets'
|
||||||
|
|
||||||
before_filter :set_collections
|
before_filter :set_collections
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if not @asset_collections.empty?
|
if not @asset_collections.empty?
|
||||||
redirect_to(edit_admin_asset_collection_url(@asset_collections.first)) and return
|
redirect_to(edit_admin_asset_collection_url(@asset_collections.first)) and return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@asset_collection = current_site.asset_collections.find(params[:id])
|
@asset_collection = current_site.asset_collections.find(params[:id])
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_collections
|
def set_collections
|
||||||
@asset_collections = current_site.asset_collections.order_by([[:name, :asc]])
|
@asset_collections = current_site.asset_collections.order_by([[:name, :asc]])
|
||||||
end
|
end
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class AssetsController < BaseController
|
class AssetsController < BaseController
|
||||||
|
|
||||||
sections 'assets'
|
sections 'assets'
|
||||||
|
|
||||||
before_filter :set_collections_and_current_collection
|
before_filter :set_collections_and_current_collection
|
||||||
|
|
||||||
respond_to :json, :only => :update
|
respond_to :json, :only => :update
|
||||||
|
|
||||||
def create
|
def create
|
||||||
create! { edit_admin_asset_collection_url(@asset_collection) }
|
create! { edit_admin_asset_collection_url(@asset_collection) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
update! { edit_admin_asset_collection_url(@asset_collection) }
|
update! { edit_admin_asset_collection_url(@asset_collection) }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def begin_of_association_chain
|
def begin_of_association_chain
|
||||||
@asset_collection
|
@asset_collection
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_collections_and_current_collection
|
def set_collections_and_current_collection
|
||||||
@asset_collections = current_site.asset_collections
|
@asset_collections = current_site.asset_collections
|
||||||
@asset_collection = @asset_collections.find(params[:collection_id])
|
@asset_collection = @asset_collections.find(params[:collection_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class BaseController < InheritedResources::Base
|
class BaseController < InheritedResources::Base
|
||||||
|
|
||||||
include Locomotive::Routing::SiteDispatcher
|
include Locomotive::Routing::SiteDispatcher
|
||||||
|
|
||||||
layout 'admin/application'
|
layout 'admin/application'
|
||||||
|
|
||||||
before_filter :authenticate_admin!
|
before_filter :authenticate_admin!
|
||||||
|
|
||||||
before_filter :require_site
|
before_filter :require_site
|
||||||
|
|
||||||
before_filter :validate_site_membership
|
before_filter :validate_site_membership
|
||||||
|
|
||||||
before_filter :set_locale
|
before_filter :set_locale
|
||||||
|
|
||||||
helper_method :sections
|
helper_method :sections
|
||||||
|
|
||||||
# https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in
|
# 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|
|
Dir[File.dirname(__FILE__) + "/../../helpers/**/*_helper.rb"].each do |file|
|
||||||
helper "admin/#{File.basename(file, '.rb').gsub(/_helper$/, '')}"
|
helper "admin/#{File.basename(file, '.rb').gsub(/_helper$/, '')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
self.responder = Locomotive::AdminResponder # custom responder
|
self.responder = Locomotive::AdminResponder # custom responder
|
||||||
|
|
||||||
defaults :route_prefix => 'admin'
|
defaults :route_prefix => 'admin'
|
||||||
|
|
||||||
respond_to :html
|
respond_to :html
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def begin_of_association_chain
|
def begin_of_association_chain
|
||||||
current_site
|
current_site
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sections(main, sub = nil)
|
def self.sections(main, sub = nil)
|
||||||
before_filter do |c|
|
before_filter do |c|
|
||||||
sub = sub.call(c) if sub.respond_to?(:call)
|
sub = sub.call(c) if sub.respond_to?(:call)
|
||||||
@ -39,18 +39,18 @@ module Admin
|
|||||||
c.instance_variable_set(:@admin_sections, sections)
|
c.instance_variable_set(:@admin_sections, sections)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sections(key = nil)
|
def sections(key = nil)
|
||||||
if !key.nil? && key.to_sym == :sub
|
if !key.nil? && key.to_sym == :sub
|
||||||
@admin_sections[:sub] || self.controller_name.dasherize
|
@admin_sections[:sub] || self.controller_name.dasherize
|
||||||
else
|
else
|
||||||
@admin_sections[:main]
|
@admin_sections[:main]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_locale
|
def set_locale
|
||||||
I18n.locale = current_admin.locale
|
I18n.locale = current_admin.locale
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class ContentTypesController < BaseController
|
class ContentTypesController < BaseController
|
||||||
|
|
||||||
sections 'contents'
|
sections 'contents'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class ContentsController < BaseController
|
class ContentsController < BaseController
|
||||||
|
|
||||||
sections 'contents'
|
sections 'contents'
|
||||||
|
|
||||||
before_filter :set_content_type
|
before_filter :set_content_type
|
||||||
|
|
||||||
respond_to :json, :only => :update
|
respond_to :json, :only => :update
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@contents = @content_type.list_or_group_contents
|
@contents = @content_type.list_or_group_contents
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
create! do |success, failure|
|
create! do |success, failure|
|
||||||
success.html { redirect_to edit_admin_content_url(@content_type.slug, @content) }
|
success.html { redirect_to edit_admin_content_url(@content_type.slug, @content) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
update! { edit_admin_content_url(@content_type.slug, @content) }
|
update! { edit_admin_content_url(@content_type.slug, @content) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort
|
def sort
|
||||||
@content_type.sort_contents!(params[:order])
|
@content_type.sort_contents!(params[:order])
|
||||||
|
|
||||||
respond_with(@content_type, :location => admin_contents_url(@content_type.slug))
|
respond_with(@content_type, :location => admin_contents_url(@content_type.slug))
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
destroy! { admin_contents_url(@content_type.slug) }
|
destroy! { admin_contents_url(@content_type.slug) }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_content_type
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def begin_of_association_chain
|
def begin_of_association_chain
|
||||||
set_content_type
|
set_content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class CurrentSitesController < BaseController
|
class CurrentSitesController < BaseController
|
||||||
|
|
||||||
sections 'settings', 'site'
|
sections 'settings', 'site'
|
||||||
|
|
||||||
actions :edit, :update
|
actions :edit, :update
|
||||||
|
|
||||||
respond_to :json, :only => :update
|
respond_to :json, :only => :update
|
||||||
|
|
||||||
def update
|
def update
|
||||||
update! do |success, failure|
|
update! do |success, failure|
|
||||||
success.html { redirect_to edit_admin_current_site_url(new_host_if_subdomain_changed) }
|
success.html { redirect_to edit_admin_current_site_url(new_host_if_subdomain_changed) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def resource
|
def resource
|
||||||
@site = current_site
|
@site = current_site
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_host_if_subdomain_changed
|
def new_host_if_subdomain_changed
|
||||||
if @site.domains.include?(request.host)
|
if @site.domains.include?(request.host)
|
||||||
{}
|
{}
|
||||||
@ -26,6 +26,6 @@ module Admin
|
|||||||
{ :host => "#{@site.subdomain}.#{Locomotive.config.default_domain}:#{request.port}" }
|
{ :host => "#{@site.subdomain}.#{Locomotive.config.default_domain}:#{request.port}" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class CustomFieldsController < BaseController
|
class CustomFieldsController < BaseController
|
||||||
|
|
||||||
layout false
|
layout false
|
||||||
|
|
||||||
before_filter :set_parent_and_fields
|
before_filter :set_parent_and_fields
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@field = @fields.find(params[:id])
|
@field = @fields.find(params[:id])
|
||||||
render :action => "edit_#{@field.kind.downcase}"
|
render :action => "edit_#{@field.kind.downcase}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@field = @fields.find(params[:id])
|
@field = @fields.find(params[:id])
|
||||||
@field.updated_at = Time.now # forces mongoid to save the object
|
@field.updated_at = Time.now # forces mongoid to save the object
|
||||||
|
|
||||||
params[:custom_field][:category_items_attributes].delete('-1')
|
params[:custom_field][:category_items_attributes].delete('-1')
|
||||||
|
|
||||||
if @field.update_attributes(params[:custom_field])
|
if @field.update_attributes(params[:custom_field])
|
||||||
render :json => @field.attributes
|
render :json => @field.attributes
|
||||||
else
|
else
|
||||||
render :json => { :error => t('flash.admin.custom_fields.update.alert') }
|
render :json => { :error => t('flash.admin.custom_fields.update.alert') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_parent_and_fields
|
def set_parent_and_fields
|
||||||
if params[:parent] == 'asset_collection'
|
if params[:parent] == 'asset_collection'
|
||||||
@parent = current_site.asset_collections.where(:slug => params[:slug]).first
|
@parent = current_site.asset_collections.where(:slug => params[:slug]).first
|
||||||
@fields = @parent.asset_custom_fields
|
@fields = @parent.asset_custom_fields
|
||||||
else
|
else
|
||||||
@parent = current_site.content_types.where(:slug => params[:slug]).first
|
@parent = current_site.content_types.where(:slug => params[:slug]).first
|
||||||
@fields = @parent.content_custom_fields
|
@fields = @parent.content_custom_fields
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class LayoutsController < BaseController
|
class LayoutsController < BaseController
|
||||||
|
|
||||||
sections 'settings'
|
sections 'settings'
|
||||||
|
|
||||||
respond_to :json, :only => :update
|
respond_to :json, :only => :update
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@layouts = current_site.layouts.order_by([[:name, :asc]])
|
@layouts = current_site.layouts.order_by([[:name, :asc]])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class MembershipsController < BaseController
|
class MembershipsController < BaseController
|
||||||
|
|
||||||
sections 'settings'
|
sections 'settings'
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@membership = current_site.memberships.build(params[:membership])
|
@membership = current_site.memberships.build(params[:membership])
|
||||||
|
|
||||||
@ -21,6 +21,6 @@ module Admin
|
|||||||
def destroy
|
def destroy
|
||||||
destroy! { edit_admin_current_site_url }
|
destroy! { edit_admin_current_site_url }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class MyAccountsController < BaseController
|
class MyAccountsController < BaseController
|
||||||
|
|
||||||
sections 'settings', 'account'
|
sections 'settings', 'account'
|
||||||
|
|
||||||
actions :edit, :update
|
actions :edit, :update
|
||||||
|
|
||||||
respond_to :json, :only => :update
|
respond_to :json, :only => :update
|
||||||
|
|
||||||
def update
|
def update
|
||||||
update! { edit_admin_my_account_url }
|
update! { edit_admin_my_account_url }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def resource
|
def resource
|
||||||
@account = current_admin
|
@account = current_admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def begin_of_association_chain; nil; end # not related directly to current_site
|
def begin_of_association_chain; nil; end # not related directly to current_site
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,4 +12,4 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,4 +28,4 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class PasswordsController < Devise::PasswordsController
|
class PasswordsController < Devise::PasswordsController
|
||||||
|
|
||||||
include Locomotive::Routing::SiteDispatcher
|
include Locomotive::Routing::SiteDispatcher
|
||||||
|
|
||||||
layout 'admin/login'
|
layout 'admin/login'
|
||||||
|
|
||||||
before_filter :require_site
|
before_filter :require_site
|
||||||
|
|
||||||
helper 'admin/base', 'admin/login'
|
helper 'admin/base', 'admin/login'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class RenderingController < ActionController::Base
|
class RenderingController < ActionController::Base
|
||||||
|
|
||||||
include Locomotive::Routing::SiteDispatcher
|
include Locomotive::Routing::SiteDispatcher
|
||||||
|
|
||||||
include Locomotive::Render
|
include Locomotive::Render
|
||||||
|
|
||||||
before_filter :require_site
|
before_filter :require_site
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render_locomotive_page
|
render_locomotive_page
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class SessionsController < Devise::SessionsController
|
class SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
include Locomotive::Routing::SiteDispatcher
|
include Locomotive::Routing::SiteDispatcher
|
||||||
|
|
||||||
layout 'admin/login'
|
layout 'admin/login'
|
||||||
|
|
||||||
before_filter :require_site
|
before_filter :require_site
|
||||||
|
|
||||||
helper 'admin/base', 'admin/login'
|
helper 'admin/base', 'admin/login'
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
def after_sign_in_path_for(resource)
|
||||||
admin_pages_url
|
admin_pages_url
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class SitemapsController < ActionController::Base
|
class SitemapsController < ActionController::Base
|
||||||
|
|
||||||
include Locomotive::Routing::SiteDispatcher
|
include Locomotive::Routing::SiteDispatcher
|
||||||
|
|
||||||
before_filter :require_site
|
before_filter :require_site
|
||||||
|
|
||||||
respond_to :xml
|
respond_to :xml
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@pages = current_site.pages.published
|
@pages = current_site.pages.published
|
||||||
@host = request.host
|
@host = request.host
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class SitesController < BaseController
|
class SitesController < BaseController
|
||||||
|
|
||||||
sections 'settings'
|
sections 'settings'
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@site = Site.new(params[:site])
|
@site = Site.new(params[:site])
|
||||||
@site.memberships.build :account => @current_admin, :admin => true
|
@site.memberships.build :account => @current_admin, :admin => true
|
||||||
|
|
||||||
create! { edit_admin_my_account_url }
|
create! { edit_admin_my_account_url }
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@site = current_admin.sites.detect { |s| s._id == params[:id] }
|
@site = current_admin.sites.detect { |s| s._id == params[:id] }
|
||||||
|
|
||||||
@ -18,13 +18,13 @@ module Admin
|
|||||||
else
|
else
|
||||||
@site.errors.add(:base, 'Can not destroy the site you are logging in now')
|
@site.errors.add(:base, 'Can not destroy the site you are logging in now')
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with @site, :location => edit_admin_my_account_url
|
respond_with @site, :location => edit_admin_my_account_url
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def begin_of_association_chain; nil; end # not related directly to current_site
|
def begin_of_association_chain; nil; end # not related directly to current_site
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class SnippetsController < BaseController
|
class SnippetsController < BaseController
|
||||||
|
|
||||||
sections 'settings'
|
sections 'settings'
|
||||||
|
|
||||||
respond_to :json, :only => :update
|
respond_to :json, :only => :update
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@snippets = current_site.snippets.order_by([[:name, :asc]])
|
@snippets = current_site.snippets.order_by([[:name, :asc]])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,4 +40,4 @@ module Admin
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
|
|
||||||
def show; end
|
def show; end
|
||||||
|
|
||||||
def unknown; end
|
def unknown; end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Admin::AccountsHelper
|
module Admin::AccountsHelper
|
||||||
|
|
||||||
def admin_on?(site = current_site)
|
def admin_on?(site = current_site)
|
||||||
site.memberships.detect { |a| a.admin? && a.account == current_admin }
|
site.memberships.detect { |a| a.admin? && a.account == current_admin }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
module Admin::AssetsHelper
|
module Admin::AssetsHelper
|
||||||
|
|
||||||
def vignette_tag(asset)
|
def vignette_tag(asset)
|
||||||
image_tag(asset.vignette_url)
|
image_tag(asset.vignette_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_dimensions_and_size(asset)
|
def image_dimensions_and_size(asset)
|
||||||
content_tag(:small, "#{asset.width}px x #{asset.height}px | #{number_to_human_size(asset.size)}")
|
content_tag(:small, "#{asset.width}px x #{asset.height}px | #{number_to_human_size(asset.size)}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_plain_text_editing?(asset)
|
def allow_plain_text_editing?(asset)
|
||||||
asset.new_record? || asset.stylesheet? || asset.javascript?
|
asset.new_record? || asset.stylesheet? || asset.javascript?
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_picker_include_tags
|
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 = 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 += stylesheet_link_tag 'admin/plugins/fancybox', 'admin/box'
|
||||||
html
|
html
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Admin::BaseHelper
|
module Admin::BaseHelper
|
||||||
|
|
||||||
def title(title = nil)
|
def title(title = nil)
|
||||||
if title.nil?
|
if title.nil?
|
||||||
@content_for_title
|
@content_for_title
|
||||||
@ -8,25 +8,25 @@ module Admin::BaseHelper
|
|||||||
''
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_menu_item(name, url)
|
def admin_menu_item(name, url)
|
||||||
label = content_tag(:em) + escape_once(' ') + t("admin.shared.menu.#{name}")
|
label = content_tag(:em) + escape_once(' ') + t("admin.shared.menu.#{name}")
|
||||||
content_tag(:li, link_to(label, url), :class => name.dasherize)
|
content_tag(:li, link_to(label, url), :class => name.dasherize)
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_button_tag(text, url, options = {})
|
def admin_button_tag(text, url, options = {})
|
||||||
text = text.is_a?(Symbol) ? t(".#{text}") : text
|
text = text.is_a?(Symbol) ? t(".#{text}") : text
|
||||||
link_to(url, options) do
|
link_to(url, options) do
|
||||||
content_tag(:em, escape_once(' ')) + text
|
content_tag(:em, escape_once(' ')) + text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_submenu_item(name, url, options = {}, &block)
|
def admin_submenu_item(name, url, options = {}, &block)
|
||||||
default_options = { :i18n => true, :css => name.dasherize.downcase }
|
default_options = { :i18n => true, :css => name.dasherize.downcase }
|
||||||
default_options.merge!(options)
|
default_options.merge!(options)
|
||||||
|
|
||||||
css = "#{'on' if name == sections(:sub)} #{'links' if block_given?} #{options[:css]}"
|
css = "#{'on' if name == sections(:sub)} #{'links' if block_given?} #{options[:css]}"
|
||||||
|
|
||||||
label_link = default_options[:i18n] ? t("admin.shared.menu.#{name}") : name
|
label_link = default_options[:i18n] ? t("admin.shared.menu.#{name}") : name
|
||||||
if block_given?
|
if block_given?
|
||||||
popup = content_tag(:div, capture(&block), :class => 'popup', :style => 'display: none')
|
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)
|
content_tag(:li, link_to(content_tag(:span, label_link), url), :class => css)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def growl_message
|
def growl_message
|
||||||
if not flash.empty?
|
if not flash.empty?
|
||||||
%{
|
%{
|
||||||
@ -50,5 +50,5 @@ module Admin::BaseHelper
|
|||||||
def nocoffee_tag
|
def nocoffee_tag
|
||||||
link_to 'noCoffee', 'http://www.nocoffee.fr', :id => 'nocoffee'
|
link_to 'noCoffee', 'http://www.nocoffee.fr', :id => 'nocoffee'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
module Admin::CustomFieldsHelper
|
module Admin::CustomFieldsHelper
|
||||||
|
|
||||||
def options_for_field_kind(selected = nil)
|
def options_for_field_kind(selected = nil)
|
||||||
options = %w{String Text Category Boolean Date File}.map do |kind|
|
options = %w{String Text Category Boolean Date File}.map do |kind|
|
||||||
[t("admin.custom_fields.kind.#{kind.downcase}"), kind]
|
[t("admin.custom_fields.kind.#{kind.downcase}"), kind]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_order_by(content_type, collection_name)
|
def options_for_order_by(content_type, collection_name)
|
||||||
options = %w{updated_at _position_in_list}.map do |type|
|
options = %w{updated_at _position_in_list}.map do |type|
|
||||||
[t("admin.content_types.form.order_by.#{type.gsub(/^_/, '')}"), type]
|
[t("admin.content_types.form.order_by.#{type.gsub(/^_/, '')}"), type]
|
||||||
end
|
end
|
||||||
options + options_for_highlighted_field(content_type, collection_name)
|
options + options_for_highlighted_field(content_type, collection_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_highlighted_field(content_type, collection_name)
|
def options_for_highlighted_field(content_type, collection_name)
|
||||||
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
|
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
|
||||||
collection = content_type.send(custom_fields_collection_name)
|
collection = content_type.send(custom_fields_collection_name)
|
||||||
collection.delete_if { |f| f.label == 'field name' }
|
collection.delete_if { |f| f.label == 'field name' }
|
||||||
collection.map { |field| [field.label, field._name] }
|
collection.map { |field| [field.label, field._name] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_group_by_field(content_type, collection_name)
|
def options_for_group_by_field(content_type, collection_name)
|
||||||
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
|
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
|
||||||
collection = content_type.send(custom_fields_collection_name)
|
collection = content_type.send(custom_fields_collection_name)
|
||||||
collection.delete_if { |f| not f.category? }
|
collection.delete_if { |f| not f.category? }
|
||||||
collection.map { |field| [field.label, field._name] }
|
collection.map { |field| [field.label, field._name] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_text_formatting
|
def options_for_text_formatting
|
||||||
options = %w{none html}.map do |option|
|
options = %w{none html}.map do |option|
|
||||||
[t("admin.custom_fields.text_formatting.#{option}"), option]
|
[t("admin.custom_fields.text_formatting.#{option}"), option]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
module Admin::LoginHelper
|
module Admin::LoginHelper
|
||||||
|
|
||||||
def login_flash_message
|
def login_flash_message
|
||||||
if not flash.empty?
|
if not flash.empty?
|
||||||
content_tag :div, flash.values.first,
|
content_tag :div, flash.values.first,
|
||||||
:id => "flash-#{flash.keys.first}",
|
:id => "flash-#{flash.keys.first}",
|
||||||
:class => 'application-message'
|
:class => 'application-message'
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def login_button_tag(label)
|
def login_button_tag(label)
|
||||||
content_tag(:button, content_tag(:span, label), :type => 'submit', :class => 'button')
|
content_tag(:button, content_tag(:span, label), :type => 'submit', :class => 'button')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
module Admin::PagesHelper
|
module Admin::PagesHelper
|
||||||
|
|
||||||
def page_main_url(page, content = nil)
|
def page_main_url(page, content = nil)
|
||||||
url = ''
|
url = ''
|
||||||
|
|
||||||
if page.site.domains.empty?
|
if page.site.domains.empty?
|
||||||
url = main_site_url(page.site)
|
url = main_site_url(page.site)
|
||||||
else
|
else
|
||||||
url = "http://#{current_site.domains.first}"
|
url = "http://#{current_site.domains.first}"
|
||||||
url += ":#{request.port}" if request.port != 80
|
url += ":#{request.port}" if request.port != 80
|
||||||
end
|
end
|
||||||
|
|
||||||
if content.nil?
|
if content.nil?
|
||||||
File.join(url, page.fullpath)
|
File.join(url, page.fullpath)
|
||||||
else
|
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
|
end
|
||||||
|
|
||||||
def parent_pages_options
|
def parent_pages_options
|
||||||
roots = current_site.pages.roots.where(:slug.ne => '404').and(:_id.ne => @page.id)
|
roots = current_site.pages.roots.where(:slug.ne => '404').and(:_id.ne => @page.id)
|
||||||
|
|
||||||
returning [] do |list|
|
returning [] do |list|
|
||||||
roots.each do |page|
|
roots.each do |page|
|
||||||
list = add_children_to_options(page, list)
|
list = add_children_to_options(page, list)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_children_to_options(page, list)
|
def add_children_to_options(page, list)
|
||||||
return list if page.path.include?(@page.id) || page == @page
|
return list if page.path.include?(@page.id) || page == @page
|
||||||
|
|
||||||
offset = '- ' * (page.depth || 0) * 2
|
offset = '- ' * (page.depth || 0) * 2
|
||||||
|
|
||||||
list << ["#{offset}#{page.title}", page.id]
|
list << ["#{offset}#{page.title}", page.id]
|
||||||
page.children.each { |child| add_children_to_options(child, list) }
|
page.children.each { |child| add_children_to_options(child, list) }
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_page_cache_strategy
|
def options_for_page_cache_strategy
|
||||||
[
|
[
|
||||||
[t('.cache_strategy.none'), 'none'],
|
[t('.cache_strategy.none'), 'none'],
|
||||||
[t('.cache_strategy.simple'), 'simple'],
|
[t('.cache_strategy.simple'), 'simple'],
|
||||||
[t('.cache_strategy.hour'), 1.hour.to_s],
|
[t('.cache_strategy.hour'), 1.hour.to_s],
|
||||||
[t('.cache_strategy.day'), 1.day.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]
|
[t('.cache_strategy.month'), 1.month.to_s]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
module Admin::SitesHelper
|
module Admin::SitesHelper
|
||||||
|
|
||||||
def application_domain
|
def application_domain
|
||||||
domain = Locomotive.config.default_domain
|
domain = Locomotive.config.default_domain
|
||||||
domain += ":#{request.port}" if request.port != 80
|
domain += ":#{request.port}" if request.port != 80
|
||||||
domain
|
domain
|
||||||
end
|
end
|
||||||
|
|
||||||
def main_site_url(site = current_site, options = {})
|
def main_site_url(site = current_site, options = {})
|
||||||
url = "http://#{site.subdomain}.#{Locomotive.config.default_domain}"
|
url = "http://#{site.subdomain}.#{Locomotive.config.default_domain}"
|
||||||
url += ":#{request.port}" if request.port != 80
|
url += ":#{request.port}" if request.port != 80
|
||||||
url = File.join(url, controller.request.fullpath) if options.has_key?(:uri) && options[:uri]
|
url = File.join(url, controller.request.fullpath) if options.has_key?(:uri) && options[:uri]
|
||||||
url
|
url
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_on_domain(site, name)
|
def error_on_domain(site, name)
|
||||||
if (error = (site.errors[:domains] || []).detect { |n| n.include?(name) })
|
if (error = (site.errors[:domains] || []).detect { |n| n.include?(name) })
|
||||||
content_tag(:span, error, :class => 'inline-errors')
|
content_tag(:span, error, :class => 'inline-errors')
|
||||||
@ -20,5 +20,5 @@ module Admin::SitesHelper
|
|||||||
''
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,46 +1,46 @@
|
|||||||
class Account
|
class Account
|
||||||
|
|
||||||
include Locomotive::Mongoid::Document
|
include Locomotive::Mongoid::Document
|
||||||
|
|
||||||
# devise modules
|
# devise modules
|
||||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
|
||||||
|
|
||||||
# attr_accessible :email, :password, :password_confirmation # TODO
|
# attr_accessible :email, :password, :password_confirmation # TODO
|
||||||
|
|
||||||
## attributes ##
|
## attributes ##
|
||||||
field :name
|
field :name
|
||||||
field :locale, :default => 'en'
|
field :locale, :default => 'en'
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_destroy :remove_memberships!
|
before_destroy :remove_memberships!
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
def sites
|
def sites
|
||||||
Site.where({ 'memberships.account_id' => self._id })
|
Site.where({ 'memberships.account_id' => self._id })
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def password_required?
|
def password_required?
|
||||||
!persisted? || !password.blank? || !password_confirmation.blank?
|
!persisted? || !password.blank? || !password_confirmation.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_memberships!
|
def remove_memberships!
|
||||||
self.sites.each do |site|
|
self.sites.each do |site|
|
||||||
site.memberships.delete_if { |m| m.account_id == self._id }
|
site.memberships.delete_if { |m| m.account_id == self._id }
|
||||||
|
|
||||||
if site.admin_memberships.empty?
|
if site.admin_memberships.empty?
|
||||||
raise I18n.t('errors.messages.needs_admin_account')
|
raise I18n.t('errors.messages.needs_admin_account')
|
||||||
else
|
else
|
||||||
site.save
|
site.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
class Asset
|
class Asset
|
||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
## Extensions ##
|
## Extensions ##
|
||||||
include Models::Extensions::Asset::Vignette
|
include Models::Extensions::Asset::Vignette
|
||||||
include CustomFields::ProxyClassEnabler
|
include CustomFields::ProxyClassEnabler
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :name, :type => String
|
field :name, :type => String
|
||||||
field :content_type, :type => String
|
field :content_type, :type => String
|
||||||
@ -15,25 +15,25 @@ class Asset
|
|||||||
field :size, :type => Integer
|
field :size, :type => Integer
|
||||||
field :position, :type => Integer, :default => 0
|
field :position, :type => Integer, :default => 0
|
||||||
mount_uploader :source, AssetUploader
|
mount_uploader :source, AssetUploader
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
embedded_in :collection, :class_name => 'AssetCollection', :inverse_of => :assets
|
embedded_in :collection, :class_name => 'AssetCollection', :inverse_of => :assets
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :name, :source
|
validates_presence_of :name, :source
|
||||||
|
|
||||||
## behaviours ##
|
## behaviours ##
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
%w{image stylesheet javascript pdf video audio}.each do |type|
|
%w{image stylesheet javascript pdf video audio}.each do |type|
|
||||||
define_method("#{type}?") do
|
define_method("#{type}?") do
|
||||||
self.content_type == type
|
self.content_type == type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
{ :url => self.source.url }.merge(self.attributes)
|
{ :url => self.source.url }.merge(self.attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,60 +1,60 @@
|
|||||||
class AssetCollection
|
class AssetCollection
|
||||||
|
|
||||||
include Locomotive::Mongoid::Document
|
include Locomotive::Mongoid::Document
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :name
|
field :name
|
||||||
field :slug
|
field :slug
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
belongs_to_related :site
|
belongs_to_related :site
|
||||||
embeds_many :assets
|
embeds_many :assets
|
||||||
|
|
||||||
## behaviours ##
|
## behaviours ##
|
||||||
custom_fields_for :assets
|
custom_fields_for :assets
|
||||||
liquid_methods :name, :ordered_assets
|
liquid_methods :name, :ordered_assets
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_validation :normalize_slug
|
before_validation :normalize_slug
|
||||||
before_save :store_asset_positions!
|
before_save :store_asset_positions!
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :site, :name, :slug
|
validates_presence_of :site, :name, :slug
|
||||||
validates_uniqueness_of :slug, :scope => :site_id
|
validates_uniqueness_of :slug, :scope => :site_id
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
def ordered_assets
|
def ordered_assets
|
||||||
self.assets.sort { |a, b| (a.position || 0) <=> (b.position || 0) }
|
self.assets.sort { |a, b| (a.position || 0) <=> (b.position || 0) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def assets_order
|
def assets_order
|
||||||
self.ordered_assets.collect(&:id).join(',')
|
self.ordered_assets.collect(&:id).join(',')
|
||||||
end
|
end
|
||||||
|
|
||||||
def assets_order=(order)
|
def assets_order=(order)
|
||||||
@assets_order = order
|
@assets_order = order
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def normalize_slug
|
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?
|
self.slug.slugify! if self.slug.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def store_asset_positions!
|
def store_asset_positions!
|
||||||
return if @assets_order.nil?
|
return if @assets_order.nil?
|
||||||
|
|
||||||
@assets_order.split(',').each_with_index do |asset_id, index|
|
@assets_order.split(',').each_with_index do |asset_id, index|
|
||||||
self.assets.find(asset_id).position = index
|
self.assets.find(asset_id).position = index
|
||||||
end
|
end
|
||||||
|
|
||||||
self.assets.clone.each do |asset|
|
self.assets.clone.each do |asset|
|
||||||
if !@assets_order.split(',').include?(asset._id)
|
if !@assets_order.split(',').include?(asset._id)
|
||||||
self.assets.delete(asset)
|
self.assets.delete(asset)
|
||||||
asset.send(:delete)
|
asset.send(:delete)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,71 +2,71 @@ class ContentInstance
|
|||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
## extensions ##
|
## extensions ##
|
||||||
include CustomFields::ProxyClassEnabler
|
include CustomFields::ProxyClassEnabler
|
||||||
|
|
||||||
## fields (dynamic fields) ##
|
## fields (dynamic fields) ##
|
||||||
field :_slug
|
field :_slug
|
||||||
field :_position_in_list, :type => Integer, :default => 0
|
field :_position_in_list, :type => Integer, :default => 0
|
||||||
field :_visible, :type => Boolean, :default => true
|
field :_visible, :type => Boolean, :default => true
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validate :require_highlighted_field
|
validate :require_highlighted_field
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
embedded_in :content_type, :inverse_of => :contents
|
embedded_in :content_type, :inverse_of => :contents
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_save :set_slug
|
before_save :set_slug
|
||||||
before_save :set_visibility
|
before_save :set_visibility
|
||||||
before_create :add_to_list_bottom
|
before_create :add_to_list_bottom
|
||||||
|
|
||||||
## named scopes ##
|
## named scopes ##
|
||||||
named_scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_items_nb
|
named_scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_items_nb
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
alias :visible? :_visible?
|
alias :visible? :_visible?
|
||||||
|
|
||||||
def visible?
|
def visible?
|
||||||
self._visible || self._visible.nil?
|
self._visible || self._visible.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
Locomotive::Liquid::Drops::Content.new(self)
|
Locomotive::Liquid::Drops::Content.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_slug
|
def set_slug
|
||||||
_alias = self.highlighted_field_alias
|
_alias = self.highlighted_field_alias
|
||||||
self._slug = self.send(_alias).parameterize('_')
|
self._slug = self.send(_alias).parameterize('_')
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_visibility
|
def set_visibility
|
||||||
field = self.content_type.content_custom_fields.detect { |f| %w{visible active}.include?(f._alias) }
|
field = self.content_type.content_custom_fields.detect { |f| %w{visible active}.include?(f._alias) }
|
||||||
self._visible = self.send(field._name) rescue true
|
self._visible = self.send(field._name) rescue true
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_list_bottom
|
def add_to_list_bottom
|
||||||
Rails.logger.debug "add_to_list_bottom"
|
Rails.logger.debug "add_to_list_bottom"
|
||||||
self._position_in_list = self.content_type.contents.size
|
self._position_in_list = self.content_type.contents.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_highlighted_field
|
def require_highlighted_field
|
||||||
_alias = self.highlighted_field_alias
|
_alias = self.highlighted_field_alias
|
||||||
if self.send(_alias).blank?
|
if self.send(_alias).blank?
|
||||||
self.errors.add(_alias, :blank)
|
self.errors.add(_alias, :blank)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlighted_field_value
|
def highlighted_field_value
|
||||||
self.send(self.content_type.highlighted_field._name)
|
self.send(self.content_type.highlighted_field._name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlighted_field_alias
|
def highlighted_field_alias
|
||||||
self.content_type.highlighted_field._alias.to_sym
|
self.content_type.highlighted_field._alias.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class ContentType
|
class ContentType
|
||||||
|
|
||||||
include Locomotive::Mongoid::Document
|
include Locomotive::Mongoid::Document
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :name
|
field :name
|
||||||
field :description
|
field :description
|
||||||
@ -10,7 +10,7 @@ class ContentType
|
|||||||
field :highlighted_field_name
|
field :highlighted_field_name
|
||||||
field :group_by_field_name
|
field :group_by_field_name
|
||||||
field :api_enabled, :type => Boolean, :default => false
|
field :api_enabled, :type => Boolean, :default => false
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
belongs_to_related :site
|
belongs_to_related :site
|
||||||
embeds_many :contents, :class_name => 'ContentInstance' do
|
embeds_many :contents, :class_name => 'ContentInstance' do
|
||||||
@ -22,21 +22,21 @@ class ContentType
|
|||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_validation :normalize_slug
|
before_validation :normalize_slug
|
||||||
before_save :set_default_values
|
before_save :set_default_values
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :site, :name, :slug
|
validates_presence_of :site, :name, :slug
|
||||||
validates_uniqueness_of :slug, :scope => :site_id
|
validates_uniqueness_of :slug, :scope => :site_id
|
||||||
validates_size_of :content_custom_fields, :minimum => 1, :message => :array_too_short
|
validates_size_of :content_custom_fields, :minimum => 1, :message => :array_too_short
|
||||||
|
|
||||||
## behaviours ##
|
## behaviours ##
|
||||||
custom_fields_for :contents
|
custom_fields_for :contents
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
def groupable?
|
def groupable?
|
||||||
self.group_by_field && group_by_field.category?
|
self.group_by_field && group_by_field.category?
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_or_group_contents
|
def list_or_group_contents
|
||||||
if self.groupable?
|
if self.groupable?
|
||||||
groups = self.contents.klass.send(:"group_by_#{self.group_by_field._alias}", :ordered_contents)
|
groups = self.contents.klass.send(:"group_by_#{self.group_by_field._alias}", :ordered_contents)
|
||||||
@ -52,42 +52,42 @@ class ContentType
|
|||||||
self.ordered_contents
|
self.ordered_contents
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_contents(conditions = {})
|
def ordered_contents(conditions = {})
|
||||||
column = self.order_by.to_sym
|
column = self.order_by.to_sym
|
||||||
|
|
||||||
(if conditions.nil? || conditions.empty?
|
(if conditions.nil? || conditions.empty?
|
||||||
self.contents
|
self.contents
|
||||||
else
|
else
|
||||||
self.contents.where(conditions)
|
self.contents.where(conditions)
|
||||||
end).sort { |a, b| (a.send(column) || 0) <=> (b.send(column) || 0) }
|
end).sort { |a, b| (a.send(column) || 0) <=> (b.send(column) || 0) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_contents!(order)
|
def sort_contents!(order)
|
||||||
order.split(',').each_with_index do |id, position|
|
order.split(',').each_with_index do |id, position|
|
||||||
self.contents.find(id)._position_in_list = position
|
self.contents.find(id)._position_in_list = position
|
||||||
end
|
end
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlighted_field
|
def highlighted_field
|
||||||
self.content_custom_fields.detect { |f| f._name == self.highlighted_field_name }
|
self.content_custom_fields.detect { |f| f._name == self.highlighted_field_name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_by_field
|
def group_by_field
|
||||||
@group_by_field ||= self.content_custom_fields.detect { |f| f._name == self.group_by_field_name }
|
@group_by_field ||= self.content_custom_fields.detect { |f| f._name == self.group_by_field_name }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_default_values
|
def set_default_values
|
||||||
self.order_by ||= 'updated_at'
|
self.order_by ||= 'updated_at'
|
||||||
self.highlighted_field_name ||= self.content_custom_fields.first._name
|
self.highlighted_field_name ||= self.content_custom_fields.first._name
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_slug
|
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?
|
self.slug.slugify! if self.slug.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Models
|
module Models
|
||||||
module Extensions
|
module Extensions
|
||||||
module Asset
|
module Asset
|
||||||
module Vignette
|
module Vignette
|
||||||
|
|
||||||
def vignette_url
|
def vignette_url
|
||||||
if self.image?
|
if self.image?
|
||||||
if self.width < 80 && self.height < 80
|
if self.width < 80 && self.height < 80
|
||||||
@ -16,9 +16,9 @@ module Models
|
|||||||
mime_type_to_url(:medium)
|
mime_type_to_url(:medium)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def mime_type_to_url(size)
|
def mime_type_to_url(size)
|
||||||
mime_type = File.mime_type?(self.source_filename)
|
mime_type = File.mime_type?(self.source_filename)
|
||||||
filename = "unknown"
|
filename = "unknown"
|
||||||
@ -35,8 +35,8 @@ module Models
|
|||||||
|
|
||||||
File.join("admin", "icons", "filetype", size.to_s, filename + ".png")
|
File.join("admin", "icons", "filetype", size.to_s, filename + ".png")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
module Models
|
module Models
|
||||||
module Extensions
|
module Extensions
|
||||||
module Page
|
module Page
|
||||||
module Parts
|
module Parts
|
||||||
|
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
|
||||||
before_create { |p| p.parts << PagePart.build_body_part if p.parts.empty? }
|
before_create { |p| p.parts << PagePart.build_body_part if p.parts.empty? }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
def parts_attributes=(attributes)
|
def parts_attributes=(attributes)
|
||||||
self.update_parts(attributes.values.map { |attrs| PagePart.new(attrs) })
|
self.update_parts(attributes.values.map { |attrs| PagePart.new(attrs) })
|
||||||
end
|
end
|
||||||
|
|
||||||
def joined_parts
|
def joined_parts
|
||||||
self.parts.enabled.map(&:template).join('')
|
self.parts.enabled.map(&:template).join('')
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def update_parts(parts)
|
def update_parts(parts)
|
||||||
performed = []
|
performed = []
|
||||||
|
|
||||||
@ -46,9 +46,9 @@ module Models
|
|||||||
self.update_parts(new_parts)
|
self.update_parts(new_parts)
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Models
|
module Models
|
||||||
module Extensions
|
module Extensions
|
||||||
module Page
|
module Page
|
||||||
module Render
|
module Render
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
@ -12,8 +12,8 @@ module Models
|
|||||||
::Liquid::Template.parse("{{ content_for_layout }}").render(context)
|
::Liquid::Template.parse("{{ content_for_layout }}").render(context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
module Models
|
module Models
|
||||||
module Extensions
|
module Extensions
|
||||||
module Page
|
module Page
|
||||||
module Templatized
|
module Templatized
|
||||||
|
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
|
||||||
belongs_to_related :content_type
|
belongs_to_related :content_type
|
||||||
|
|
||||||
field :templatized, :type => Boolean, :default => false
|
field :templatized, :type => Boolean, :default => false
|
||||||
|
|
||||||
field :content_type_visible_column
|
field :content_type_visible_column
|
||||||
|
|
||||||
before_validation :set_slug_if_templatized
|
before_validation :set_slug_if_templatized
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
def set_slug_if_templatized
|
def set_slug_if_templatized
|
||||||
self.slug = 'content_type_template' if self.templatized?
|
self.slug = 'content_type_template' if self.templatized?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Models
|
module Models
|
||||||
module Extensions
|
module Extensions
|
||||||
module Page
|
module Page
|
||||||
module Tree
|
module Tree
|
||||||
|
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
include Mongoid::Acts::Tree
|
include Mongoid::Acts::Tree
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :position, :type => Integer
|
field :position, :type => Integer
|
||||||
|
|
||||||
## behaviours ##
|
## behaviours ##
|
||||||
acts_as_tree :order => ['position', 'asc']
|
acts_as_tree :order => ['position', 'asc']
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_validation :reset_parent
|
before_validation :reset_parent
|
||||||
before_save { |p| p.send(:write_attribute, :parent_id, nil) if p.parent_id.blank? }
|
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
|
# Fixme (Didier L.): Instances methods are defined before the include itself
|
||||||
alias :fix_position :hacked_fix_position
|
alias :fix_position :hacked_fix_position
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
def sort_children!(ids)
|
def sort_children!(ids)
|
||||||
ids.each_with_index do |id, position|
|
ids.each_with_index do |id, position|
|
||||||
child = self.children.detect { |p| p._id == id }
|
child = self.children.detect { |p| p._id == id }
|
||||||
@ -35,15 +35,15 @@ module Models
|
|||||||
child.save
|
child.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent=(owner) # missing in acts_as_tree
|
def parent=(owner) # missing in acts_as_tree
|
||||||
@_parent = owner
|
@_parent = owner
|
||||||
self.fix_position(false)
|
self.fix_position(false)
|
||||||
self.instance_variable_set :@_will_move, true
|
self.instance_variable_set :@_will_move, true
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def change_parent
|
def change_parent
|
||||||
if self.parent_id_changed?
|
if self.parent_id_changed?
|
||||||
self.fix_position(false)
|
self.fix_position(false)
|
||||||
@ -63,15 +63,15 @@ module Models
|
|||||||
self[depth_field] = parent[depth_field] + 1
|
self[depth_field] = parent[depth_field] + 1
|
||||||
self.save if perform_save
|
self.save if perform_save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_parent
|
def reset_parent
|
||||||
if self.parent_id_changed?
|
if self.parent_id_changed?
|
||||||
@_parent = nil
|
@_parent = nil
|
||||||
end
|
end
|
||||||
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
|
self.position = (::Page.where(:_id.ne => self._id).and(:parent_id => self.parent_id).max(:position) || 0) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -83,9 +83,9 @@ module Models
|
|||||||
p.save
|
p.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,46 +3,46 @@ class Layout < LiquidTemplate
|
|||||||
## associations ##
|
## associations ##
|
||||||
has_many_related :pages
|
has_many_related :pages
|
||||||
embeds_many :parts, :class_name => 'PagePart'
|
embeds_many :parts, :class_name => 'PagePart'
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_save :build_parts_from_value
|
before_save :build_parts_from_value
|
||||||
after_save :update_parts_in_pages
|
after_save :update_parts_in_pages
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_format_of :value, :with => Locomotive::Regexps::CONTENT_FOR_LAYOUT, :message => :missing_content_for_layout
|
validates_format_of :value, :with => Locomotive::Regexps::CONTENT_FOR_LAYOUT, :message => :missing_content_for_layout
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def build_parts_from_value
|
def build_parts_from_value
|
||||||
if self.value_changed? || self.new_record?
|
if self.value_changed? || self.new_record?
|
||||||
self.parts.each { |p| p.disabled = true }
|
self.parts.each { |p| p.disabled = true }
|
||||||
|
|
||||||
self.value.scan(Locomotive::Regexps::CONTENT_FOR).each do |attributes|
|
self.value.scan(Locomotive::Regexps::CONTENT_FOR).each do |attributes|
|
||||||
slug = attributes[0].strip.downcase
|
slug = attributes[0].strip.downcase
|
||||||
name = slug.humanize
|
name = slug.humanize
|
||||||
name = I18n.t('attributes.defaults.page_parts.name') if slug == 'layout'
|
name = I18n.t('attributes.defaults.page_parts.name') if slug == 'layout'
|
||||||
|
|
||||||
if part = self.parts.detect { |p| p.slug == slug }
|
if part = self.parts.detect { |p| p.slug == slug }
|
||||||
part.name = name if name.present?
|
part.name = name if name.present?
|
||||||
part.disabled = false
|
part.disabled = false
|
||||||
else
|
else
|
||||||
self.parts.build :slug => slug, :name => name || slug
|
self.parts.build :slug => slug, :name => name || slug
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# body always first
|
# body always first
|
||||||
body = self.parts.detect { |p| p.slug == 'layout' }
|
body = self.parts.detect { |p| p.slug == 'layout' }
|
||||||
self.parts.delete(body)
|
self.parts.delete(body)
|
||||||
self.parts.insert(0, body)
|
self.parts.insert(0, body)
|
||||||
|
|
||||||
@_update_pages = true if self.value_changed?
|
@_update_pages = true if self.value_changed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_parts_in_pages
|
def update_parts_in_pages
|
||||||
self.pages.each { |p| p.send(:update_parts!, self.parts) } if @_update_pages
|
self.pages.each { |p| p.send(:update_parts!, self.parts) } if @_update_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
class LiquidTemplate
|
class LiquidTemplate
|
||||||
|
|
||||||
include Locomotive::Mongoid::Document
|
include Locomotive::Mongoid::Document
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :name
|
field :name
|
||||||
field :slug
|
field :slug
|
||||||
field :value
|
field :value
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
belongs_to_related :site
|
belongs_to_related :site
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
before_validation :normalize_slug
|
before_validation :normalize_slug
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :site, :name, :slug, :value
|
validates_presence_of :site, :name, :slug, :value
|
||||||
validates_uniqueness_of :slug, :scope => :site_id
|
validates_uniqueness_of :slug, :scope => :site_id
|
||||||
|
|
||||||
## behaviours ##
|
## behaviours ##
|
||||||
liquify_template :value
|
liquify_template :value
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def normalize_slug
|
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!(:without_extension => true, :downcase => true) if self.slug.present?
|
self.slug.slugify!(:without_extension => true, :downcase => true) if self.slug.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
class Membership
|
class Membership
|
||||||
|
|
||||||
include Locomotive::Mongoid::Document
|
include Locomotive::Mongoid::Document
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :admin, :type => Boolean, :default => false
|
field :admin, :type => Boolean, :default => false
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
belongs_to_related :account
|
belongs_to_related :account
|
||||||
embedded_in :site, :inverse_of => :memberships
|
embedded_in :site, :inverse_of => :memberships
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :account
|
validates_presence_of :account
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
def email; @email; end
|
def email; @email; end
|
||||||
|
|
||||||
def email=(email)
|
def email=(email)
|
||||||
@email = email
|
@email = email
|
||||||
self.account = Account.where(:email => email).first
|
self.account = Account.where(:email => email).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def process!
|
def process!
|
||||||
if @email.blank?
|
if @email.blank?
|
||||||
self.errors.add_on_blank(:email)
|
self.errors.add_on_blank(:email)
|
||||||
@ -35,5 +35,5 @@ class Membership
|
|||||||
:save_it
|
:save_it
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -96,4 +96,4 @@ class Page
|
|||||||
self.slug.slugify!(:without_extension => true) if self.slug.present?
|
self.slug.slugify!(:without_extension => true) if self.slug.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class PagePart
|
class PagePart
|
||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
@ -8,28 +8,28 @@ class PagePart
|
|||||||
field :value
|
field :value
|
||||||
field :disabled, :type => Boolean, :default => false
|
field :disabled, :type => Boolean, :default => false
|
||||||
field :value
|
field :value
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
embedded_in :page, :inverse_of => :parts
|
embedded_in :page, :inverse_of => :parts
|
||||||
|
|
||||||
## validations ##
|
## validations ##
|
||||||
validates_presence_of :name, :slug
|
validates_presence_of :name, :slug
|
||||||
|
|
||||||
## named scopes ##
|
## named scopes ##
|
||||||
named_scope :enabled, where(:disabled => false)
|
named_scope :enabled, where(:disabled => false)
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
def template
|
def template
|
||||||
"{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}"
|
"{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build_body_part
|
def self.build_body_part
|
||||||
self.new({
|
self.new({
|
||||||
:name => I18n.t('attributes.defaults.page_parts.name'),
|
:name => I18n.t('attributes.defaults.page_parts.name'),
|
||||||
:value => I18n.t('attributes.defaults.pages.other.body'),
|
:value => I18n.t('attributes.defaults.pages.other.body'),
|
||||||
:slug => 'layout'
|
:slug => 'layout'
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -93,4 +93,4 @@ class Site
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
class Snippet < LiquidTemplate
|
class Snippet < LiquidTemplate
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -117,4 +117,4 @@ class ThemeAsset
|
|||||||
self.errors.add(:source, :extname_changed)
|
self.errors.add(:source, :extname_changed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,16 +7,16 @@ class AssetUploader < CarrierWave::Uploader::Base
|
|||||||
def store_dir
|
def store_dir
|
||||||
"sites/#{model.collection.site_id}/assets/#{model.id}"
|
"sites/#{model.collection.site_id}/assets/#{model.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_dir
|
def cache_dir
|
||||||
"#{Rails.root}/tmp/uploads"
|
"#{Rails.root}/tmp/uploads"
|
||||||
end
|
end
|
||||||
|
|
||||||
version :thumb do
|
version :thumb do
|
||||||
process :resize_to_fill => [50, 50]
|
process :resize_to_fill => [50, 50]
|
||||||
process :convert => 'png'
|
process :convert => 'png'
|
||||||
end
|
end
|
||||||
|
|
||||||
version :medium do
|
version :medium do
|
||||||
process :resize_to_fill => [80, 80]
|
process :resize_to_fill => [80, 80]
|
||||||
process :convert => 'png'
|
process :convert => 'png'
|
||||||
@ -24,18 +24,18 @@ class AssetUploader < CarrierWave::Uploader::Base
|
|||||||
|
|
||||||
version :preview do
|
version :preview do
|
||||||
process :resize_to_fit => [880, 1100]
|
process :resize_to_fit => [880, 1100]
|
||||||
process :convert => 'png'
|
process :convert => 'png'
|
||||||
end
|
end
|
||||||
|
|
||||||
process :set_content_type
|
process :set_content_type
|
||||||
process :set_size
|
process :set_size
|
||||||
process :set_width_and_height
|
process :set_width_and_height
|
||||||
|
|
||||||
def set_content_type
|
def set_content_type
|
||||||
value = :other
|
value = :other
|
||||||
|
|
||||||
content_type = file.content_type == 'application/octet-stream' ? File.mime_type?(original_filename) : file.content_type
|
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|
|
self.class.content_types.each_pair do |type, rules|
|
||||||
rules.each do |rule|
|
rules.each do |rule|
|
||||||
case rule
|
case rule
|
||||||
@ -44,20 +44,20 @@ class AssetUploader < CarrierWave::Uploader::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
model.content_type = value
|
model.content_type = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_size
|
def set_size
|
||||||
model.size = file.size
|
model.size = file.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_width_and_height
|
def set_width_and_height
|
||||||
if model.image?
|
if model.image?
|
||||||
model.width, model.height = `identify -format "%wx%h" #{file.path}`.split(/x/).collect(&:to_i)
|
model.width, model.height = `identify -format "%wx%h" #{file.path}`.split(/x/).collect(&:to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.content_types
|
def self.content_types
|
||||||
{
|
{
|
||||||
:image => ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'],
|
: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'],
|
:stylesheet => ['text/css'],
|
||||||
:javascript => ['text/javascript', 'text/js', 'application/x-javascript', 'application/javascript'],
|
:javascript => ['text/javascript', 'text/js', 'application/x-javascript', 'application/javascript'],
|
||||||
:font => ['application/x-font-ttf', 'application/vnd.ms-fontobject']
|
:font => ['application/x-font-ttf', 'application/vnd.ms-fontobject']
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
class ThemeAssetUploader < AssetUploader
|
class ThemeAssetUploader < AssetUploader
|
||||||
|
|
||||||
process :set_content_type
|
process :set_content_type
|
||||||
process :set_size
|
process :set_size
|
||||||
process :set_width_and_height
|
process :set_width_and_height
|
||||||
|
|
||||||
version :thumb do
|
version :thumb do
|
||||||
process :resize_to_fill => [50, 50]
|
process :resize_to_fill => [50, 50]
|
||||||
process :convert => 'png'
|
process :convert => 'png'
|
||||||
end
|
end
|
||||||
|
|
||||||
version :medium do
|
version :medium do
|
||||||
process :resize_to_fill => [80, 80]
|
process :resize_to_fill => [80, 80]
|
||||||
process :convert => 'png'
|
process :convert => 'png'
|
||||||
@ -18,15 +18,15 @@ class ThemeAssetUploader < AssetUploader
|
|||||||
|
|
||||||
version :preview do
|
version :preview do
|
||||||
process :resize_to_fit => [880, 1100]
|
process :resize_to_fit => [880, 1100]
|
||||||
process :convert => 'png'
|
process :convert => 'png'
|
||||||
end
|
end
|
||||||
|
|
||||||
def store_dir
|
def store_dir
|
||||||
"sites/#{model.site_id}/themes/#{model.id}"
|
"sites/#{model.site_id}/themes/#{model.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def extension_white_list
|
def extension_white_list
|
||||||
%w(jpg jpeg gif png css js swf flv)
|
%w(jpg jpeg gif png css js swf flv)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -40,7 +40,7 @@ module Locomotive
|
|||||||
# g.template_engine :erb
|
# g.template_engine :erb
|
||||||
# g.test_framework :test_unit, :fixture => true
|
# g.test_framework :test_unit, :fixture => true
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# Configure the default encoding used in templates for Ruby 1.9.
|
# Configure the default encoding used in templates for Ruby 1.9.
|
||||||
config.encoding = "utf-8"
|
config.encoding = "utf-8"
|
||||||
|
|
||||||
|
@ -31,4 +31,4 @@ end
|
|||||||
CarrierWave.configure do |config|
|
CarrierWave.configure do |config|
|
||||||
config.storage = :file
|
config.storage = :file
|
||||||
config.root = File.join(Rails.root, 'public')
|
config.root = File.join(Rails.root, 'public')
|
||||||
end
|
end
|
||||||
|
@ -30,4 +30,4 @@ Locomotive::Application.configure do
|
|||||||
|
|
||||||
# Enable threaded mode
|
# Enable threaded mode
|
||||||
# config.threadsafe!
|
# config.threadsafe!
|
||||||
end
|
end
|
||||||
|
@ -30,4 +30,4 @@ end
|
|||||||
|
|
||||||
CarrierWave.configure do |config|
|
CarrierWave.configure do |config|
|
||||||
config.storage = :file
|
config.storage = :file
|
||||||
end
|
end
|
||||||
|
@ -143,4 +143,4 @@ Devise.setup do |config|
|
|||||||
# end
|
# end
|
||||||
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Be sure to restart your server when you modify this file.
|
# 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):
|
# (all these examples are active by default):
|
||||||
# ActiveSupport::Inflector.inflections do |inflect|
|
# ActiveSupport::Inflector.inflections do |inflect|
|
||||||
# inflect.plural /^(ox)$/i, '\1en'
|
# inflect.plural /^(ox)$/i, '\1en'
|
||||||
|
@ -6,24 +6,24 @@ Locomotive.configure do |config|
|
|||||||
# Ex:
|
# Ex:
|
||||||
# config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com'
|
# config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com'
|
||||||
config.default_domain = '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
|
config.lastest_items_nb = 5
|
||||||
|
|
||||||
# tell if logs are enabled. Useful for debug purpose.
|
# tell if logs are enabled. Useful for debug purpose.
|
||||||
config.enable_logs = true
|
config.enable_logs = true
|
||||||
|
|
||||||
# tell if the application is hosted on Heroku.
|
# tell if the application is hosted on Heroku.
|
||||||
# Locomotive uses heroku api to add / remove domains.
|
# Locomotive uses heroku api to add / remove domains.
|
||||||
# there are 2 ways of passing heroku credentials to Locomotive
|
# there are 2 ways of passing heroku credentials to Locomotive
|
||||||
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
|
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
|
||||||
# - from this file
|
# - from this file
|
||||||
#
|
#
|
||||||
# Notes:
|
# Notes:
|
||||||
# - IMPORTANT: behaviours related to this option will only be applied in production
|
# - IMPORTANT: behaviours related to this option will only be applied in production
|
||||||
# - credentials coming from this file take precedence over ENV variables
|
# - credentials coming from this file take precedence over ENV variables
|
||||||
#
|
#
|
||||||
# Ex:
|
# Ex:
|
||||||
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
|
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
|
||||||
config.heroku = false
|
config.heroku = false
|
||||||
end
|
end
|
||||||
|
@ -5,4 +5,4 @@ if Rails.env.test?
|
|||||||
g.test_framework :rspec
|
g.test_framework :rspec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
# Your secret key for verifying the integrity of signed cookies.
|
# Your secret key for verifying the integrity of signed cookies.
|
||||||
# If you change this key, all old signed cookies will become invalid!
|
# 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.
|
# no regular words or you'll be exposed to dictionary attacks.
|
||||||
Rails.application.config.secret_token = 'aa84844b97e90edda8e005a686d82c3bef1f8e20a1255301f1d0886fc592a45ef2393d64b0c3d3ea858b1f6406ad6f15305666264716a79fcfa17de93ad0d69d'
|
Rails.application.config.secret_token = 'aa84844b97e90edda8e005a686d82c3bef1f8e20a1255301f1d0886fc592a45ef2393d64b0c3d3ea858b1f6406ad6f15305666264716a79fcfa17de93ad0d69d'
|
||||||
|
@ -6,4 +6,4 @@ site.save!
|
|||||||
|
|
||||||
puts "Your first website has been created !"
|
puts "Your first website has been created !"
|
||||||
puts "Admin url: http://test.example.com:3000/admin"
|
puts "Admin url: http://test.example.com:3000/admin"
|
||||||
puts "Crendetials: admin@example.com / locomotive"
|
puts "Crendetials: admin@example.com / locomotive"
|
||||||
|
@ -41,7 +41,7 @@ end
|
|||||||
## Common
|
## Common
|
||||||
|
|
||||||
def create_site_and_admin_account
|
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' })
|
@admin = Factory(:account, { :name => 'Admin', :email => 'admin@locomotiveapp.org' })
|
||||||
@site.memberships.build :account => @admin, :admin => true
|
@site.memberships.build :account => @admin, :admin => true
|
||||||
@site.save
|
@site.save
|
||||||
@ -56,5 +56,5 @@ def create_layout_samples
|
|||||||
<div id="main">\{\{ content_for_layout \}\}</div>
|
<div id="main">\{\{ content_for_layout \}\}</div>
|
||||||
</body>
|
</body>
|
||||||
</html>})
|
</html>})
|
||||||
Factory(:layout, :site => @site)
|
Factory(:layout, :site => @site)
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
# 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
|
# 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
|
# 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
|
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
||||||
# files.
|
# files.
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
||||||
current_path = URI.parse(current_url).path
|
current_path = URI.parse(current_url).path
|
||||||
if current_path.respond_to? :should
|
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
|
query = URI.parse(current_url).query
|
||||||
actual_params = query ? CGI.parse(query) : {}
|
actual_params = query ? CGI.parse(query) : {}
|
||||||
expected_params = {}
|
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
|
if actual_params.respond_to? :should
|
||||||
actual_params.should == expected_params
|
actual_params.should == expected_params
|
||||||
else
|
else
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
# 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
|
# 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
|
# 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
|
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
||||||
# files.
|
# files.
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links wi
|
|||||||
# steps to use the XPath syntax.
|
# steps to use the XPath syntax.
|
||||||
Capybara.default_selector = :css
|
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
|
# 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
|
# 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.
|
# 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'
|
config.default_domain = 'example.com'
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara.default_host = 'test.example.com'
|
Capybara.default_host = 'test.example.com'
|
||||||
|
@ -3,7 +3,7 @@ class String
|
|||||||
# def perma_string(sep = '_')
|
# def perma_string(sep = '_')
|
||||||
# ActiveSupport::Inflector.parameterize(self, sep).to_s
|
# ActiveSupport::Inflector.parameterize(self, sep).to_s
|
||||||
# end
|
# end
|
||||||
|
|
||||||
def slugify(options = {})
|
def slugify(options = {})
|
||||||
options = { :sep => '_', :without_extension => false, :downcase => false, :underscore => false }.merge(options)
|
options = { :sep => '_', :without_extension => false, :downcase => false, :underscore => false }.merge(options)
|
||||||
# replace accented chars with ther ascii equivalents
|
# replace accented chars with ther ascii equivalents
|
||||||
@ -24,21 +24,21 @@ class String
|
|||||||
s.gsub!(/[\-]/i, '_') if options[:underscore]
|
s.gsub!(/[\-]/i, '_') if options[:underscore]
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
def slugify!(options = {})
|
def slugify!(options = {})
|
||||||
replace(self.slugify(options))
|
replace(self.slugify(options))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## Hash
|
## Hash
|
||||||
|
|
||||||
class Hash
|
class Hash
|
||||||
|
|
||||||
def underscore_keys
|
def underscore_keys
|
||||||
new_hash = {}
|
new_hash = {}
|
||||||
|
|
||||||
self.each_pair do |key, value|
|
self.each_pair do |key, value|
|
||||||
if value.respond_to?(:collect!) # Array
|
if value.respond_to?(:collect!) # Array
|
||||||
value.collect do |item|
|
value.collect do |item|
|
||||||
if item.respond_to?(:each_pair) # Hash item within
|
if item.respond_to?(:each_pair) # Hash item within
|
||||||
@ -50,13 +50,13 @@ class Hash
|
|||||||
elsif value.respond_to?(:each_pair) # Hash
|
elsif value.respond_to?(:each_pair) # Hash
|
||||||
value = value.underscore_keys
|
value = value.underscore_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
new_key = key.is_a?(String) ? key.underscore : key # only String keys
|
new_key = key.is_a?(String) ? key.underscore : key # only String keys
|
||||||
|
|
||||||
new_hash[new_key] = value
|
new_hash[new_key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
self.replace(new_hash)
|
self.replace(new_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
class CopyAssetsGenerator < Rails::Generators::Base
|
class CopyAssetsGenerator < Rails::Generators::Base
|
||||||
|
|
||||||
def self.source_root
|
def self.source_root
|
||||||
@_locomotive_source_root ||= File.expand_path('../../../../../', __FILE__)
|
@_locomotive_source_root ||= File.expand_path('../../../../../', __FILE__)
|
||||||
@_locomotive_source_root
|
@_locomotive_source_root
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_public_files
|
def copy_public_files
|
||||||
directory 'public', 'public', :recursive => true
|
directory 'public', 'public', :recursive => true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Locomotive
|
|||||||
def copy_initializer
|
def copy_initializer
|
||||||
template 'locomotive.rb', 'config/initializers/locomotive.rb'
|
template 'locomotive.rb', 'config/initializers/locomotive.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
def seed_db
|
def seed_db
|
||||||
append_file 'db/seeds.rb', %{
|
append_file 'db/seeds.rb', %{
|
||||||
# Uncomment the following lines if you want to create the first website / account
|
# 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.memberships.build :account => account, :admin => true
|
||||||
#site.save!}
|
#site.save!}
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_readme
|
def show_readme
|
||||||
readme 'README'
|
readme 'README'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,24 +3,24 @@ Locomotive.configure do |config|
|
|||||||
# Ex:
|
# Ex:
|
||||||
# config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com'
|
# config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com'
|
||||||
config.default_domain = 'mydomain.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
|
config.lastest_items_nb = 5
|
||||||
|
|
||||||
# tell if logs are enabled. Useful for debug purpose.
|
# tell if logs are enabled. Useful for debug purpose.
|
||||||
config.enable_logs = true
|
config.enable_logs = true
|
||||||
|
|
||||||
# tell if the application is hosted on Heroku.
|
# tell if the application is hosted on Heroku.
|
||||||
# Locomotive uses heroku api to add / remove domains.
|
# Locomotive uses heroku api to add / remove domains.
|
||||||
# there are 2 ways of passing heroku credentials to Locomotive
|
# there are 2 ways of passing heroku credentials to Locomotive
|
||||||
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
|
# - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD
|
||||||
# - from this file
|
# - from this file
|
||||||
#
|
#
|
||||||
# Notes:
|
# Notes:
|
||||||
# - IMPORTANT: behaviours related to this option will only be applied in production
|
# - IMPORTANT: behaviours related to this option will only be applied in production
|
||||||
# - credentials coming from this file take precedence over ENV variables
|
# - credentials coming from this file take precedence over ENV variables
|
||||||
#
|
#
|
||||||
# Ex:
|
# Ex:
|
||||||
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
|
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
|
||||||
config.heroku = false
|
config.heroku = false
|
||||||
end
|
end
|
||||||
|
@ -13,43 +13,43 @@ require 'locomotive/admin_responder'
|
|||||||
require 'mongo_session_store/mongoid'
|
require 'mongo_session_store/mongoid'
|
||||||
|
|
||||||
module Locomotive
|
module Locomotive
|
||||||
|
|
||||||
include Locomotive::Heroku
|
include Locomotive::Heroku
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :config
|
attr_accessor :config
|
||||||
|
|
||||||
def config
|
def config
|
||||||
self.config = Configuration.new unless @config
|
self.config = Configuration.new unless @config
|
||||||
@config
|
@config
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.configure
|
def self.configure
|
||||||
self.config ||= Configuration.new
|
self.config ||= Configuration.new
|
||||||
yield(self.config)
|
yield(self.config)
|
||||||
|
|
||||||
after_configure
|
after_configure
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.after_configure
|
def self.after_configure
|
||||||
raise '[Error] Locomotive needs a default domain name' if Locomotive.config.default_domain.blank?
|
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' : '')
|
ActionMailer::Base.default_url_options[:host] = self.config.default_domain + (Rails.env.development? ? ':3000' : '')
|
||||||
|
|
||||||
# cookies stored in mongodb (mongoid_store)
|
# cookies stored in mongodb (mongoid_store)
|
||||||
Rails.application.config.session_store :mongoid_store, {
|
Rails.application.config.session_store :mongoid_store, {
|
||||||
:key => Locomotive.config.cookie_key
|
:key => Locomotive.config.cookie_key
|
||||||
}
|
}
|
||||||
|
|
||||||
# Heroku support
|
# Heroku support
|
||||||
self.enable_heroku if self.heroku?
|
self.enable_heroku if self.heroku?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.logger(message)
|
def self.logger(message)
|
||||||
if Locomotive.config.enable_logs == true
|
if Locomotive.config.enable_logs == true
|
||||||
Rails.logger.info(message)
|
Rails.logger.info(message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,9 +2,9 @@ require 'responders'
|
|||||||
|
|
||||||
module Locomotive
|
module Locomotive
|
||||||
class AdminResponder < ::ActionController::Responder
|
class AdminResponder < ::ActionController::Responder
|
||||||
|
|
||||||
include ::Responders::FlashResponder
|
include ::Responders::FlashResponder
|
||||||
|
|
||||||
def api_behavior(error)
|
def api_behavior(error)
|
||||||
raise error unless resourceful?
|
raise error unless resourceful?
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ module Locomotive
|
|||||||
else
|
else
|
||||||
display({ :notice => controller.flash[:notice] })
|
display({ :notice => controller.flash[:notice] })
|
||||||
end
|
end
|
||||||
|
|
||||||
controller.flash.discard # reset flash messages !
|
controller.flash.discard # reset flash messages !
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module CarrierWave
|
module CarrierWave
|
||||||
module Uploader
|
module Uploader
|
||||||
class Base
|
class Base
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
{
|
{
|
||||||
:url => self.url,
|
:url => self.url,
|
||||||
@ -9,7 +9,7 @@ module CarrierWave
|
|||||||
:size => self.size
|
:size => self.size
|
||||||
}.stringify_keys
|
}.stringify_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
require 'carrierwave'
|
require 'carrierwave'
|
||||||
|
|
||||||
module CarrierWave
|
module CarrierWave
|
||||||
|
|
||||||
class SanitizedFile
|
class SanitizedFile
|
||||||
|
|
||||||
def original_filename=(filename)
|
def original_filename=(filename)
|
||||||
@original_filename = filename
|
@original_filename = filename
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type=(content_type)
|
def content_type=(content_type)
|
||||||
@content_type = content_type
|
@content_type = content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
# http://github.com/jnicklas/carrierwave/issuesearch?state=closed&q=content+type#issue/48
|
# http://github.com/jnicklas/carrierwave/issuesearch?state=closed&q=content+type#issue/48
|
||||||
def copy_to_with_content_type(new_path, permissions=nil)
|
def copy_to_with_content_type(new_path, permissions=nil)
|
||||||
new_file = self.copy_to_without_content_type(new_path, permissions)
|
new_file = self.copy_to_without_content_type(new_path, permissions)
|
||||||
new_file.content_type = self.content_type
|
new_file.content_type = self.content_type
|
||||||
new_file
|
new_file
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method_chain :copy_to, :content_type
|
alias_method_chain :copy_to, :content_type
|
||||||
|
|
||||||
# FIXME (Did) CarrierWave speaks mime type now
|
# FIXME (Did) CarrierWave speaks mime type now
|
||||||
def content_type
|
def content_type
|
||||||
return @content_type if @content_type
|
return @content_type if @content_type
|
||||||
@ -30,9 +30,9 @@ module CarrierWave
|
|||||||
File.mime_type?(@file) if @file.is_a?(String)
|
File.mime_type?(@file) if @file.is_a?(String)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module CarrierWave
|
module CarrierWave
|
||||||
@ -44,7 +44,7 @@ module CarrierWave
|
|||||||
record.errors.add attr, options[:message] if record.send("#{attr}_integrity_error")
|
record.errors.add attr, options[:message] if record.send("#{attr}_integrity_error")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validates_processing_of(*attrs)
|
def validates_processing_of(*attrs)
|
||||||
options = attrs.last.is_a?(Hash) ? attrs.last : {}
|
options = attrs.last.is_a?(Hash) ? attrs.last : {}
|
||||||
options[:message] ||= I18n.t('carrierwave.errors.processing', :default => 'failed to be processed.')
|
options[:message] ||= I18n.t('carrierwave.errors.processing', :default => 'failed to be processed.')
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
class Configuration
|
class Configuration
|
||||||
|
|
||||||
@@defaults = {
|
@@defaults = {
|
||||||
@ -18,7 +18,7 @@ module Locomotive
|
|||||||
def initialize
|
def initialize
|
||||||
@@settings = self.class.get_from_hash(@@defaults)
|
@@settings = self.class.get_from_hash(@@defaults)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.settings
|
def self.settings
|
||||||
@@settings
|
@@settings
|
||||||
end
|
end
|
||||||
@ -43,7 +43,7 @@ module Locomotive
|
|||||||
|
|
||||||
# specialized hash for storing configuration settings
|
# specialized hash for storing configuration settings
|
||||||
class ConfigurationHash < Hash
|
class ConfigurationHash < Hash
|
||||||
# ensure that default entries always produce
|
# ensure that default entries always produce
|
||||||
# instances of the ConfigurationHash class
|
# instances of the ConfigurationHash class
|
||||||
def default(key=nil)
|
def default(key=nil)
|
||||||
include?(key) ? self[key] : self[key] = self.class.new
|
include?(key) ? self[key] : self[key] = self.class.new
|
||||||
@ -59,11 +59,11 @@ module Locomotive
|
|||||||
# i.e. params.id === params[:id]
|
# i.e. params.id === params[:id]
|
||||||
# note: all keys are converted to symbols
|
# note: all keys are converted to symbols
|
||||||
def method_missing(name, *args, &block)
|
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
|
send :[]=, name.to_s.chomp('=').to_sym, *args
|
||||||
else
|
else
|
||||||
send(:[], name.to_sym, &block)
|
send(:[], name.to_sym, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ module CustomFields
|
|||||||
module Types
|
module Types
|
||||||
module File
|
module File
|
||||||
class FileUploader < ::CarrierWave::Uploader::Base
|
class FileUploader < ::CarrierWave::Uploader::Base
|
||||||
|
|
||||||
def store_dir
|
def store_dir
|
||||||
"sites/#{model.content_type.site_id}/contents/#{model.id}/files"
|
"sites/#{model.content_type.site_id}/contents/#{model.id}/files"
|
||||||
end
|
end
|
||||||
@ -11,8 +11,8 @@ module CustomFields
|
|||||||
def cache_dir
|
def cache_dir
|
||||||
"#{Rails.root}/tmp/uploads"
|
"#{Rails.root}/tmp/uploads"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,4 +18,4 @@ module Locomotive
|
|||||||
class Engine < Rails::Engine
|
class Engine < Rails::Engine
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,58 +2,58 @@ require 'heroku'
|
|||||||
|
|
||||||
module Locomotive
|
module Locomotive
|
||||||
module Heroku
|
module Heroku
|
||||||
|
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :heroku_connection
|
attr_accessor :heroku_connection
|
||||||
attr_accessor :heroku_domains
|
attr_accessor :heroku_domains
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
||||||
def heroku?
|
def heroku?
|
||||||
!self.config.heroku.nil? && self.config.heroku.respond_to?(:[])
|
!self.config.heroku.nil? && self.config.heroku.respond_to?(:[])
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_heroku
|
def enable_heroku
|
||||||
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
||||||
|
|
||||||
self.open_heroku_connection
|
self.open_heroku_connection
|
||||||
self.enhance_site_model
|
self.enhance_site_model
|
||||||
|
|
||||||
# "cache" domains for better performance
|
# "cache" domains for better performance
|
||||||
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_heroku_connection
|
def open_heroku_connection
|
||||||
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
||||||
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
|
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
|
||||||
|
|
||||||
self.heroku_connection = ::Heroku::Client.new(login, password)
|
self.heroku_connection = ::Heroku::Client.new(login, password)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enhance_site_model
|
def enhance_site_model
|
||||||
Site.send :include, Locomotive::Heroku::CustomDomain
|
Site.send :include, Locomotive::Heroku::CustomDomain
|
||||||
end
|
end
|
||||||
|
|
||||||
# manage domains
|
# manage domains
|
||||||
|
|
||||||
def add_heroku_domain(name)
|
def add_heroku_domain(name)
|
||||||
Locomotive.logger "[add heroku domain] #{name}"
|
Locomotive.logger "[add heroku domain] #{name}"
|
||||||
self.heroku_connection.add_domain(self.config.heroku[:name], name)
|
self.heroku_connection.add_domain(self.config.heroku[:name], name)
|
||||||
self.heroku_domains << name
|
self.heroku_domains << name
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_heroku_domain(name)
|
def remove_heroku_domain(name)
|
||||||
Locomotive.logger "[remove heroku domain] #{name}"
|
Locomotive.logger "[remove heroku domain] #{name}"
|
||||||
self.heroku_connection.remove_domain(self.config.heroku[:name], name)
|
self.heroku_connection.remove_domain(self.config.heroku[:name], name)
|
||||||
self.heroku_domains.delete(name)
|
self.heroku_domains.delete(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Heroku
|
module Heroku
|
||||||
module CustomDomain
|
module CustomDomain
|
||||||
|
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
|
||||||
after_save :add_heroku_domains
|
after_save :add_heroku_domains
|
||||||
after_destroy :remove_heroku_domains
|
after_destroy :remove_heroku_domains
|
||||||
|
|
||||||
alias_method_chain :add_subdomain_to_domains, :heroku
|
alias_method_chain :add_subdomain_to_domains, :heroku
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def add_subdomain_to_domains_with_heroku
|
def add_subdomain_to_domains_with_heroku
|
||||||
unless self.domains_change.nil?
|
unless self.domains_change.nil?
|
||||||
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
|
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]
|
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
add_subdomain_to_domains_without_heroku
|
add_subdomain_to_domains_without_heroku
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_heroku_domains
|
def add_heroku_domains
|
||||||
return if @heroku_domains_change.nil?
|
return if @heroku_domains_change.nil?
|
||||||
|
|
||||||
@heroku_domains_change[:added].each do |name|
|
@heroku_domains_change[:added].each do |name|
|
||||||
Locomotive.add_heroku_domain(name)
|
Locomotive.add_heroku_domain(name)
|
||||||
end
|
end
|
||||||
@ -38,15 +38,15 @@ module Locomotive
|
|||||||
Locomotive.remove_heroku_domain(name)
|
Locomotive.remove_heroku_domain(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_heroku_domains
|
def remove_heroku_domains
|
||||||
self.domains_without_subdomain.each do |name|
|
self.domains_without_subdomain.each do |name|
|
||||||
Locomotive.remove_heroku_domain(name)
|
Locomotive.remove_heroku_domain(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
require 'locomotive/httparty/webservice'
|
require 'locomotive/httparty/webservice'
|
||||||
require 'locomotive/httparty/patches'
|
require 'locomotive/httparty/patches'
|
||||||
|
@ -2,17 +2,17 @@ require 'crack/json'
|
|||||||
|
|
||||||
module Crack
|
module Crack
|
||||||
class JSON
|
class JSON
|
||||||
|
|
||||||
def self.parse_with_tumblr(json)
|
def self.parse_with_tumblr(json)
|
||||||
cleaned_json = json.gsub(/^var\s+.+\s+=\s+/, '').gsub(/;$/, '')
|
cleaned_json = json.gsub(/^var\s+.+\s+=\s+/, '').gsub(/;$/, '')
|
||||||
parse_without_tumblr(cleaned_json)
|
parse_without_tumblr(cleaned_json)
|
||||||
rescue ArgumentError => e
|
rescue ArgumentError => e
|
||||||
raise ParseError, "Invalid JSON string #{e.inspect}"
|
raise ParseError, "Invalid JSON string #{e.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
alias_method_chain :parse, :tumblr
|
alias_method_chain :parse, :tumblr
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Httparty
|
module Httparty
|
||||||
class Webservice
|
class Webservice
|
||||||
|
|
||||||
include ::HTTParty
|
include ::HTTParty
|
||||||
|
|
||||||
def self.consume(url, options = {})
|
def self.consume(url, options = {})
|
||||||
@ -19,7 +19,7 @@ module Locomotive
|
|||||||
|
|
||||||
self.get(path, options).try(:underscore_keys)
|
self.get(path, options).try(:underscore_keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,12 +35,12 @@ module InheritedResources
|
|||||||
options[:location] ||= collection_url rescue nil
|
options[:location] ||= collection_url rescue nil
|
||||||
|
|
||||||
destroy_resource(object)
|
destroy_resource(object)
|
||||||
|
|
||||||
options[:alert] = object.errors.full_messages.first # display the first error if present
|
options[:alert] = object.errors.full_messages.first # display the first error if present
|
||||||
|
|
||||||
respond_with_dual_blocks(object, options, &block)
|
respond_with_dual_blocks(object, options, &block)
|
||||||
end
|
end
|
||||||
alias :destroy! :destroy
|
alias :destroy! :destroy
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib }
|
Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib }
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.file_system = Locomotive::Liquid::DbFileSystem.new # enable snippets
|
::Liquid::Template.file_system = Locomotive::Liquid::DbFileSystem.new # enable snippets
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
class DbFileSystem
|
class DbFileSystem
|
||||||
|
|
||||||
# Works only with snippets
|
# Works only with snippets
|
||||||
def read_template_file(site, template_path)
|
def read_template_file(site, template_path)
|
||||||
raise FileSystemError, "Illegal snippet name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/
|
raise FileSystemError, "Illegal snippet name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/
|
||||||
|
|
||||||
snippet = site.snippets.where(:slug => template_path).first
|
snippet = site.snippets.where(:slug => template_path).first
|
||||||
|
|
||||||
raise FileSystemError, "No such snippet '#{template_path}'" if snippet.nil?
|
raise FileSystemError, "No such snippet '#{template_path}'" if snippet.nil?
|
||||||
|
|
||||||
snippet.template
|
snippet.template
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
|
|
||||||
class AssetCollections < ::Liquid::Drop
|
class AssetCollections < ::Liquid::Drop
|
||||||
|
|
||||||
def initialize(site)
|
def initialize(site)
|
||||||
@site = site
|
@site = site
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(meth)
|
def before_method(meth)
|
||||||
@site.asset_collections.where(:slug => meth.to_s)
|
@site.asset_collections.where(:slug => meth.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
# Code taken from Mephisto sources (http://mephistoblog.com/)
|
# Code taken from Mephisto sources (http://mephistoblog.com/)
|
||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Base < ::Liquid::Drop
|
class Base < ::Liquid::Drop
|
||||||
|
|
||||||
@@forbidden_attributes = %w{_id _version _index}
|
@@forbidden_attributes = %w{_id _version _index}
|
||||||
|
|
||||||
class_inheritable_reader :liquid_attributes
|
class_inheritable_reader :liquid_attributes
|
||||||
write_inheritable_attribute :liquid_attributes, []
|
write_inheritable_attribute :liquid_attributes, []
|
||||||
attr_reader :source
|
attr_reader :source
|
||||||
delegate :hash, :to => :source
|
delegate :hash, :to => :source
|
||||||
|
|
||||||
def initialize(source)
|
def initialize(source)
|
||||||
unless source.nil?
|
unless source.nil?
|
||||||
@source = source
|
@source = source
|
||||||
@liquid = liquid_attributes.flatten.inject({}) { |h, k| h.update k.to_s => @source.send(k) }
|
@liquid = liquid_attributes.flatten.inject({}) { |h, k| h.update k.to_s => @source.send(k) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def id
|
def id
|
||||||
(@source.respond_to?(:id) ? @source.id : nil) || 'new'
|
(@source.respond_to?(:id) ? @source.id : nil) || 'new'
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(method)
|
def before_method(method)
|
||||||
@liquid[method.to_s]
|
@liquid[method.to_s]
|
||||||
end
|
end
|
||||||
@ -29,7 +29,7 @@ module Locomotive
|
|||||||
# converts an array of records to an array of liquid drops
|
# converts an array of records to an array of liquid drops
|
||||||
def self.liquify(*records, &block)
|
def self.liquify(*records, &block)
|
||||||
i = -1
|
i = -1
|
||||||
records =
|
records =
|
||||||
records.inject [] do |all, r|
|
records.inject [] do |all, r|
|
||||||
i+=1
|
i+=1
|
||||||
attrs = (block && block.arity == 1) ? [r] : [r, i]
|
attrs = (block && block.arity == 1) ? [r] : [r, i]
|
||||||
@ -41,12 +41,12 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def liquify(*records, &block)
|
def liquify(*records, &block)
|
||||||
self.class.liquify(*records, &block)
|
self.class.liquify(*records, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Content < Base
|
class Content < Base
|
||||||
|
|
||||||
def before_method(meth)
|
def before_method(meth)
|
||||||
return '' if @source.nil?
|
return '' if @source.nil?
|
||||||
|
|
||||||
if not @@forbidden_attributes.include?(meth.to_s)
|
if not @@forbidden_attributes.include?(meth.to_s)
|
||||||
value = @source.send(meth)
|
value = @source.send(meth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlighted_field_value
|
def highlighted_field_value
|
||||||
@source.highlighted_field_value
|
@source.highlighted_field_value
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,39 +2,39 @@ module Locomotive
|
|||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Contents < ::Liquid::Drop
|
class Contents < ::Liquid::Drop
|
||||||
|
|
||||||
def initialize(site)
|
def initialize(site)
|
||||||
@site = site
|
@site = site
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(meth)
|
def before_method(meth)
|
||||||
type = @site.content_types.where(:slug => meth.to_s).first
|
type = @site.content_types.where(:slug => meth.to_s).first
|
||||||
ProxyCollection.new(@site, type)
|
ProxyCollection.new(@site, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class ProxyCollection < ::Liquid::Drop
|
class ProxyCollection < ::Liquid::Drop
|
||||||
|
|
||||||
def initialize(site, content_type)
|
def initialize(site, content_type)
|
||||||
@site = site
|
@site = site
|
||||||
@content_type = content_type
|
@content_type = content_type
|
||||||
@collection = nil
|
@collection = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def first
|
def first
|
||||||
content = @content_type.ordered_contents(@context['with_scope']).first
|
content = @content_type.ordered_contents(@context['with_scope']).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def last
|
def last
|
||||||
content = @content_type.ordered_contents(@context['with_scope']).last
|
content = @content_type.ordered_contents(@context['with_scope']).last
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@collection ||= @content_type.ordered_contents(@context['with_scope'])
|
@collection ||= @content_type.ordered_contents(@context['with_scope'])
|
||||||
@collection.each(&block)
|
@collection.each(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def paginate(options = {})
|
def paginate(options = {})
|
||||||
@collection ||= @content_type.ordered_contents(@context['with_scope']).paginate(options)
|
@collection ||= @content_type.ordered_contents(@context['with_scope']).paginate(options)
|
||||||
{
|
{
|
||||||
@ -47,11 +47,11 @@ module Locomotive
|
|||||||
:per_page => @collection.per_page
|
:per_page => @collection.per_page
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def api
|
def api
|
||||||
{ 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) }
|
{ 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(meth)
|
def before_method(meth)
|
||||||
klass = @content_type.contents.klass # delegate to the proxy class
|
klass = @content_type.contents.klass # delegate to the proxy class
|
||||||
if (meth.to_s =~ /^group_by_.+$/) == 0
|
if (meth.to_s =~ /^group_by_.+$/) == 0
|
||||||
@ -61,6 +61,6 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Javascripts < ::Liquid::Drop
|
class Javascripts < ::Liquid::Drop
|
||||||
|
|
||||||
def initialize(site)
|
def initialize(site)
|
||||||
@site = site
|
@site = site
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(meth)
|
def before_method(meth)
|
||||||
asset = @site.theme_assets.where(:content_type => 'javascript', :slug => meth.to_s).first
|
asset = @site.theme_assets.where(:content_type => 'javascript', :slug => meth.to_s).first
|
||||||
!asset.nil? ? asset.source.url : nil
|
!asset.nil? ? asset.source.url : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,4 +22,4 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,4 +12,4 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Stylesheets < ::Liquid::Drop
|
class Stylesheets < ::Liquid::Drop
|
||||||
|
|
||||||
def initialize(site)
|
def initialize(site)
|
||||||
@site = site
|
@site = site
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(meth)
|
def before_method(meth)
|
||||||
asset = @site.theme_assets.where(:content_type => 'stylesheet', :slug => meth.to_s).first
|
asset = @site.theme_assets.where(:content_type => 'stylesheet', :slug => meth.to_s).first
|
||||||
!asset.nil? ? asset.source.url : nil
|
!asset.nil? ? asset.source.url : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,4 +16,4 @@ module Locomotive
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Filters
|
module Filters
|
||||||
module Date
|
module Date
|
||||||
|
|
||||||
def localized_date(input, *args)
|
def localized_date(input, *args)
|
||||||
format, locale = args[0], args[1] rescue 'en'
|
format, locale = args[0], args[1] rescue 'en'
|
||||||
|
|
||||||
date = input.is_a?(String) ? Time.parse(input) : input
|
date = input.is_a?(String) ? Time.parse(input) : input
|
||||||
|
|
||||||
if format.to_s.empty?
|
if format.to_s.empty?
|
||||||
return input.to_s
|
return input.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
date = input.is_a?(String) ? Time.parse(input) : input
|
date = input.is_a?(String) ? Time.parse(input) : input
|
||||||
|
|
||||||
if date.respond_to?(:strftime)
|
if date.respond_to?(:strftime)
|
||||||
I18n.locale = locale
|
I18n.locale = locale
|
||||||
I18n.l date, :format => format
|
I18n.l date, :format => format
|
||||||
@ -21,10 +21,10 @@ module Locomotive
|
|||||||
input
|
input
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Date)
|
::Liquid::Template.register_filter(Date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Filters
|
module Filters
|
||||||
module Html
|
module Html
|
||||||
|
|
||||||
# Write the link to a stylesheet resource
|
# Write the link to a stylesheet resource
|
||||||
# input: url of the css file
|
# input: url of the css file
|
||||||
def stylesheet_tag(input)
|
def stylesheet_tag(input)
|
||||||
@ -10,7 +10,7 @@ module Locomotive
|
|||||||
input = "#{input}.css" unless input.ends_with?('.css')
|
input = "#{input}.css" unless input.ends_with?('.css')
|
||||||
%{<link href="#{input}" media="screen" rel="stylesheet" type="text/css" />}
|
%{<link href="#{input}" media="screen" rel="stylesheet" type="text/css" />}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write the link to javascript resource
|
# Write the link to javascript resource
|
||||||
# input: url of the javascript file
|
# input: url of the javascript file
|
||||||
def javascript_tag(input)
|
def javascript_tag(input)
|
||||||
@ -18,15 +18,15 @@ module Locomotive
|
|||||||
input = "#{input}.js" unless input.ends_with?('.js')
|
input = "#{input}.js" unless input.ends_with?('.js')
|
||||||
%{<script src="#{input}" type="text/javascript"></script>}
|
%{<script src="#{input}" type="text/javascript"></script>}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Write an image tag
|
# Write an image tag
|
||||||
# input: url of the image OR asset drop
|
# input: url of the image OR asset drop
|
||||||
def image_tag(input, *args)
|
def image_tag(input, *args)
|
||||||
image_options = inline_options(args_to_options(args))
|
image_options = inline_options(args_to_options(args))
|
||||||
"<img src=\"#{File.join('/', get_path_from_asset(input))}\" #{image_options}/>"
|
"<img src=\"#{File.join('/', get_path_from_asset(input))}\" #{image_options}/>"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Embed a flash movie into a page
|
# Embed a flash movie into a page
|
||||||
# input: url of the flash movie OR asset drop
|
# input: url of the flash movie OR asset drop
|
||||||
# width: width (in pixel or in %) of the embedded movie
|
# width: width (in pixel or in %) of the embedded movie
|
||||||
@ -46,15 +46,15 @@ module Locomotive
|
|||||||
# Render the navigation for a paginated collection
|
# Render the navigation for a paginated collection
|
||||||
def default_pagination(paginate, *args)
|
def default_pagination(paginate, *args)
|
||||||
return '' if paginate['parts'].empty?
|
return '' if paginate['parts'].empty?
|
||||||
|
|
||||||
options = args_to_options(args)
|
options = args_to_options(args)
|
||||||
|
|
||||||
previous_link = (if paginate['previous'].blank?
|
previous_link = (if paginate['previous'].blank?
|
||||||
"<span class=\"disabled prev_page\">#{I18n.t('pagination.previous')}</span>"
|
"<span class=\"disabled prev_page\">#{I18n.t('pagination.previous')}</span>"
|
||||||
else
|
else
|
||||||
"<a href=\"#{paginate['previous']['url']}\" class=\"prev_page\">#{I18n.t('pagination.previous')}</a>"
|
"<a href=\"#{paginate['previous']['url']}\" class=\"prev_page\">#{I18n.t('pagination.previous')}</a>"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
links = ""
|
links = ""
|
||||||
paginate['parts'].each do |part|
|
paginate['parts'].each do |part|
|
||||||
links << (if part['is_link']
|
links << (if part['is_link']
|
||||||
@ -65,22 +65,22 @@ module Locomotive
|
|||||||
"<span class=\"current\">#{part['title']}</span>"
|
"<span class=\"current\">#{part['title']}</span>"
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
next_link = (if paginate['next'].blank?
|
next_link = (if paginate['next'].blank?
|
||||||
"<span class=\"disabled next_page\">#{I18n.t('pagination.next')}</span>"
|
"<span class=\"disabled next_page\">#{I18n.t('pagination.next')}</span>"
|
||||||
else
|
else
|
||||||
"<a href=\"#{paginate['next']['url']}\" class=\"next_page\">#{I18n.t('pagination.next')}</a>"
|
"<a href=\"#{paginate['next']['url']}\" class=\"next_page\">#{I18n.t('pagination.next')}</a>"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
%{<div class="pagination #{options[:css]}">
|
%{<div class="pagination #{options[:css]}">
|
||||||
#{previous_link}
|
#{previous_link}
|
||||||
#{links}
|
#{links}
|
||||||
#{next_link}
|
#{next_link}
|
||||||
</div>}
|
</div>}
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Convert an array of properties ('key:value') into a hash
|
# Convert an array of properties ('key:value') into a hash
|
||||||
# Ex: ['width:50', 'height:100'] => { :width => '50', :height => '100' }
|
# Ex: ['width:50', 'height:100'] => { :width => '50', :height => '100' }
|
||||||
def args_to_options(*args)
|
def args_to_options(*args)
|
||||||
@ -92,23 +92,23 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write options (Hash) into a string according to the following pattern:
|
# Write options (Hash) into a string according to the following pattern:
|
||||||
# <key1>="<value1>", <key2>="<value2", ...etc
|
# <key1>="<value1>", <key2>="<value2", ...etc
|
||||||
def inline_options(options = {})
|
def inline_options(options = {})
|
||||||
return '' if options.empty?
|
return '' if options.empty?
|
||||||
(options.stringify_keys.to_a.collect { |a, b| "#{a}=\"#{b}\"" }).join(' ') << ' '
|
(options.stringify_keys.to_a.collect { |a, b| "#{a}=\"#{b}\"" }).join(' ') << ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the path to be used in html tags such as image_tag, flash_tag, ...etc
|
# Get the path to be used in html tags such as image_tag, flash_tag, ...etc
|
||||||
# input: url (String) OR asset drop
|
# input: url (String) OR asset drop
|
||||||
def get_path_from_asset(input)
|
def get_path_from_asset(input)
|
||||||
input.respond_to?(:url) ? input.url : input
|
input.respond_to?(:url) ? input.url : input
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Html)
|
::Liquid::Template.register_filter(Html)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Filters
|
module Filters
|
||||||
module Misc
|
module Misc
|
||||||
|
|
||||||
def underscore(input)
|
def underscore(input)
|
||||||
input.to_s.gsub(' ', '_').gsub('/', '_').underscore
|
input.to_s.gsub(' ', '_').gsub('/', '_').underscore
|
||||||
end
|
end
|
||||||
|
|
||||||
def dasherize(input)
|
def dasherize(input)
|
||||||
input.to_s.gsub(' ', '-').gsub('/', '-').dasherize
|
input.to_s.gsub(' ', '-').gsub('/', '-').dasherize
|
||||||
end
|
end
|
||||||
|
|
||||||
def concat(input, *args)
|
def concat(input, *args)
|
||||||
result = input.to_s
|
result = input.to_s
|
||||||
args.flatten.each { |a| result << a.to_s }
|
args.flatten.each { |a| result << a.to_s }
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def modulo(word, index, modulo)
|
def modulo(word, index, modulo)
|
||||||
(index.to_i + 1) % modulo == 0 ? word : ''
|
(index.to_i + 1) % modulo == 0 ? word : ''
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Misc)
|
::Liquid::Template.register_filter(Misc)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Filters
|
module Filters
|
||||||
module Text
|
module Text
|
||||||
|
|
||||||
def textile(input)
|
def textile(input)
|
||||||
::RedCloth.new(input).to_html
|
::RedCloth.new(input).to_html
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Text)
|
::Liquid::Template.register_filter(Text)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module LiquifyTemplate
|
module LiquifyTemplate
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend(ClassMethods)
|
base.extend(ClassMethods)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store the parsed version of a liquid template into a column in order to increase performance
|
# Store the parsed version of a liquid template into a column in order to increase performance
|
||||||
# See http://cjohansen.no/en/rails/liquid_email_templates_in_rails
|
# See http://cjohansen.no/en/rails/liquid_email_templates_in_rails
|
||||||
#
|
#
|
||||||
# class Page
|
# class Page
|
||||||
# liquify_template :body
|
# liquify_template :body
|
||||||
@ -15,33 +15,33 @@ module Locomotive
|
|||||||
#
|
#
|
||||||
# page = Page.new :body => '...some liquid tags'
|
# page = Page.new :body => '...some liquid tags'
|
||||||
# page.template # Liquid::Template
|
# page.template # Liquid::Template
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
||||||
def liquify_template(source = :value)
|
def liquify_template(source = :value)
|
||||||
field :serialized_template, :type => Binary
|
field :serialized_template, :type => Binary
|
||||||
before_validation :store_template
|
before_validation :store_template
|
||||||
|
|
||||||
class_eval <<-EOV
|
class_eval <<-EOV
|
||||||
def liquify_template_source
|
def liquify_template_source
|
||||||
self.send(:#{source.to_s})
|
self.send(:#{source.to_s})
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
|
|
||||||
include InstanceMethods
|
include InstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
def template
|
def template
|
||||||
Marshal.load(read_attribute(:serialized_template).to_s) rescue nil
|
Marshal.load(read_attribute(:serialized_template).to_s) rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def store_template
|
def store_template
|
||||||
begin
|
begin
|
||||||
template = ::Liquid::Template.parse(self.liquify_template_source)
|
template = ::Liquid::Template.parse(self.liquify_template_source)
|
||||||
@ -50,8 +50,8 @@ module Locomotive
|
|||||||
self.errors.add :template, :liquid_syntax_error
|
self.errors.add :template, :liquid_syntax_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Tags
|
module Tags
|
||||||
class Blueprint < ::Liquid::Tag
|
class Blueprint < ::Liquid::Tag
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
%{
|
%{
|
||||||
<link href="/stylesheets/admin/blueprint/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
|
<link href="/stylesheets/admin/blueprint/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
|
||||||
<link href="/stylesheets/admin/blueprint/print.css" media="print" rel="stylesheet" type="text/css" />
|
<link href="/stylesheets/admin/blueprint/print.css" media="print" rel="stylesheet" type="text/css" />
|
||||||
<!--[if IE]>
|
<!--[if IE]>
|
||||||
<link href="/stylesheets/admin/blueprint/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
|
<link href="/stylesheets/admin/blueprint/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_tag('blueprint_stylesheets', Blueprint)
|
::Liquid::Template.register_tag('blueprint_stylesheets', Blueprint)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Tags
|
module Tags
|
||||||
# Consume web services as easy as pie directly in liquid !
|
# Consume web services as easy as pie directly in liquid !
|
||||||
@ -12,7 +12,7 @@ module Locomotive
|
|||||||
# {% endconsume %}
|
# {% endconsume %}
|
||||||
#
|
#
|
||||||
class Consume < ::Liquid::Block
|
class Consume < ::Liquid::Block
|
||||||
|
|
||||||
Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}+)/
|
Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}+)/
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
@ -27,20 +27,20 @@ module Locomotive
|
|||||||
raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume <var> from \"<url>\" [username: value, password: value]")
|
raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume <var> from \"<url>\" [username: value, password: value]")
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
context.stack do
|
context.stack do
|
||||||
context.scopes.last[@target.to_s] = Locomotive::Httparty::Webservice.consume(@url, @options.symbolize_keys)
|
context.scopes.last[@target.to_s] = Locomotive::Httparty::Webservice.consume(@url, @options.symbolize_keys)
|
||||||
|
|
||||||
render_all(@nodelist, context)
|
render_all(@nodelist, context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_tag('consume', Consume)
|
::Liquid::Template.register_tag('consume', Consume)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
module Locomotive
|
module Locomotive
|
||||||
module Tags
|
module Tags
|
||||||
class Jquery < ::Liquid::Tag
|
class Jquery < ::Liquid::Tag
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
@ -10,8 +10,8 @@ module Liquid
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_tag('jQuery', Jquery)
|
::Liquid::Template.register_tag('jQuery', Jquery)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user