upgrade to the last version of delayed_job_mongoid gem + remove reference to the previous handlebars-rails gem (just add the js file instead) + refactor the way to display the list of content types in the back-office menu

This commit is contained in:
did 2012-01-08 16:17:31 -08:00
parent 0926286318
commit 5dfbb2bdb7
13 changed files with 1620 additions and 189 deletions

View File

@ -24,7 +24,7 @@ gem 'coffee-script', '~> 2.2.0'
gem 'uglifier', '~> 1.0.4' gem 'uglifier', '~> 1.0.4'
gem 'jquery-rails', '~> 1.0.16' gem 'jquery-rails', '~> 1.0.16'
gem 'rails-backbone', '0.5.4' gem 'rails-backbone', '0.5.4'
gem 'handlebars-rails', :git => 'git://github.com/yabawock/handlebars-rails.git' # gem 'handlebars-rails', :git => 'git://github.com/yabawock/handlebars-rails.git'
gem 'codemirror-rails' gem 'codemirror-rails'
gem 'tinymce-rails' gem 'tinymce-rails'
gem 'flash_cookie_session', '~> 1.1.1' gem 'flash_cookie_session', '~> 1.1.1'
@ -47,8 +47,7 @@ gem 'rubyzip'
gem 'actionmailer-with-request', '~> 0.3.0', :require => 'actionmailer_with_request' gem 'actionmailer-with-request', '~> 0.3.0', :require => 'actionmailer_with_request'
gem 'httparty', '~> 0.8.1' gem 'httparty', '~> 0.8.1'
gem 'delayed_job', '~> 3.0.0.pre4' gem 'delayed_job_mongoid', '~> 1.0.8'
gem 'delayed_job_mongoid', '~> 1.0.7'
gem 'SystemTimer', :platforms => :ruby_18 gem 'SystemTimer', :platforms => :ruby_18
# The rest of the dependencies are for use when in the locomotive dev environment # The rest of the dependencies are for use when in the locomotive dev environment

View File

@ -1,27 +1,22 @@
GIT GIT
remote: git://github.com/chriseppstein/compass.git remote: git://github.com/chriseppstein/compass.git
revision: 79d94647f9a00b06c4a83db02e86f5d404569baf revision: bffba483754cb9381fa51efd8e2a1f0482a21ac6
specs: specs:
compass (0.12.alpha.1.79d9464) compass (0.12.alpha.4.bffba48)
chunky_png (~> 1.2) chunky_png (~> 1.2)
fssm (>= 0.2.7) fssm (>= 0.2.7)
sass (~> 3.1) sass (~> 3.1)
GIT GIT
remote: git://github.com/plataformatec/devise.git remote: git://github.com/plataformatec/devise.git
revision: ede004169c6af7416f8c4e3fc29a653bee133f60 revision: a949f9eca24f9d43f516363fbf2f5d004623355e
specs: specs:
devise (1.5.1) devise (2.0.0.rc)
bcrypt-ruby (~> 3.0) bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3) orm_adapter (~> 0.0.3)
railties (~> 3.1)
warden (~> 1.1) warden (~> 1.1)
GIT
remote: git://github.com/yabawock/handlebars-rails.git
revision: a09077aa91f10e08403af84586b2f2f0b38d9e2f
specs:
handlebars-rails (0.9.1)
GIT GIT
remote: git@github.com:locomotivecms/mongoid_acts_as_tree.git remote: git@github.com:locomotivecms/mongoid_acts_as_tree.git
revision: ca494d22c3d7946385aba1153c017d9c30e9f9d3 revision: ca494d22c3d7946385aba1153c017d9c30e9f9d3
@ -39,7 +34,7 @@ PATH
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
RedCloth (4.2.8) RedCloth (4.2.9)
SystemTimer (1.2.3) SystemTimer (1.2.3)
ZenTest (4.6.2) ZenTest (4.6.2)
actionmailer (3.1.3) actionmailer (3.1.3)
@ -77,7 +72,7 @@ GEM
autotest (4.4.6) autotest (4.4.6)
ZenTest (>= 4.4.1) ZenTest (>= 4.4.1)
bcrypt-ruby (3.0.1) bcrypt-ruby (3.0.1)
bson (1.4.0) bson (1.5.2)
bson_ext (1.4.0) bson_ext (1.4.0)
builder (3.0.0) builder (3.0.0)
bushido (0.0.35) bushido (0.0.35)
@ -98,44 +93,43 @@ GEM
carrierwave-mongoid (0.1.3) carrierwave-mongoid (0.1.3)
carrierwave (>= 0.5.6) carrierwave (>= 0.5.6)
mongoid (~> 2.1) mongoid (~> 2.1)
cells (3.7.0) cells (3.7.1)
actionpack (~> 3.0) actionpack (~> 3.0)
railties (~> 3.0) railties (~> 3.0)
childprocess (0.2.2) childprocess (0.2.6)
ffi (~> 1.0.6) ffi (~> 1.0.6)
chunky_png (1.2.5) chunky_png (1.2.5)
codemirror-rails (0.3.1) codemirror-rails (0.3.2)
railties (~> 3.0)
coffee-script (2.2.0) coffee-script (2.2.0)
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.1.3) coffee-script-source (1.2.0)
cucumber (1.1.3) cucumber (1.1.4)
builder (>= 2.1.2) builder (>= 2.1.2)
diff-lcs (>= 1.1.2) diff-lcs (>= 1.1.2)
gherkin (~> 2.6.7) gherkin (~> 2.7.1)
json (>= 1.4.6) json (>= 1.4.6)
term-ansicolor (>= 1.0.6) term-ansicolor (>= 1.0.6)
cucumber-rails (1.2.0) cucumber-rails (1.2.1)
capybara (>= 1.1.1) capybara (>= 1.1.2)
cucumber (>= 1.1.1) cucumber (>= 1.1.3)
nokogiri (>= 1.5.0) nokogiri (>= 1.5.0)
daemons (1.0.10)
database_cleaner (0.7.0) database_cleaner (0.7.0)
delayed_job (3.0.0.pre4) delayed_job (3.0.0)
activesupport (~> 3.0) activesupport (~> 3.0)
daemons (= 1.0.10) delayed_job_mongoid (1.0.8)
delayed_job_mongoid (1.0.7) delayed_job (~> 3.0.0)
delayed_job (~> 3.0.0.pre)
mongoid (>= 2.0) mongoid (>= 2.0)
diff-lcs (1.1.3) diff-lcs (1.1.3)
dragonfly (0.9.8) dragonfly (0.9.9)
rack rack
ejs (1.0.0) ejs (1.0.0)
erubis (2.7.0) erubis (2.7.0)
excon (0.7.8) excon (0.7.12)
execjs (1.2.9) execjs (1.2.13)
multi_json (~> 1.0) multi_json (~> 1.0)
factory_girl (2.3.1) factory_girl (2.3.2)
activesupport activesupport
factory_girl_rails (1.4.0) factory_girl_rails (1.4.0)
factory_girl (~> 2.3.0) factory_girl (~> 2.3.0)
@ -156,25 +150,26 @@ GEM
formatador (0.2.1) formatador (0.2.1)
formtastic (2.0.2) formtastic (2.0.2)
rails (~> 3.0) rails (~> 3.0)
fssm (0.2.7) fssm (0.2.8.1)
gherkin (2.6.8) gherkin (2.7.2)
json (>= 1.4.6) json (>= 1.4.6)
growl-glue (1.0.7) growl-glue (1.0.7)
haml (3.1.3) haml (3.1.4)
highline (1.6.8) highline (1.6.9)
hike (1.2.1) hike (1.2.1)
httparty (0.8.1) httparty (0.8.1)
multi_json multi_json
multi_xml multi_xml
i18n (0.6.0) i18n (0.6.0)
jquery-rails (1.0.18) jquery-rails (1.0.19)
railties (~> 3.0) railties (~> 3.0)
thor (~> 0.14) thor (~> 0.14)
json (1.6.1) json (1.6.4)
json_pure (1.6.1) kaminari (0.13.0)
kaminari (0.12.4) actionpack (>= 3.0.0)
rails (>= 3.0.0) activesupport (>= 3.0.0)
kgio (2.6.0) railties (>= 3.0.0)
kgio (2.7.2)
launchy (2.0.5) launchy (2.0.5)
addressable (~> 2.2.6) addressable (~> 2.2.6)
locomotive_liquid (2.2.2) locomotive_liquid (2.2.2)
@ -185,13 +180,13 @@ GEM
mime-types (1.17.2) mime-types (1.17.2)
mimetype-fu (0.1.2) mimetype-fu (0.1.2)
mocha (0.9.12) mocha (0.9.12)
mongo (1.4.0) mongo (1.5.2)
bson (= 1.4.0) bson (= 1.5.2)
mongoid (2.3.4) mongoid (2.3.4)
activemodel (~> 3.1) activemodel (~> 3.1)
mongo (~> 1.3) mongo (~> 1.3)
tzinfo (~> 0.3.22) tzinfo (~> 0.3.22)
multi_json (1.0.3) multi_json (1.0.4)
multi_xml (0.4.1) multi_xml (0.4.1)
net-scp (1.0.4) net-scp (1.0.4)
net-ssh (>= 1.99.1) net-ssh (>= 1.99.1)
@ -202,7 +197,7 @@ GEM
cucumber (>= 0.8) cucumber (>= 0.8)
rake rake
polyglot (0.3.3) polyglot (0.3.3)
rack (1.3.5) rack (1.3.6)
rack-cache (1.1) rack-cache (1.1)
rack (>= 0.4) rack (>= 0.4)
rack-mount (0.8.3) rack-mount (0.8.3)
@ -232,7 +227,7 @@ GEM
thor (~> 0.14.6) thor (~> 0.14.6)
raindrops (0.8.0) raindrops (0.8.0)
rake (0.9.2) rake (0.9.2)
rdoc (3.11) rdoc (3.12)
json (~> 1.4) json (~> 1.4)
responders (0.6.4) responders (0.6.4)
rest-client (1.6.7) rest-client (1.6.7)
@ -242,7 +237,7 @@ GEM
rspec-core (~> 2.6.0) rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0) rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0) rspec-mocks (~> 2.6.0)
rspec-cells (0.1.0) rspec-cells (0.1.1)
rails (~> 3.0) rails (~> 3.0)
rspec-rails (~> 2.2) rspec-rails (~> 2.2)
rspec-core (2.6.4) rspec-core (2.6.4)
@ -255,19 +250,19 @@ GEM
railties (~> 3.0) railties (~> 3.0)
rspec (~> 2.6.0) rspec (~> 2.6.0)
ruby-hmac (0.4.0) ruby-hmac (0.4.0)
rubyzip (0.9.4) rubyzip (0.9.5)
sanitize (2.0.3) sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6) nokogiri (>= 1.4.4, < 1.6)
sass (3.1.10) sass (3.1.12)
sass-rails (3.1.5) sass-rails (3.1.5)
actionpack (~> 3.1.0) actionpack (~> 3.1.0)
railties (~> 3.1.0) railties (~> 3.1.0)
sass (~> 3.1.10) sass (~> 3.1.10)
tilt (~> 1.3.2) tilt (~> 1.3.2)
selenium-webdriver (2.13.0) selenium-webdriver (2.16.0)
childprocess (>= 0.2.1) childprocess (>= 0.2.5)
ffi (~> 1.0.9) ffi (~> 1.0.9)
json_pure multi_json (~> 1.0.4)
rubyzip rubyzip
sprockets (2.0.3) sprockets (2.0.3)
hike (~> 1.2) hike (~> 1.2)
@ -315,8 +310,7 @@ DEPENDENCIES
cucumber-rails cucumber-rails
custom_fields! custom_fields!
database_cleaner database_cleaner
delayed_job (~> 3.0.0.pre4) delayed_job_mongoid (~> 1.0.8)
delayed_job_mongoid (~> 1.0.7)
devise! devise!
dragonfly (~> 0.9.8) dragonfly (~> 0.9.8)
factory_girl_rails (~> 1.1) factory_girl_rails (~> 1.1)
@ -325,7 +319,6 @@ DEPENDENCIES
formtastic (~> 2.0.2) formtastic (~> 2.0.2)
growl-glue growl-glue
haml (~> 3.1.3) haml (~> 3.1.3)
handlebars-rails!
highline (~> 1.6.2) highline (~> 1.6.2)
httparty (~> 0.8.1) httparty (~> 0.8.1)
jquery-rails (~> 1.0.16) jquery-rails (~> 1.0.16)

View File

@ -8,7 +8,6 @@
//= require jquery-ui //= require jquery-ui
//= require jquery_ujs //= require jquery_ujs
//= require underscore //= require underscore
//= require handlebars
//= require backbone //= require backbone
//= require codemirror //= require codemirror
//= require tinymce-jquery //= require tinymce-jquery

View File

@ -36,14 +36,6 @@ module Locomotive::BaseHelper
end end
end end
# def collection_to_js(collection, options = {}) # FIXME: DEPRECATED
# js = collection.collect { |object| object.to_json }
#
# options_to_js = ActiveSupport::JSON.encode(options).gsub(/^\{/, '').gsub(/\}$/, '')
#
# "new Object({ \"collection\": [#{js.join(', ')}], #{options_to_js} })"
# end
def flash_message def flash_message
if not flash.empty? if not flash.empty?
first_key = flash.keys.first first_key = flash.keys.first

View File

@ -1,23 +1,50 @@
module Locomotive::ContentTypesHelper module Locomotive::ContentTypesHelper
def each_content_type_menu_item(&block) # Iterates over the content types with the following rules
current_site.content_types.ordered.only(:site_id, :name, :slug, :label_field_name).each do |content_type| # - content types are ordered by the updated_at date (DESC)
next unless content_type.persisted? # - each content type has its own submenu if saved recently
# - if there are more than ui.max_content_types content types, the extra ones go under "..."
# - if a content type is selected and it is part of the extra content types, then
# it will be moved to the first position in the displayed list (with its own submenu)
#
# @param [ Block ] block The statements responsible to display the menu item from a content type or a list of content types
#
def each_content_type(&block)
visible, others = [], []
item_on = (content_type.slug == @content_type.slug) rescue nil current_site.content_types.ordered.only(:site_id, :name, :slug, :label_field_name).each_with_index do |content_type, index|
next if !content_type.persisted?
label = truncate(content_type.name, :length => 15) if index >= Locomotive.config.ui.max_content_types
url = content_entries_url(content_type.slug) if self.is_content_type_selected(content_type)
css = @content_type && content_type.slug == @content_type.slug ? 'on' : '' others << visible.delete_at(Locomotive.config.ui.max_content_types - 1) # swap content types
visible.insert(0, content_type)
html = submenu_entry(label, url, :i18n => false, :css => css) do else
yield(content_type) others << content_type # fills the "..." menu
end
next
end end
haml_concat(html) visible << content_type
end end
visible.map { |c| yield(c) }
yield(others)
end end
def is_content_type_selected(content_type)
@content_type && content_type.slug == @content_type.slug
end
# Renders the label of a content type entry. If no raw_item_template filled in the content type,
# it just calls the _label method of the entry (based on the label_field_id). Otherwise, it
# parses and renders the liquid template.
#
# @param [ ContentType ] content_type The content type for better performance
# @param [ ContentEntry] entry The entry we want to display the label
#
# @return [ String ] The label of the content type entry
#
def entry_label(content_type, entry) def entry_label(content_type, entry)
if content_type.raw_item_template.blank? if content_type.raw_item_template.blank?
entry._label # default one entry._label # default one
@ -34,90 +61,4 @@ module Locomotive::ContentTypesHelper
end end
end end
# MAX_DISPLAYED_CONTENTS = 4
#
# def fetch_content_types
# return @content_types if @content_types
#
# @content_types = current_site.content_types.ordered.
# limit(:contents => Locomotive.config.lastest_items_nb).
# only(:site_id, :name, :slug, :highlighted_field_name, :contents_custom_fields_version, :order_by, :serialized_item_template, :raw_item_template).to_a
#
# if @content_type && @content_type.persisted? && @content_types.index(@content_type) >= MAX_DISPLAYED_CONTENTS
# @content_types.delete(@content_type)
# @content_types.insert(0, @content_type)
# end
#
# # be sure, we've got the custom klass up-to-date, otherwise it will fail miserably
# @content_types.each do |content_type|
# if content_type.content_klass_out_of_date?
# content_type.reload
# content_type.invalidate_content_klass
# end
# end
#
# @content_types
# end
#
# def each_content_type_menu_item(which = :first, &block)
# types = fetch_content_types
# sliced = []
#
# if which == :first
# sliced = types[0..MAX_DISPLAYED_CONTENTS - 1]
# elsif types.size > MAX_DISPLAYED_CONTENTS
# sliced = types[MAX_DISPLAYED_CONTENTS, types.size - MAX_DISPLAYED_CONTENTS]
# end
#
# return [] if sliced.empty?
#
# sliced.each do |content_type|
# next if content_type.new_record?
# item_on = (content_type.slug == @content_type.slug) rescue nil
#
# label = truncate(content_type.name, :length => 15)
# url = contents_url(content_type.slug)
# css = @content_type && content_type.slug == @content_type.slug ? 'on' : ''
#
# html = submenu_entry(label, url, :i18n => false, :css => css) do
# yield(content_type)
# end
#
# haml_concat(html)
# end
# end
#
# def other_content_types(&block)
# types = fetch_content_types
#
# if types.size > MAX_DISPLAYED_CONTENTS
# sliced = types[MAX_DISPLAYED_CONTENTS, types.size - MAX_DISPLAYED_CONTENTS]
#
# html = submenu_entry('...', '#', :i18n => false) do
# yield(sliced)
# end
#
# haml_concat(html)
# end
# end
#
# def content_label_for(content)
# if content._parent.raw_item_template.blank?
# content._label # default one
# else
# assigns = {
# 'site' => current_site,
# 'content' => content.to_liquid
# }
#
# registers = {
# :controller => self,
# :site => current_site,
# :current_locomotive_account => current_locomotive_account
# }
#
# preserve(content._parent.item_template.render(::Liquid::Context.new({}, assigns, registers)))
# end
# end
end end

View File

@ -27,7 +27,7 @@ module Locomotive
## named scopes ## ## named scopes ##
scope :visible, :where => { :_visible => true } scope :visible, :where => { :_visible => true }
scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.lastest_entries_nb scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.ui.lastest_entries_nb
## methods ## ## methods ##

View File

@ -41,7 +41,7 @@ module Locomotive
validates_exclusion_of :slug, :in => Locomotive.config.reserved_slugs, :if => Proc.new { |p| p.depth == 0 } validates_exclusion_of :slug, :in => Locomotive.config.reserved_slugs, :if => Proc.new { |p| p.depth == 0 }
## named scopes ## ## named scopes ##
scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_entries_nb scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.ui.lastest_entries_nb
scope :root, :where => { :slug => 'index', :depth => 0 } scope :root, :where => { :slug => 'index', :depth => 0 }
scope :not_found, :where => { :slug => '404', :depth => 0 } scope :not_found, :where => { :slug => '404', :depth => 0 }
scope :published, :where => { :published => true } scope :published, :where => { :published => true }

View File

@ -11,25 +11,30 @@
= link_to truncate(page.title, :length => 25), edit_page_url(page) = link_to truncate(page.title, :length => 25), edit_page_url(page)
%span= time_ago_in_words(page.updated_at) %span= time_ago_in_words(page.updated_at)
- each_content_type_menu_item do |content_type| - each_content_type do |menu_item|
.wrapper -if menu_item.is_a?(Array)
.header - content_types = menu_item
%p= link_to t('locomotive.content_entries.index.new'), new_content_entry_url(content_type.slug) = submenu_entry '...', '#', :i18n => false do
.wrapper
.inner
%ul.big-links
- content_types.each do |content_type|
%li
= link_to truncate(content_type.name, :length => 20), content_entries_url(content_type.slug)
- else
- content_type = menu_item
= submenu_entry truncate(content_type.name, :length => 15), content_entries_url(content_type.slug), :i18n => false, :css => "#{'on' if is_content_type_selected(content_type)}" do
.wrapper
.header
%p= link_to t('locomotive.content_entries.index.new'), new_content_entry_url(content_type.slug)
- if can? :manage, content_type - if can? :manage, content_type
%p.edit= link_to t('locomotive.content_entries.index.edit'), edit_content_type_url(content_type) %p.edit= link_to t('locomotive.content_types.index.edit'), edit_content_type_url(content_type)
.inner .inner
%h2!= t('locomotive.content_entries.index.lastest_entries') %h2!= t('locomotive.content_entries.index.lastest_entries')
%ul %ul
- content_type.entries.latest_updated.each do |entry| - content_type.entries.latest_updated.each do |entry|
%li %li
= link_to truncate(entry._label(content_type), :length => 20), edit_content_entry_url(content_type.slug, entry) = link_to truncate(entry._label(content_type), :length => 20), edit_content_entry_url(content_type.slug, entry)
%span= time_ago_in_words(entry.updated_at) %span= time_ago_in_words(entry.updated_at)
/ - other_content_types do |content_types|
/ .inner
/ %ul.big-links
/ - content_types.each do |content_type|
/ %li
/ = link_to truncate(content_type.name, :length => 20), contents_url(content_type.slug)

View File

@ -49,7 +49,7 @@ x edit my site
x show / hide options of a field based on its type x show / hide options of a field based on its type
x select: add/edit/remove options x select: add/edit/remove options
x text: formatting x text: formatting
- change in main menu x change in main menu
x manage contents x manage contents
x list (highlighted field) x list (highlighted field)
x slugify x slugify

View File

@ -44,7 +44,10 @@ Locomotive.configure do |config|
config.delayed_job = false config.delayed_job = false
# 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_entries_nb = 5 # config.ui = {
# :lastest_entries_nb => 5,
# :max_content_types => 1
# }
# default locale (for now, only en, de, fr, pt-BR and it are supported) # default locale (for now, only en, de, fr, pt-BR and it are supported)
config.default_locale = :en config.default_locale = :en

View File

@ -16,7 +16,10 @@ module Locomotive
:mailer_sender => 'support@example.com', :mailer_sender => 'support@example.com',
:manage_subdomain => false, :manage_subdomain => false,
:manage_manage_domains => false, :manage_manage_domains => false,
:lastest_entries_nb => 5, :ui => {
:lastest_entries_nb => 5,
:max_content_types => 1 # TODO 4
},
:rack_cache => { :rack_cache => {
:verbose => true, :verbose => true,
:metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces :metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces

View File

@ -45,7 +45,10 @@ Locomotive.configure do |config|
config.delayed_job = true # false config.delayed_job = true # false
# 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_entries_nb = 5 # config.ui = {
# :lastest_entries_nb => 5,
# :max_content_types => 1
# }
# default locale (for now, only en, de, fr, pt-BR and it are supported) # default locale (for now, only en, de, fr, pt-BR and it are supported)
config.default_locale = :en config.default_locale = :en

1493
vendor/assets/javascripts/handlebars.js vendored Normal file

File diff suppressed because it is too large Load Diff