From 22f34a5a6031fb58e9094ed3274e90c9a884e3cf Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 15:36:19 +0800 Subject: [PATCH 01/65] Added a failing feature for #336. --- features/backoffice/mounting.feature | 13 +++++++++++++ .../backoffice/mounting_steps.rb | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 features/backoffice/mounting.feature create mode 100644 features/step_definitions/backoffice/mounting_steps.rb diff --git a/features/backoffice/mounting.feature b/features/backoffice/mounting.feature new file mode 100644 index 00000000..0f6af821 --- /dev/null +++ b/features/backoffice/mounting.feature @@ -0,0 +1,13 @@ +Feature: Mounting Locomotive CMS + As an administrator + In order to gain some flexibility when mounting locomotive CMS + I want to be able to mount locomotove on any given path + + Background: + Given I have a site set up + + @javascript + Scenario: Accessing the backend when mounted on a custom path + Given the engine is mounted on a non standard path + And I am an authenticated "admin" + Then I should be able to access the backend diff --git a/features/step_definitions/backoffice/mounting_steps.rb b/features/step_definitions/backoffice/mounting_steps.rb new file mode 100644 index 00000000..fc9c6adf --- /dev/null +++ b/features/step_definitions/backoffice/mounting_steps.rb @@ -0,0 +1,16 @@ +Given /^the engine is mounted on a non standard path$/ do + Rails.application.routes.draw do + mount Locomotive::Engine => '/my-custom-path', :as => 'locomotive' + end +end + +Then /^I should be able to access the backend$/ do + # Ensure we can access the backend + visit '/my-custom-path' + page.should have_content 'LocomotiveCMS' + + # Ensure we can update the homepage content + click_link 'Home page' + click_button 'Save' + page.should have_content 'Page was successfully updated' +end From 667768990218e52e28fda2b5da82ed394c347f2f Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 15:54:54 +0800 Subject: [PATCH 02/65] Load the locomotive mount path earlier in the JS to make it available for backbone models. Fixes #336 --- app/assets/javascripts/locomotive/application.js.coffee | 4 ++-- app/views/locomotive/shared/_head.html.haml | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/locomotive/application.js.coffee b/app/assets/javascripts/locomotive/application.js.coffee index ea35ecea..6590be79 100644 --- a/app/assets/javascripts/locomotive/application.js.coffee +++ b/app/assets/javascripts/locomotive/application.js.coffee @@ -4,9 +4,9 @@ #= require_tree ./views window.Locomotive = - mounted_on: '/locomotive' # default path + mounted_on: window.Locomotive.mounted_on Models: {} Collections: {} Views: {} -window.Locomotive.Views.Memberships = {} \ No newline at end of file +window.Locomotive.Views.Memberships = {} diff --git a/app/views/locomotive/shared/_head.html.haml b/app/views/locomotive/shared/_head.html.haml index 89f25515..fb89e923 100644 --- a/app/views/locomotive/shared/_head.html.haml +++ b/app/views/locomotive/shared/_head.html.haml @@ -7,6 +7,10 @@ %meta{ :name => 'key-param', :content => Rails.application.config.session_options[:key] } %meta{ :name => 'key-token', :content => cookies[key] } +%script{ :type => 'text/javascript' } + :plain + window.Locomotive = { mounted_on: '#{Locomotive.mounted_on}' }; + = stylesheet_link_tag 'locomotive', :media => 'screen' = javascript_include_tag 'locomotive' @@ -15,7 +19,6 @@ window.locale = '#{I18n.locale}'; window.content_locale = '#{::Mongoid::Fields::I18n.locale}'; - Locomotive.mounted_on = '#{Locomotive.mounted_on}'; Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_json}); Locomotive.current_account = new Locomotive.Models.Account(#{current_locomotive_account.to_json}); @@ -32,4 +35,4 @@ = yield :head -= render 'locomotive/shared/main_app_head' \ No newline at end of file += render 'locomotive/shared/main_app_head' From 760687d3fe0462fe67f8f6c9d64486086e1c3610 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 16:08:06 +0800 Subject: [PATCH 03/65] Small cucumber steps fix that was messing with routing. --- features/step_definitions/backoffice/mounting_steps.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/step_definitions/backoffice/mounting_steps.rb b/features/step_definitions/backoffice/mounting_steps.rb index fc9c6adf..b142a72c 100644 --- a/features/step_definitions/backoffice/mounting_steps.rb +++ b/features/step_definitions/backoffice/mounting_steps.rb @@ -13,4 +13,7 @@ Then /^I should be able to access the backend$/ do click_link 'Home page' click_button 'Save' page.should have_content 'Page was successfully updated' + + # Reset the routes back to normal once we are done + Rails.application.reload_routes! end From e4133738586e0b4c5f93fe047068c1efd9ea2984 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 16:13:24 +0800 Subject: [PATCH 04/65] Test the master and 1.0 stable branches. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1a2513bf..aeec3fa5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ notifications: branches: only: - master - - 2.0.0.rc + - 1.0.0 From 7260f36be7e3143932179c2fa3355f555d20468c Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 23:10:16 +0800 Subject: [PATCH 05/65] Downcase subdomains and domains when given as user input. --- .../extensions/site/subdomain_domains.rb | 8 +++++-- .../extensions/site/subdomain_domains_spec.rb | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 spec/models/locomotive/extensions/site/subdomain_domains_spec.rb diff --git a/app/models/locomotive/extensions/site/subdomain_domains.rb b/app/models/locomotive/extensions/site/subdomain_domains.rb index 46f1df2a..71963b5f 100644 --- a/app/models/locomotive/extensions/site/subdomain_domains.rb +++ b/app/models/locomotive/extensions/site/subdomain_domains.rb @@ -37,9 +37,13 @@ module Locomotive module InstanceMethods + def subdomain=(subdomain) + super(subdomain.try(:downcase)) + end + def domains=(array) array.reject!(&:blank?) - array = [] if array.blank?; super(array) + array = [] if array.blank?; super(array.map(&:downcase)) end def add_subdomain_to_domains @@ -84,4 +88,4 @@ module Locomotive end end end -end \ No newline at end of file +end diff --git a/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb b/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb new file mode 100644 index 00000000..f9fb33e4 --- /dev/null +++ b/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Locomotive::Extensions::Site::SubdomainDomains do + describe '#subdomain=' do + let(:site) { Locomotive::Site.new } + + it 'downcases the subdomain' do + site.subdomain = 'MiXeDCaSe' + + site.subdomain.should == 'mixedcase' + end + end + + describe '#domains=' do + let(:site) { Locomotive::Site.new } + + it 'downcases the domains' do + site.domains = ['FIRST.com', 'second.com', 'THIRD.com'] + + site.domains.should == ['first.com', 'second.com', 'third.com'] + end + end +end From 63c17313fb620a243d29ad8643630398ee138321 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 23:39:29 +0800 Subject: [PATCH 06/65] Test the 1.0 stable branch. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aeec3fa5..8abce396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ notifications: branches: only: - master - - 1.0.0 + - 1.0-stable From 087f9c6c552e92caa6aa9d4695e239cc40bf42da Mon Sep 17 00:00:00 2001 From: Dan Sapala Date: Sat, 7 Apr 2012 15:59:50 -0400 Subject: [PATCH 07/65] fixing misspelled word wizard --- lib/generators/locomotive/install/templates/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/locomotive/install/templates/README b/lib/generators/locomotive/install/templates/README index 7ce9b161..ef88b677 100644 --- a/lib/generators/locomotive/install/templates/README +++ b/lib/generators/locomotive/install/templates/README @@ -19,8 +19,8 @@ The Locomotive Engine has been correctly installed in your Rails application. > open localhost:8080 - 4. Follow the installation wizzard steps + 4. Follow the installation wizard steps 5. Enjoy ! -=============================================================================== \ No newline at end of file +=============================================================================== From ad9bd5f5f39a53cc933dd4e1b1f43dc7363ad6a7 Mon Sep 17 00:00:00 2001 From: Sergey Kuleshov Date: Fri, 6 Apr 2012 18:03:46 +0300 Subject: [PATCH 08/65] support cyrilic in slug --- app/assets/javascripts/locomotive/utils/core_ext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/locomotive/utils/core_ext.js b/app/assets/javascripts/locomotive/utils/core_ext.js index 2a6e4f46..504f335b 100644 --- a/app/assets/javascripts/locomotive/utils/core_ext.js +++ b/app/assets/javascripts/locomotive/utils/core_ext.js @@ -18,7 +18,7 @@ String.prototype.slugify = function(sep) { if (typeof sep == 'undefined') sep = '_'; - var alphaNumRegexp = new RegExp('[^a-zA-Z0-9\\' + sep + ']', 'g'); + var alphaNumRegexp = new RegExp('[^a-zA-Z0-9а-яА-Я\\' + sep + ']', 'g'); var avoidDuplicateRegexp = new RegExp('[\\' + sep + ']{2,}', 'g'); return this.replace(/\s/g, sep).replace(alphaNumRegexp, '').replace(avoidDuplicateRegexp, sep).toLowerCase() } From 2798e15481801aaab0f0b60da44938081f4385c3 Mon Sep 17 00:00:00 2001 From: Sergey Kuleshov Date: Sat, 7 Apr 2012 20:25:36 +0300 Subject: [PATCH 09/65] =?UTF-8?q?Made=20JS=20permalink=20regexp=20more=20g?= =?UTF-8?q?eneric=20for=20non=E2=80=93latin=20languages.=20Fixed=20specs?= =?UTF-8?q?=20for=20permalinks=20generated=20by=20stringex.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 2 ++ app/assets/javascripts/locomotive/utils/core_ext.js | 2 +- spec/models/locomotive/content_entry_spec.rb | 7 ++++++- spec/models/locomotive/page_spec.rb | 6 +++--- spec/models/locomotive/snippet_spec.rb | 8 ++++---- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 55ff43f7..aa6289dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,7 @@ PATH responders (~> 0.6.4) rmagick (~> 2.12.2) sanitize (~> 2.0.3) + stringex (~> 1.3.2) GEM remote: http://rubygems.org/ @@ -297,6 +298,7 @@ GEM hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + stringex (1.3.2) term-ansicolor (1.0.7) thor (0.14.6) tilt (1.3.3) diff --git a/app/assets/javascripts/locomotive/utils/core_ext.js b/app/assets/javascripts/locomotive/utils/core_ext.js index 504f335b..c3e112cd 100644 --- a/app/assets/javascripts/locomotive/utils/core_ext.js +++ b/app/assets/javascripts/locomotive/utils/core_ext.js @@ -18,7 +18,7 @@ String.prototype.slugify = function(sep) { if (typeof sep == 'undefined') sep = '_'; - var alphaNumRegexp = new RegExp('[^a-zA-Z0-9а-яА-Я\\' + sep + ']', 'g'); + var alphaNumRegexp = new RegExp('[^\w\\' + sep + ']', 'g'); var avoidDuplicateRegexp = new RegExp('[\\' + sep + ']{2,}', 'g'); return this.replace(/\s/g, sep).replace(alphaNumRegexp, '').replace(avoidDuplicateRegexp, sep).toLowerCase() } diff --git a/spec/models/locomotive/content_entry_spec.rb b/spec/models/locomotive/content_entry_spec.rb index fbe58d6b..f4a1ced2 100644 --- a/spec/models/locomotive/content_entry_spec.rb +++ b/spec/models/locomotive/content_entry_spec.rb @@ -146,7 +146,12 @@ describe Locomotive::ContentEntry do it 'removes dots' do @content_entry.title = "my.test"; @content_entry.send(:set_slug) - @content_entry._permalink.should == 'my-test' + @content_entry._permalink.should == 'my-dot-test' + end + + it 'accepts non-latin chars' do + @content_entry.title = "абракадабра"; @content_entry.send(:set_slug) + @content_entry._permalink.should == 'abrakadabra' end it 'also accepts a file field as the highlighted field' do diff --git a/spec/models/locomotive/page_spec.rb b/spec/models/locomotive/page_spec.rb index cbcf4ea6..adc442be 100644 --- a/spec/models/locomotive/page_spec.rb +++ b/spec/models/locomotive/page_spec.rb @@ -102,11 +102,11 @@ describe Locomotive::Page do it 'should have normalized slug' do page = FactoryGirl.build(:page, :slug => ' Valid ité.html ') page.valid? - page.slug.should == 'valid-ite-html' + page.slug.should == 'valid-ite-dot-html' page = FactoryGirl.build(:page, :title => ' Valid ité.html ', :slug => nil, :site => page.site) page.should be_valid - page.slug.should == 'valid-ite-html' + page.slug.should == 'valid-ite-dot-html' end it 'has no cache strategy' do @@ -235,7 +235,7 @@ describe Locomotive::Page do it 'fills in the slug field' do @page.valid? - @page.slug.should == 'content_type_template' + @page.slug.should == 'content-type-template' end it 'returns the target klass' do diff --git a/spec/models/locomotive/snippet_spec.rb b/spec/models/locomotive/snippet_spec.rb index 274fee6e..bfa8cf15 100644 --- a/spec/models/locomotive/snippet_spec.rb +++ b/spec/models/locomotive/snippet_spec.rb @@ -20,13 +20,13 @@ describe Locomotive::Snippet do before :each do @site = FactoryGirl.create(:site, :subdomain => 'omg') - @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my_test_snippet', :template => 'a testing template') + @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my-test-snippet', :template => 'a testing template') end context 'with a normal top level snippet' do before :each do - @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% include 'my_test_snippet' %}") + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% include 'my-test-snippet' %}") end it 'updates templates with the new snippet template' do @@ -39,7 +39,7 @@ describe Locomotive::Snippet do context 'for snippets inside of a block' do before :each do - @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% block main %}{% include 'my_test_snippet' %}{% endblock %}") + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% block main %}{% include 'my-test-snippet' %}{% endblock %}") end it 'updates templates with the new snippet template' do @@ -54,7 +54,7 @@ describe Locomotive::Snippet do before :each do Mongoid::Fields::I18n.with_locale(:fr) do @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my_localized_test_snippet', :template => 'a testing template') - @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_localized_test_snippet', :raw_template => "{% block main %}{% include 'my_localized_test_snippet' %}{% endblock %}") + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_localized_test_snippet', :raw_template => "{% block main %}{% include 'my-localized-test-snippet' %}{% endblock %}") end end From 22d55cf0e0920f329fdf5625da447af8d5bbff2b Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Sun, 8 Apr 2012 14:42:19 +0800 Subject: [PATCH 10/65] Slugs should not have 'dot' in them. --- spec/models/locomotive/content_entry_spec.rb | 2 +- spec/models/locomotive/page_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/locomotive/content_entry_spec.rb b/spec/models/locomotive/content_entry_spec.rb index f4a1ced2..08794995 100644 --- a/spec/models/locomotive/content_entry_spec.rb +++ b/spec/models/locomotive/content_entry_spec.rb @@ -146,7 +146,7 @@ describe Locomotive::ContentEntry do it 'removes dots' do @content_entry.title = "my.test"; @content_entry.send(:set_slug) - @content_entry._permalink.should == 'my-dot-test' + @content_entry._permalink.should == 'my-test' end it 'accepts non-latin chars' do diff --git a/spec/models/locomotive/page_spec.rb b/spec/models/locomotive/page_spec.rb index adc442be..ce035261 100644 --- a/spec/models/locomotive/page_spec.rb +++ b/spec/models/locomotive/page_spec.rb @@ -102,11 +102,11 @@ describe Locomotive::Page do it 'should have normalized slug' do page = FactoryGirl.build(:page, :slug => ' Valid ité.html ') page.valid? - page.slug.should == 'valid-ite-dot-html' + page.slug.should == 'valid-ite-html' page = FactoryGirl.build(:page, :title => ' Valid ité.html ', :slug => nil, :site => page.site) page.should be_valid - page.slug.should == 'valid-ite-dot-html' + page.slug.should == 'valid-ite-html' end it 'has no cache strategy' do From f74306503b4720d56556d74b21cb81b83d600552 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Sun, 8 Apr 2012 15:13:07 +0800 Subject: [PATCH 11/65] Use unidecoder for converting non ascii charcters for page slugs. Fixes #340 --- Gemfile.lock | 4 ++-- lib/locomotive/core_ext.rb | 2 +- lib/locomotive/dependencies.rb | 1 + locomotive_cms.gemspec | 3 ++- spec/models/locomotive/content_entry_spec.rb | 2 +- spec/models/locomotive/page_spec.rb | 2 +- spec/models/locomotive/snippet_spec.rb | 8 ++++---- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aa6289dd..06fd266c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,7 @@ PATH responders (~> 0.6.4) rmagick (~> 2.12.2) sanitize (~> 2.0.3) - stringex (~> 1.3.2) + unidecoder (~> 1.1.1) GEM remote: http://rubygems.org/ @@ -298,7 +298,6 @@ GEM hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - stringex (1.3.2) term-ansicolor (1.0.7) thor (0.14.6) tilt (1.3.3) @@ -313,6 +312,7 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) + unidecoder (1.1.1) warden (1.1.1) rack (>= 1.0) xpath (0.1.4) diff --git a/lib/locomotive/core_ext.rb b/lib/locomotive/core_ext.rb index ca911d2b..276eb005 100644 --- a/lib/locomotive/core_ext.rb +++ b/lib/locomotive/core_ext.rb @@ -5,7 +5,7 @@ class String #:nodoc def permalink - self.parameterize('-') + self.to_ascii.parameterize('-') end def permalink! diff --git a/lib/locomotive/dependencies.rb b/lib/locomotive/dependencies.rb index 581d3da3..57c06bfb 100644 --- a/lib/locomotive/dependencies.rb +++ b/lib/locomotive/dependencies.rb @@ -19,6 +19,7 @@ require 'cancan' require 'RMagick' require 'cells' require 'sanitize' +require 'unidecoder' require 'compass' require 'codemirror/rails' diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 5bec1508..674e31d3 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -49,6 +49,7 @@ Gem::Specification.new do |s| s.add_dependency 'RedCloth', '~> 4.2.8' s.add_dependency 'sanitize', '~> 2.0.3' s.add_dependency 'highline', '~> 1.6.2' + s.add_dependency 'unidecoder', '~> 1.1.1' s.add_dependency 'rmagick', '~> 2.12.2' s.add_dependency 'carrierwave-mongoid', '~> 0.1.3' @@ -77,4 +78,4 @@ Gem::Specification.new do |s| 'README.textile' ] -end \ No newline at end of file +end diff --git a/spec/models/locomotive/content_entry_spec.rb b/spec/models/locomotive/content_entry_spec.rb index 08794995..5063e6f4 100644 --- a/spec/models/locomotive/content_entry_spec.rb +++ b/spec/models/locomotive/content_entry_spec.rb @@ -148,7 +148,7 @@ describe Locomotive::ContentEntry do @content_entry.title = "my.test"; @content_entry.send(:set_slug) @content_entry._permalink.should == 'my-test' end - + it 'accepts non-latin chars' do @content_entry.title = "абракадабра"; @content_entry.send(:set_slug) @content_entry._permalink.should == 'abrakadabra' diff --git a/spec/models/locomotive/page_spec.rb b/spec/models/locomotive/page_spec.rb index ce035261..cbcf4ea6 100644 --- a/spec/models/locomotive/page_spec.rb +++ b/spec/models/locomotive/page_spec.rb @@ -235,7 +235,7 @@ describe Locomotive::Page do it 'fills in the slug field' do @page.valid? - @page.slug.should == 'content-type-template' + @page.slug.should == 'content_type_template' end it 'returns the target klass' do diff --git a/spec/models/locomotive/snippet_spec.rb b/spec/models/locomotive/snippet_spec.rb index bfa8cf15..274fee6e 100644 --- a/spec/models/locomotive/snippet_spec.rb +++ b/spec/models/locomotive/snippet_spec.rb @@ -20,13 +20,13 @@ describe Locomotive::Snippet do before :each do @site = FactoryGirl.create(:site, :subdomain => 'omg') - @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my-test-snippet', :template => 'a testing template') + @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my_test_snippet', :template => 'a testing template') end context 'with a normal top level snippet' do before :each do - @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% include 'my-test-snippet' %}") + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% include 'my_test_snippet' %}") end it 'updates templates with the new snippet template' do @@ -39,7 +39,7 @@ describe Locomotive::Snippet do context 'for snippets inside of a block' do before :each do - @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% block main %}{% include 'my-test-snippet' %}{% endblock %}") + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% block main %}{% include 'my_test_snippet' %}{% endblock %}") end it 'updates templates with the new snippet template' do @@ -54,7 +54,7 @@ describe Locomotive::Snippet do before :each do Mongoid::Fields::I18n.with_locale(:fr) do @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my_localized_test_snippet', :template => 'a testing template') - @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_localized_test_snippet', :raw_template => "{% block main %}{% include 'my-localized-test-snippet' %}{% endblock %}") + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_localized_test_snippet', :raw_template => "{% block main %}{% include 'my_localized_test_snippet' %}{% endblock %}") end end From 4bf16b00f98a38667e5470cd56b1a04c1cfed51e Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Tue, 10 Apr 2012 18:06:28 +0800 Subject: [PATCH 12/65] Require the engine on gem load. --- lib/locomotive_cms.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/locomotive_cms.rb diff --git a/lib/locomotive_cms.rb b/lib/locomotive_cms.rb new file mode 100644 index 00000000..df2c2281 --- /dev/null +++ b/lib/locomotive_cms.rb @@ -0,0 +1 @@ +require 'locomotive/engine' From 106cc6fc504f56b5f9a51185dc8af1a9781da9d6 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Wed, 11 Apr 2012 00:26:59 +0200 Subject: [PATCH 13/65] fix issue #346 --- app/models/locomotive/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/locomotive/page.rb b/app/models/locomotive/page.rb index 50dc06e4..35b8cd14 100644 --- a/app/models/locomotive/page.rb +++ b/app/models/locomotive/page.rb @@ -52,7 +52,7 @@ module Locomotive scope :published, :where => { :published => true } scope :fullpath, lambda { |fullpath| { :where => { :fullpath => fullpath } } } scope :handle, lambda { |handle| { :where => { :handle => handle } } } - scope :minimal_attributes, lambda { |attrs = []| { :only => (attrs || []) + %w(title slug fullpath position depth published templatized redirect listed response_type parent_id site_id created_at updated_at) } } + scope :minimal_attributes, lambda { |attrs = []| { :only => (attrs || []) + %w(title slug fullpath position depth published templatized redirect listed response_type parent_id parent_ids site_id created_at updated_at) } } scope :dependent_from, lambda { |id| { :where => { :template_dependencies.in => [id] } } } ## methods ## From cd703970b45e28635edca2efbdf5a77c77b50a49 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Wed, 11 Apr 2012 14:24:41 -0500 Subject: [PATCH 14/65] Added new buttons and styling --- .../images/locomotive/list/icons/toggle.png | Bin 347 -> 1340 bytes .../locomotive/list/icons/toggle_off.png | Bin 346 -> 1285 bytes .../custom_field_entry_view.js.coffee | 2 ++ .../backoffice/formtastic_changes.css.scss | 4 ++++ 4 files changed, 6 insertions(+) diff --git a/app/assets/images/locomotive/list/icons/toggle.png b/app/assets/images/locomotive/list/icons/toggle.png index 0fbbfeea3ec8c0f7dd130077270f3a4ffaadc904..130a62ce4ee92577dd23f6582dcb74ed31d622a1 100644 GIT binary patch literal 1340 zcmbVMeP|nH7{9Jvn|>~1+O3_PZ?Cl*+T`B5Bu#TPHXoNP8BL98WSRfCOYTi`ZSTX& zbxDItnzb^au#OFxOb`^LpcE1OXI9*_NTq_hKNM7?gdzjc$?yYpcD~m()j!Gv4~~1E z=bqp5@q3=`T5h|u+XLl68eae)^ogu2(O?d z5eQ5CD2gFon0oqSG(Zs588M#F6Okb{rASuZu(9SP6{87aU@))psd1!(BpMZEH+k#b z_emfMZt|of0wby)WyDZHLnDRZc&ad-atY+%qhKJQw+O*Euio_#X3t!7e{Cz+*q0<~%tPyg)m^svJFC~0iE2-a$xsDM z=3BMp^Xhw1*zxA*EWr+$F=M54a=CgbA*zL{%SHtS&e7eo<<=NtAoQ#@+)nZJ=g(w3xUs-LF1)F5(#$ zrpKOZd8eZul6wz#70eI&ehHPDLcuTRS}&=^OD+7jk@PfM_lEDXH`D(3(w@e%;#-G~ zRt?padlM&CNgWc5oVp!| zbr}c)U8q_iWCL1&SP@+%m+>Aj#sU5>|=r^(^>d5 z;0P0to_CDUydVlqVRA(J9pr68kO8oS^cslWfcP>InlD4uzC+IoH-Xp$h+A>Q%wMRS r2~;fuEG6R0&Z0;z#G0J}0t^)ZJ(fkIb(DWk00000NkvXXu0mjf#PEN3 diff --git a/app/assets/images/locomotive/list/icons/toggle_off.png b/app/assets/images/locomotive/list/icons/toggle_off.png index 11bdcd4b53e089de5bd6cbcd7aa1a9779ea42e06..749f40144b4bd8eafb83e587c9e86c6bbe23b615 100644 GIT binary patch literal 1285 zcmaJ>ZA=?w9KX`8?Z~PZ*_OEv`gkyvNPBmsrS?XlFIUzoB?P*xei5#B5A=Y0+1;@g zzDQv*784=FWXlp0&HO+Rwoe*gKB(Cek+>`-=$vj@L^HR=1kG5=5)*umQRWBhC6{~t z|NMTx|Lb$7J3EfJst;CU80JbQ*e>+N&DUwiFiURzY6%%n8}W?Mt@IgrPJ>uPP_hst zC9WTKK~5Ms{tax#Fl(Kd&KQ|gJHsoIhchvrf}|oghBdbqRE{5n2FSvGQ4SGnpMOCB zQ3w&o{3$A>#$ZlNjB2oZv?I-r4)Q^PXl((_1qKO7(BMEp8j^LU5F)m88FV(?BmuS{ z#$bqelvF0w31W%{f!{;9d8&y9O+F9pqk_I*1MpHbMbci93b<*C@dp@+2HOvTqG>`O z)5W%J$3j+!$Qg#pkYqle_v9Nriq=ok!C;W2yrkFbMhLe)A{$)6E$g*q1s3YOCaQ+0 z$iP(OvdXX#B2cD}N|4kYSy|t16KWV);8c?KP-aPGU@GqZxRobP`M>*)~{ zl3h?&hBY1yuCLY%r7|%Ma)zR%6=kU0#m<~!D0)s&L9E;Fp+Sn{McMRhF;XceDeDF& z^DxPV2&CZ=MS*Ff8~wg$Bp8T!S(=X1k+?SyjkmGUU?Us#$Gl}OtMJ1Tl#Mc1c+8Dd zB_$R$xSq&eDujk@eY`(qw=78e;i zs}E(g?;2X{`NO}wg6>v6$wtzJpRz-e1hH|S9h|?@ieomsHhr?VYie`i0A{h(SoHAN zX^RWF+v84r&AvL_u(Vw4WiqcGJ-V+Q)YSbsx47tf9_+!xRO3oI<$1_j~Hj|6I&Ga~X3|zp0p|30$zQR?mI3gb85> z9qL_<=jlH+=hNT&0vF!~(2A!0Q&= z!P_kKjrANHzz)oee;qi3BlrwSPb-MQ0~CVT;atHrvDtvE-az8~j)ZFiy}^G8L}q24 z=RHD1tmzw2r>!KGzO^7tKn*fJyh(wOBTeQ@*2}VVEF<#xdj5@$95fbo$DB3fpfX)Z zTM%-jsXTtB*D1lsnUJP+c@{!`VN1)s)3#UCV0cI`umQD&xaQi{oP{Syff~7)j{l`x qD^4R#*&bYYoI}l_IL==I1^^UZl|be}Wta{C0000# diff --git a/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee b/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee index d10a06fe..647abf87 100644 --- a/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee @@ -78,8 +78,10 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View form = @$('ol') if form.is(':hidden') + @$('this').addClass('open') form.slideDown() else + @$('this').removeClass('open') form.slideUp() show_error: (message) -> diff --git a/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss b/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss index 4841dc0a..00bd24a9 100644 --- a/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss @@ -157,6 +157,10 @@ form.formtastic { &:hover { background-image: image-url("locomotive/list/icons/toggle.png"); } + &.open { + @include rotate(180); + } + @include single-transition(transform, 0.5s); } &.drag { From 560afc6b0a1b5743e91d8f09c90cbc01d02be542 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Wed, 11 Apr 2012 15:35:23 -0500 Subject: [PATCH 15/65] Fixed my css and javascript problems --- .../views/content_types/custom_field_entry_view.js.coffee | 4 ++-- .../locomotive/backoffice/formtastic_changes.css.scss | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee b/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee index 647abf87..07f707ad 100644 --- a/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee @@ -78,10 +78,10 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View form = @$('ol') if form.is(':hidden') - @$('this').addClass('open') + @$('a.toggle').addClass('open') form.slideDown() else - @$('this').removeClass('open') + @$('a.toggle').removeClass('open') form.slideUp() show_error: (message) -> diff --git a/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss b/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss index 00bd24a9..d6137c39 100644 --- a/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss @@ -158,7 +158,7 @@ form.formtastic { background-image: image-url("locomotive/list/icons/toggle.png"); } &.open { - @include rotate(180); + @include rotate(180deg); } @include single-transition(transform, 0.5s); } From 7a595208aa0672ad55ae224903cd216b23ebd17f Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 13 Apr 2012 14:38:00 +0200 Subject: [PATCH 16/65] fix issue #338 --- app/mailers/locomotive/notifications.rb | 4 ++-- app/models/locomotive/content_entry.rb | 2 +- .../notifications/new_content_entry.html.haml | 17 ++++++++++++----- spec/models/locomotive/content_entry_spec.rb | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/mailers/locomotive/notifications.rb b/app/mailers/locomotive/notifications.rb index b59e1364..88926776 100644 --- a/app/mailers/locomotive/notifications.rb +++ b/app/mailers/locomotive/notifications.rb @@ -3,8 +3,8 @@ module Locomotive default :from => Locomotive.config.mailer_sender - def new_content_entry(account, entry) - @account, @entry, @type = account, entry.to_presenter, entry.content_type + def new_content_entry(entry, account) + @account, @entry, @type = account, entry, entry.content_type subject = t('locomotive.notifications.new_content_entry.subject', :type => @type.name, :locale => account.locale) diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index adb981f6..8273c46f 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -146,7 +146,7 @@ module Locomotive return if !self.content_type.public_submission_enabled? || self.content_type.public_submission_accounts.blank? self.site.accounts.each do |account| - next unless self.content_type.public_submission_accounts.include?(account._id) + next unless self.content_type.public_submission_accounts.map(&:to_s).include?(account._id.to_s) Locomotive::Notifications.new_content_entry(account, self).deliver end diff --git a/app/views/locomotive/notifications/new_content_entry.html.haml b/app/views/locomotive/notifications/new_content_entry.html.haml index 05844631..ea3b670a 100644 --- a/app/views/locomotive/notifications/new_content_entry.html.haml +++ b/app/views/locomotive/notifications/new_content_entry.html.haml @@ -10,13 +10,20 @@ %hr %ul - - @type.entries_custom_fields.each do |field| - - value = @entry.value_for(field) + - @type.ordered_entries_custom_fields.each do |field| + - value = @entry.send(field.name) %li %strong= field.label  -  %i - - if field.type == 'file' - = link_to File.basename(value), value - - else + - case field.type.to_s + - when 'string', 'text', 'boolean', 'date' = value + - when 'file' + = link_to File.basename(value.to_s), value.to_s + - when 'select' + = value + - when 'belongs_to' + = value.try(:_label) + - when 'has_many', 'many_to_many' + = value.map(&:_label).join(', ') \ No newline at end of file diff --git a/spec/models/locomotive/content_entry_spec.rb b/spec/models/locomotive/content_entry_spec.rb index 5063e6f4..c11097c0 100644 --- a/spec/models/locomotive/content_entry_spec.rb +++ b/spec/models/locomotive/content_entry_spec.rb @@ -202,7 +202,7 @@ describe Locomotive::ContentEntry do @account_2 = FactoryGirl.build('frenchy user', :id => fake_bson_id('2')) @content_type.public_submission_enabled = true - @content_type.public_submission_accounts = ['', @account_1._id, @account_2._id] + @content_type.public_submission_accounts = ['', @account_1._id, @account_2._id.to_s] site = FactoryGirl.build(:site) site.stubs(:accounts).returns([@account_1, @account_2]) From 56a0affbcb7c34319ad0ff48b94ff77db2660bbf Mon Sep 17 00:00:00 2001 From: Alex Sanford Date: Tue, 10 Apr 2012 21:29:54 -0300 Subject: [PATCH 17/65] Changed iframe resize function Instead of resizing the iframe based on the height of the body element of the iframe content, do it based on the entire content height. Also, don't compare the inner content height to the body height of the outer page, but use the iframe height instead. --- .../locomotive/views/inline_editor/application_view.js.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee b/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee index 9ed71b53..2f242986 100644 --- a/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee @@ -30,11 +30,11 @@ class Locomotive.Views.InlinEditor.ApplicationView extends Backbone.View if @_$('meta[name=inline-editor]').size() > 0 # bind the resize event. When the iFrame's size changes, update its height - iframe_content = iframe.contents().find('body') + iframe_content = iframe.contents() iframe_content.resize -> elem = $(this) - if elem.outerHeight(true) > $('body').outerHeight(true) # Resize the iFrame. + if elem.outerHeight(true) > iframe.outerHeight(true) # Resize the iFrame. iframe.css height: elem.outerHeight(true) # Resize the iFrame immediately. From d0698b1ffc74fc31bd935c48f81fa35d88183085 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 13 Apr 2012 15:29:06 +0200 Subject: [PATCH 18/65] fix issue #348 --- Gemfile.lock | 31 +++++++++++++++++-------------- locomotive_cms.gemspec | 4 ++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 06fd266c..30ca762b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,9 +48,9 @@ PATH httparty (~> 0.8.1) jquery-rails (~> 1.0.16) kaminari (~> 0.13.0) - locomotive-aloha-rails (~> 0.20.1.1) + locomotive-aloha-rails (~> 0.20.1.2) locomotive-mongoid-tree (~> 0.6.2) - locomotive-tinymce-rails (~> 3.4.7.1) + locomotive-tinymce-rails (~> 3.4.7.2) locomotive_liquid (= 2.2.2) mimetype-fu (~> 0.1.2) mongo (~> 1.5.2) @@ -112,7 +112,7 @@ GEM rack-test (>= 0.5.4) selenium-webdriver (~> 2.0) xpath (~> 0.1.4) - carrierwave (0.6.0) + carrierwave (0.6.2) activemodel (>= 3.2.0) activesupport (>= 3.2.0) carrierwave-mongoid (0.1.3) @@ -132,7 +132,7 @@ GEM coffee-script (2.2.0) coffee-script-source execjs - coffee-script-source (1.2.0) + coffee-script-source (1.3.1) cucumber (1.1.9) builder (>= 2.1.2) diff-lcs (>= 1.1.2) @@ -149,7 +149,7 @@ GEM orm_adapter (~> 0.0.3) warden (~> 1.1) diff-lcs (1.1.3) - dragonfly (0.9.11) + dragonfly (0.9.12) rack ejs (1.0.0) erubis (2.7.0) @@ -177,13 +177,13 @@ GEM formatador (0.2.1) formtastic (2.0.2) rails (~> 3.0) - fssm (0.2.8.1) + fssm (0.2.9) gherkin (2.9.3) json (>= 1.4.6) haml (3.1.4) highline (1.6.11) hike (1.2.1) - httparty (0.8.1) + httparty (0.8.2) multi_json multi_xml i18n (0.6.0) @@ -199,12 +199,14 @@ GEM kgio (2.7.4) launchy (2.1.0) addressable (~> 2.2.6) - locomotive-aloha-rails (0.20.1.1) + libwebsocket (0.1.3) + addressable + locomotive-aloha-rails (0.20.1.2) actionpack (~> 3.2.1) locomotive-mongoid-tree (0.6.2) mongoid (~> 2.0) - locomotive-tinymce-rails (3.4.7.1) - actionpack (~> 3.2.1) + locomotive-tinymce-rails (3.4.7.2) + actionpack (~> 3.0) locomotive_liquid (2.2.2) mail (2.4.4) i18n (>= 0.4.0) @@ -215,7 +217,7 @@ GEM mocha (0.9.12) mongo (1.5.2) bson (= 1.5.2) - mongoid (2.4.7) + mongoid (2.4.8) activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) @@ -280,7 +282,7 @@ GEM railties (>= 3.0) rspec (~> 2.8.0) ruby-hmac (0.4.0) - rubyzip (0.9.6.1) + rubyzip (0.9.7) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) sass (3.1.15) @@ -288,9 +290,10 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.20.0) + selenium-webdriver (2.21.0) childprocess (>= 0.2.5) ffi (~> 1.0) + libwebsocket (~> 0.1.3) multi_json (~> 1.0) rubyzip shoulda-matchers (1.0.0) @@ -304,7 +307,7 @@ GEM treetop (1.4.10) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.32) + tzinfo (0.3.33) uglifier (1.2.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 674e31d3..d6af690e 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -38,8 +38,8 @@ Gem::Specification.new do |s| s.add_dependency 'jquery-rails', '~> 1.0.16' s.add_dependency 'rails-backbone', '~> 0.6.1' s.add_dependency 'codemirror-rails', '~> 2.21' - s.add_dependency 'locomotive-tinymce-rails', '~> 3.4.7.1' - s.add_dependency 'locomotive-aloha-rails', '~> 0.20.1.1' + s.add_dependency 'locomotive-tinymce-rails', '~> 3.4.7.2' + s.add_dependency 'locomotive-aloha-rails', '~> 0.20.1.2' s.add_dependency 'flash_cookie_session', '~> 1.1.1' s.add_dependency 'locomotive_liquid', '2.2.2' From edca6323fb03980ffaf857204dd1af661cc1a7b0 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 13 Apr 2012 22:11:44 +0800 Subject: [PATCH 19/65] Fixed a regression when updating javascript stringify. Fixes #355. --- app/assets/javascripts/locomotive/utils/core_ext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/locomotive/utils/core_ext.js b/app/assets/javascripts/locomotive/utils/core_ext.js index c3e112cd..61d3501c 100644 --- a/app/assets/javascripts/locomotive/utils/core_ext.js +++ b/app/assets/javascripts/locomotive/utils/core_ext.js @@ -18,7 +18,7 @@ String.prototype.slugify = function(sep) { if (typeof sep == 'undefined') sep = '_'; - var alphaNumRegexp = new RegExp('[^\w\\' + sep + ']', 'g'); + var alphaNumRegexp = new RegExp('[^\\w\\' + sep + ']', 'g'); var avoidDuplicateRegexp = new RegExp('[\\' + sep + ']{2,}', 'g'); return this.replace(/\s/g, sep).replace(alphaNumRegexp, '').replace(avoidDuplicateRegexp, sep).toLowerCase() } From a507d756b730f4597d24627151f8dd3d233024d1 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 13 Apr 2012 18:08:53 +0200 Subject: [PATCH 20/65] repair the js slugify method --- app/assets/javascripts/locomotive/utils/core_ext.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/locomotive/utils/core_ext.js b/app/assets/javascripts/locomotive/utils/core_ext.js index c3e112cd..bededa0c 100644 --- a/app/assets/javascripts/locomotive/utils/core_ext.js +++ b/app/assets/javascripts/locomotive/utils/core_ext.js @@ -18,9 +18,9 @@ String.prototype.slugify = function(sep) { if (typeof sep == 'undefined') sep = '_'; - var alphaNumRegexp = new RegExp('[^\w\\' + sep + ']', 'g'); + var alphaNumRegexp = new RegExp('[^\\w\\' + sep + ']', 'g'); var avoidDuplicateRegexp = new RegExp('[\\' + sep + ']{2,}', 'g'); - return this.replace(/\s/g, sep).replace(alphaNumRegexp, '').replace(avoidDuplicateRegexp, sep).toLowerCase() + return this.replace(/\s/g, sep).replace(alphaNumRegexp, '').replace(avoidDuplicateRegexp, sep).toLowerCase(); } window.addParameterToURL = function(key, value, context) { // code from http://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript From 06fa564f3798d08fa6f59dcabd839392ce2eb82a Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 13 Apr 2012 18:32:55 +0200 Subject: [PATCH 21/65] fix a couple of potential bugs when playing with the site locales --- .../locomotive/extensions/site/locales.rb | 33 +++++++++++++- config/locales/default.en.yml | 2 + config/locales/default.fr.yml | 2 + spec/models/locomotive/site_spec.rb | 43 +++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/app/models/locomotive/extensions/site/locales.rb b/app/models/locomotive/extensions/site/locales.rb index df1a5cf6..206132a8 100644 --- a/app/models/locomotive/extensions/site/locales.rb +++ b/app/models/locomotive/extensions/site/locales.rb @@ -10,8 +10,12 @@ module Locomotive ## fields ## field :locales, :type => 'RawArray', :default => [] + ## validations ## + validate :can_not_remove_default_locale + ## callbacks ## - after_validation :add_default_locale + after_validation :add_default_locale + before_update :verify_localized_default_pages_integrity end @@ -48,6 +52,10 @@ module Locomotive self.locales.first || Locomotive.config.site_locales.first end + def default_locale_was + self.locales_was.first || Locomotive.config.site_locales.first + end + def locale_fallbacks(locale) [locale.to_s] + (locales - [locale.to_s]) end @@ -58,6 +66,29 @@ module Locomotive self.locales = [Locomotive.config.site_locales.first] if self.locales.blank? end + def can_not_remove_default_locale + if self.persisted? && !self.locales.include?(self.default_locale_was) + self.errors.add :locales, I18n.t(:default_locale_removed, :scope => [:errors, :messages, :site]) + end + end + + def verify_localized_default_pages_integrity + if self.persisted? && self.locales_changed? + self.pages.where(:"slug.#{self.default_locale_was}".in => %w(index 404), :depth => 0).each do |page| + modifications = { 'title' => {}, 'slug' => {} } + + self.locales.each do |locale| + slug = page.attributes['slug'][self.default_locale_was] + + modifications['slug'][locale] = slug + modifications['title'][locale] = page.attributes['title'][locale] || ::I18n.t("attributes.defaults.pages.#{slug}.title", :locale => locale) + end + + page.collection.update({ :_id => page._id }, { '$set' => modifications }) + end + end + end + end end diff --git a/config/locales/default.en.yml b/config/locales/default.en.yml index 016cadf0..18ecdaa1 100644 --- a/config/locales/default.en.yml +++ b/config/locales/default.en.yml @@ -12,6 +12,8 @@ en: extname_changed: "New file does not have the original extension" array_too_short: "is too small (minimum element number is %{count})" invalid_theme_file: "can't be blank or isn't a zip file" + site: + default_locale_removed: The previous default locale can not be removed right away. page: liquid_syntax: "Liquid Syntax error ('%{error}' on '%{fullpath}')" liquid_extend: "The page '%{fullpath}' extends a template which does not exist" diff --git a/config/locales/default.fr.yml b/config/locales/default.fr.yml index 45d043ae..d3a9b332 100644 --- a/config/locales/default.fr.yml +++ b/config/locales/default.fr.yml @@ -33,6 +33,8 @@ fr: extname_changed: "Nouveau fichier n'a pas l'extension original" array_too_short: "est trop petit (le nombre minimum d'éléments est %{count})" security: "présente un problème de sécurité" + site: + default_locale_removed: La langue par défaut ne peut pas être supprimée de cette façon. page: liquid_syntax: "Erreur de syntaxe dans les sections de page, veuillez vérifier la syntaxe ('%{error}'/'%{fullpath}')" liquid_extend: "La page '%{fullpath}' étend le contenu d'une page qui n'existe pas" diff --git a/spec/models/locomotive/site_spec.rb b/spec/models/locomotive/site_spec.rb index 3d8ce016..a3c9722c 100644 --- a/spec/models/locomotive/site_spec.rb +++ b/spec/models/locomotive/site_spec.rb @@ -1,3 +1,5 @@ +# coding: utf-8 + require 'spec_helper' describe Locomotive::Site do @@ -114,6 +116,47 @@ describe Locomotive::Site do @site.pages.map(&:fullpath).sort.should == %w{404 index} end + it 'translates the index/404 pages if a new locale is added' do + @site.update_attributes :locales => %w(en fr) + + @site.errors.should be_empty + + ::Mongoid::Fields::I18n.with_locale('fr') do + @site.pages.root.first.tap do |page| + page.title.should == "Page d'accueil" + page.slug.should == 'index' + end + + @site.pages.not_found.first.tap do |page| + page.title.should == 'Page non trouvée' + page.slug.should == '404' + end + end + end + + it 'translates the index/404 pages if the default locale changes' do + @site.update_attributes :locales => %w(fr en) + + @site.errors.should be_empty + + ::Mongoid::Fields::I18n.with_locale('fr') do + @site.pages.root.first.tap do |page| + page.title.should == "Page d'accueil" + page.slug.should == 'index' + end + + @site.pages.not_found.first.tap do |page| + page.title.should == 'Page non trouvée' + page.slug.should == '404' + end + end + end + + it 'does not allow to remove the default locale' do + @site.update_attributes :locales => %w(fr) + @site.errors[:locales].should == ['The previous default locale can not be removed right away.'] + end + end describe 'deleting in cascade' do From 21469ce36782d13dc9a0cab248b96551bdbce446 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sat, 14 Apr 2012 11:55:24 +0200 Subject: [PATCH 22/65] do not display the content types select box if a page is not templatized --- .../javascripts/locomotive/views/pages/_form_view.js.coffee | 2 +- app/views/locomotive/pages/_form.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee b/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee index 3531ef1d..06fc4af1 100644 --- a/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee @@ -116,7 +116,7 @@ class Locomotive.Views.Pages.FormView extends Locomotive.Views.Shared.FormView @$('li#page_slug_input').show() @$('li#page_templatized_input, li#page_target_klass_name_input').hide() else - @$('li#page_templatized_input, li#page_target_klass_name_input').show() + @$('li#page_templatized_input').show() unless @model.get('redirect') enable_response_type_select: -> @$('li#page_response_type_input').change (event) => diff --git a/app/views/locomotive/pages/_form.html.haml b/app/views/locomotive/pages/_form.html.haml index 9e5290aa..88179ff4 100644 --- a/app/views/locomotive/pages/_form.html.haml +++ b/app/views/locomotive/pages/_form.html.haml @@ -36,7 +36,7 @@ = f.input :templatized, :as => :'Locomotive::Toggle', :style => "#{'display: none' if @page.redirect? || @page.templatized_from_parent?}" - = f.input :target_klass_name, :as => :select, :collection => options_for_target_klass_name, :include_blank => false, :wrapper_html => { :style => "#{'display: none' unless @page.templatized? && !@page.templatized_from_parent?}" } + = f.input :target_klass_name, :as => :select, :collection => options_for_target_klass_name, :include_blank => false, :wrapper_html => { :style => "#{'display: none' if !@page.templatized? || @page.templatized_from_parent?}" } = f.input :published, :as => :'Locomotive::Toggle' From 1ae9557515acfa07ba6686aff9ec04a2b2752920 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sat, 14 Apr 2012 13:38:47 +0200 Subject: [PATCH 23/65] back to the original editable_short_text (#349) --- .../locomotive/models/page.js.coffee | 2 +- .../long_text_view.js.coffee | 32 +++++++++++++++++-- .../short_text_view.js.coffee | 26 ++++----------- .../backoffice/formtastic_changes.css.scss | 11 +++++++ 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/locomotive/models/page.js.coffee b/app/assets/javascripts/locomotive/models/page.js.coffee index 4ff2cde1..dd68be3d 100644 --- a/app/assets/javascripts/locomotive/models/page.js.coffee +++ b/app/assets/javascripts/locomotive/models/page.js.coffee @@ -16,7 +16,7 @@ class Locomotive.Models.Page extends Backbone.Model toJSON: -> _.tap super, (hash) => - _.each ['content_type_id_text', 'edit_url', 'parent_id_text', 'response_type_text'], (key) => delete hash[key] + _.each ['fullpath', 'localized_fullpaths', 'templatized_from_parent', 'target_klass_name_text', 'content_type_id_text', 'edit_url', 'parent_id_text', 'response_type_text'], (key) => delete hash[key] delete hash['editable_elements'] hash.editable_elements = @get('editable_elements').toJSONForSave() if @get('editable_elements')? && @get('editable_elements').length > 0 diff --git a/app/assets/javascripts/locomotive/views/editable_elements/long_text_view.js.coffee b/app/assets/javascripts/locomotive/views/editable_elements/long_text_view.js.coffee index 5c0e9925..86147c12 100644 --- a/app/assets/javascripts/locomotive/views/editable_elements/long_text_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/editable_elements/long_text_view.js.coffee @@ -2,7 +2,35 @@ Locomotive.Views.EditableElements ||= {} -class Locomotive.Views.EditableElements.LongTextView extends Locomotive.Views.EditableElements.ShortTextView +class Locomotive.Views.EditableElements.LongTextView extends Backbone.View + + tagName: 'li' + + className: 'text input html' + + render: -> + $(@el).html(ich.editable_text_input(@model.toJSON())) + + return @ + + after_render: -> + settings = _.extend {}, @tinymce_settings(), + oninit: ((editor) => + $.cmd 'S', (() => + @model.set(content: editor.getBody().innerHTML) + $(@el).parents('form').trigger('submit') + ), [], ignoreCase: true, document: editor.dom.doc), + onchange_callback: (editor) => + @model.set(content: editor.getBody().innerHTML) + + @$('textarea').tinymce(settings) tinymce_settings: -> - window.Locomotive.tinyMCE.defaultSettings \ No newline at end of file + window.Locomotive.tinyMCE.defaultSettings + + refresh: -> + # do nothing + + remove: -> + @$('textarea').tinymce().destroy() + super diff --git a/app/assets/javascripts/locomotive/views/editable_elements/short_text_view.js.coffee b/app/assets/javascripts/locomotive/views/editable_elements/short_text_view.js.coffee index 4c5a5eed..09649c82 100644 --- a/app/assets/javascripts/locomotive/views/editable_elements/short_text_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/editable_elements/short_text_view.js.coffee @@ -4,31 +4,19 @@ class Locomotive.Views.EditableElements.ShortTextView extends Backbone.View tagName: 'li' - className: 'text input html' + className: 'text input short' render: -> $(@el).html(ich.editable_text_input(@model.toJSON())) + @$('textarea').bind 'keyup', (event) => + input = $(event.target) + @model.set(content: input.val()) + return @ after_render: -> - settings = _.extend {}, @tinymce_settings(), - oninit: ((editor) => - $.cmd 'S', (() => - @model.set(content: editor.getBody().innerHTML) - $(@el).parents('form').trigger('submit') - ), [], ignoreCase: true, document: editor.dom.doc), - onchange_callback: (editor) => - @model.set(content: editor.getBody().innerHTML) - - @$('textarea').tinymce(settings) - - tinymce_settings: -> - window.Locomotive.tinyMCE.minimalSettings - - refresh: -> # do nothing - remove: -> - @$('textarea').tinymce().destroy() - super \ No newline at end of file + refresh: -> + # do nothing \ No newline at end of file diff --git a/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss b/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss index d6137c39..c256b071 100644 --- a/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss @@ -295,6 +295,17 @@ form.formtastic { } } // li.string, li.password + &.text { + + &.short textarea { + padding: 5px; + height: 28px; + width: 696px; + overflow-y: hidden; + } + + } // li.text + &.locale, &.locales { .list { margin-left: 150px; From f973ccef1b1419840db4aab8cdd062d0992471a4 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sat, 14 Apr 2012 17:35:11 +0200 Subject: [PATCH 24/65] preserve whitespace in textarea tags (HAML/Rails bug) --- config/initializers/haml.rb | 3 ++- lib/locomotive.rb | 1 + lib/locomotive/haml.rb | 34 ++++++++++++++++++++++++++ spec/dummy/config/initializers/haml.rb | 3 ++- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/locomotive/haml.rb diff --git a/config/initializers/haml.rb b/config/initializers/haml.rb index 31febf8b..c1a2c3ee 100644 --- a/config/initializers/haml.rb +++ b/config/initializers/haml.rb @@ -1 +1,2 @@ -# Haml::Template.options[:ugly] = true # improve performance in dev \ No newline at end of file +Haml::Template.options[:format] = :html5 +Haml::Template.options[:ugly] = true # improve performance in dev \ No newline at end of file diff --git a/lib/locomotive.rb b/lib/locomotive.rb index 02a6c73d..e15c1310 100644 --- a/lib/locomotive.rb +++ b/lib/locomotive.rb @@ -2,6 +2,7 @@ require 'locomotive/version' require 'locomotive/core_ext' require 'locomotive/configuration' require 'locomotive/logger' +require 'locomotive/haml' require 'locomotive/formtastic' require 'locomotive/dragonfly' require 'locomotive/kaminari' diff --git a/lib/locomotive/haml.rb b/lib/locomotive/haml.rb new file mode 100644 index 00000000..8071853e --- /dev/null +++ b/lib/locomotive/haml.rb @@ -0,0 +1,34 @@ +require 'haml/helpers/action_view_mods' + +module ActionView + module Helpers + module TagHelper + + # Only preserve whitespace in the tag's content: https://github.com/nex3/haml/pull/503 + def content_tag_with_haml_and_preserve(name, content_or_options_with_block = nil, *args, &block) + Rails.logger.debug("[content_tag_with_haml_and_preserve / ENGINE] #{name} / #{respond_to?(:content_tag_with_haml)} / #{respond_to?(:content_tag_without_haml)}") + + return content_tag_without_haml(name, content_or_options_with_block, *args, &block) unless is_haml? + + preserve = haml_buffer.options[:preserve].include?(name.to_s) + + if block_given? + if block_is_haml?(block) && preserve + content_tag_without_haml(name, content_or_options_with_block, *args) {preserve(&block)} + else + content_tag_without_haml(name, content_or_options_with_block, *args, &block) + end + else + if preserve && content_or_options_with_block + content_or_options_with_block = Haml::Helpers.preserve(content_or_options_with_block) + end + content_tag_without_haml(name, content_or_options_with_block, *args, &block) + end + end + + alias_method :content_tag_without_haml_and_preserve, :content_tag + alias_method :content_tag, :content_tag_with_haml_and_preserve + alias_method :content_tag_with_haml, :content_tag_with_haml_and_preserve + end + end +end \ No newline at end of file diff --git a/spec/dummy/config/initializers/haml.rb b/spec/dummy/config/initializers/haml.rb index df0b4de4..c1a2c3ee 100644 --- a/spec/dummy/config/initializers/haml.rb +++ b/spec/dummy/config/initializers/haml.rb @@ -1 +1,2 @@ -Haml::Template.options[:ugly] = true # improve performance in dev \ No newline at end of file +Haml::Template.options[:format] = :html5 +Haml::Template.options[:ugly] = true # improve performance in dev \ No newline at end of file From 655fe18d72a50f354f182cda14c47eb72fd24e17 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 16 Apr 2012 11:38:32 +0200 Subject: [PATCH 25/65] add UI notifications when a form is submitted + disable the form when it is being submitted + pass the current ability to the presenter + remove debug statements --- .../views/content_types/edit_view.coffee | 1 - .../inline_editor/application_view.js.coffee | 4 -- .../inline_editor/toolbar_view.js.coffee | 6 --- .../views/pages/edit_view.js.coffee | 9 +++-- .../views/shared/form_view.js.coffee | 14 ++++++- .../views/theme_assets/index_view.js.coffee | 14 +++++-- .../backoffice/application.css.scss | 23 +++++++++++ .../locomotive/backoffice/layout.css.scss | 2 +- .../locomotive/shared/_form_actions.html.haml | 2 +- .../locomotive/theme_assets/index.html.haml | 2 +- config/locales/admin_ui.de.yml | 1 + config/locales/admin_ui.en.yml | 3 ++ config/locales/admin_ui.es.yml | 1 + config/locales/admin_ui.fr.yml | 2 + config/locales/admin_ui.it.yml | 1 + config/locales/admin_ui.nl.yml | 1 + config/locales/admin_ui.no.yml | 1 + config/locales/admin_ui.pt-BR.yml | 1 + config/locales/admin_ui.ru.yml | 1 + doc/TODO | 4 +- lib/locomotive/action_controller/responder.rb | 8 ++++ lib/locomotive/haml.rb | 2 - .../locomotive/form_submit_notification.js | 39 +++++++++++++++++++ 23 files changed, 117 insertions(+), 25 deletions(-) create mode 100644 vendor/assets/javascripts/locomotive/form_submit_notification.js diff --git a/app/assets/javascripts/locomotive/views/content_types/edit_view.coffee b/app/assets/javascripts/locomotive/views/content_types/edit_view.coffee index 4ea76c59..293f9a61 100644 --- a/app/assets/javascripts/locomotive/views/content_types/edit_view.coffee +++ b/app/assets/javascripts/locomotive/views/content_types/edit_view.coffee @@ -11,5 +11,4 @@ class Locomotive.Views.ContentTypes.EditView extends Locomotive.Views.ContentTyp if custom_field.isNew() # assign an id for each new custom field custom_field.set id: data._id, _id: data._id - console.log(custom_field) diff --git a/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee b/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee index 9ed71b53..175d3d96 100644 --- a/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee @@ -26,8 +26,6 @@ class Locomotive.Views.InlinEditor.ApplicationView extends Backbone.View iframe = @iframe iframe.load => - console.log('iframe loading') - if @_$('meta[name=inline-editor]').size() > 0 # bind the resize event. When the iFrame's size changes, update its height iframe_content = iframe.contents().find('body') @@ -46,8 +44,6 @@ class Locomotive.Views.InlinEditor.ApplicationView extends Backbone.View @enhance_iframe_links() set_page: (attributes) -> - console.log('set_page') - @page = new Locomotive.Models.Page(attributes) @toolbar_view.model = @page diff --git a/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee b/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee index f156e552..68d9e6c2 100644 --- a/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee @@ -13,8 +13,6 @@ class Locomotive.Views.InlinEditor.ToolbarView extends Backbone.View render: -> super - console.log('render toolbar') - @enable_editing_mode_checkbox() @enable_content_locale_picker() @@ -22,8 +20,6 @@ class Locomotive.Views.InlinEditor.ToolbarView extends Backbone.View @ notify: (aloha_editable) -> - console.log('editable_element has been modified...') - window.bar = aloha_editable element_id = aloha_editable.obj.attr('data-element-id') @@ -125,8 +121,6 @@ class Locomotive.Views.InlinEditor.ToolbarView extends Backbone.View context.find('span.text').html(values[1]) refresh: -> - console.log('refreshing toolbar...') - @$('h1').html(@model.get('title')).removeClass() if @$('.editing-mode input[type=checkbox]').is(':checked') diff --git a/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee b/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee index 78871d00..46d74629 100644 --- a/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee @@ -5,10 +5,14 @@ class Locomotive.Views.Pages.EditView extends Locomotive.Views.Pages.FormView save: (event) -> event.stopPropagation() & event.preventDefault() + form = $(event.target).trigger('ajax:beforeSend') + @clear_errors() @model.save {}, success: (model, response, xhr) => + form.trigger('ajax:complete') + model._normalize() if model.get('template_changed') == true @@ -17,9 +21,8 @@ class Locomotive.Views.Pages.EditView extends Locomotive.Views.Pages.FormView @refresh_editable_elements() error: (model, xhr) => + form.trigger('ajax:complete') + errors = JSON.parse(xhr.responseText) @show_errors errors - - - diff --git a/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee b/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee index aa4e0017..0034de82 100644 --- a/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee @@ -16,6 +16,9 @@ class Locomotive.Views.Shared.FormView extends Backbone.View # allow users to save with CTRL+S or CMD+s @enable_save_with_keys_combination() + # enable form notifications + @enable_form_notifications() + return @ save: (event) -> @@ -24,6 +27,8 @@ class Locomotive.Views.Shared.FormView extends Backbone.View save_in_ajax: (event, options) -> event.stopPropagation() & event.preventDefault() + form = $(event.target).trigger('ajax:beforeSend') + @clear_errors() options ||= { headers: {}, on_success: null, on_error: null } @@ -33,11 +38,15 @@ class Locomotive.Views.Shared.FormView extends Backbone.View @model.save {}, headers: options.headers success: (model, response, xhr) => + form.trigger('ajax:complete') + model.attributes = previous_attributes options.on_success(response, xhr) if options.on_success error: (model, xhr) => + form.trigger('ajax:complete') + errors = JSON.parse(xhr.responseText) @show_errors errors @@ -72,7 +81,10 @@ class Locomotive.Views.Shared.FormView extends Backbone.View content.slideUp 100, -> parent.addClass('folded') enable_save_with_keys_combination: -> - $.cmd 'S', (() => @$('form').trigger('submit')), [], ignoreCase: true + $.cmd 'S', (() => @$('form input[type=submit]').trigger('click')), [], ignoreCase: true + + enable_form_notifications: -> + @$('form').formSubmitNotification() after_inputs_fold: -> # overide this method if necessary diff --git a/app/assets/javascripts/locomotive/views/theme_assets/index_view.js.coffee b/app/assets/javascripts/locomotive/views/theme_assets/index_view.js.coffee index aca117db..27613fc4 100644 --- a/app/assets/javascripts/locomotive/views/theme_assets/index_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/theme_assets/index_view.js.coffee @@ -7,7 +7,7 @@ class Locomotive.Views.ThemeAssets.IndexView extends Backbone.View _lists_views: [] initialize: -> - _.bindAll(@, 'add_asset') + _.bindAll(@, 'insert_asset') render: -> @build_uploader() @@ -29,16 +29,24 @@ class Locomotive.Views.ThemeAssets.IndexView extends Backbone.View input = form.find('input[type=file]') link = form.find('a.new') + form.formSubmitNotification() + link.bind 'click', (event) -> event.stopPropagation() & event.preventDefault() input.click() input.bind 'change', (event) => + form.trigger('ajax:beforeSend') _.each event.target.files, (file) => asset = new Locomotive.Models.ThemeAsset(source: file) - asset.save {}, success: @add_asset, headers: { 'X-Flash': true } + asset.save {}, + success: (model, response, xhr) => + form.trigger('ajax:complete') + @insert_asset(model) + error: (() => form.trigger('ajax:complete')) + headers: { 'X-Flash': true } - add_asset: (model) -> + insert_asset: (model) -> list_view = @pick_list_view(model.get('content_type')) list_view.collection.add(model) diff --git a/app/assets/stylesheets/locomotive/backoffice/application.css.scss b/app/assets/stylesheets/locomotive/backoffice/application.css.scss index d449f550..4f98f454 100644 --- a/app/assets/stylesheets/locomotive/backoffice/application.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/application.css.scss @@ -314,6 +314,29 @@ ul.list { } } +/* ___ form notification ___ */ + +#form-submit-notification { + position: fixed; + top: 0px; + right: 0px; + z-index: 9999; + + > div { + padding: 5px 10px; + + background-color: #fffbe5; + border-left: 4px solid #efe4a5; + border-bottom: 4px solid #efe4a5; + + text-align: center; + @include single-text-shadow(rgba(255, 255, 255, 1), 0px, 1px, 0px); + font-weight: bold; + font-size: 12px; + color: #aa9a79; + } +} + /* ___ paragraph (for help for example) ___ */ p span.code { diff --git a/app/assets/stylesheets/locomotive/backoffice/layout.css.scss b/app/assets/stylesheets/locomotive/backoffice/layout.css.scss index 4ccbd8d1..c252e73b 100644 --- a/app/assets/stylesheets/locomotive/backoffice/layout.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/layout.css.scss @@ -176,7 +176,7 @@ body { } } - input[type=submit] { + input[type=submit], button[type=submit] { @include light-button; } diff --git a/app/views/locomotive/shared/_form_actions.html.haml b/app/views/locomotive/shared/_form_actions.html.haml index 8532464f..030b70ae 100644 --- a/app/views/locomotive/shared/_form_actions.html.haml +++ b/app/views/locomotive/shared/_form_actions.html.haml @@ -9,6 +9,6 @@ .span-12.last %p - = submit_tag button_label.is_a?(Symbol) ? t(".#{button_label}") : button_label + = submit_tag button_label.is_a?(Symbol) ? t(".#{button_label}") : button_label, :disable_with => t('.disable_with'), :'data-sending-form-message' => t('locomotive.messages.sending_form') .clear \ No newline at end of file diff --git a/app/views/locomotive/theme_assets/index.html.haml b/app/views/locomotive/theme_assets/index.html.haml index d4b11fd6..7c9e92ff 100644 --- a/app/views/locomotive/theme_assets/index.html.haml +++ b/app/views/locomotive/theme_assets/index.html.haml @@ -27,7 +27,7 @@ - content_for :buttons do - if can?(:manage, Locomotive::ThemeAsset) - = form_tag theme_assets_url(:json), :id => 'theme-assets-quick-upload', :class => 'quick-upload' do + = form_tag theme_assets_url(:json), :id => 'theme-assets-quick-upload', :class => 'quick-upload', :'data-sending-form-message' => t('locomotive.messages.sending_form') do = file_field_tag 'theme_asset[source]', :multiple => 'multiple' = local_action_button :quick_upload, '#', :class => 'new' diff --git a/config/locales/admin_ui.de.yml b/config/locales/admin_ui.de.yml index 3b20686c..44726aaf 100644 --- a/config/locales/admin_ui.de.yml +++ b/config/locales/admin_ui.de.yml @@ -48,6 +48,7 @@ de: create: Neu update: Speichern send: Senden + disable_with: "locomotive.disable_with.form_actions" footer: who_is_behind: "Dienst entwickelt von %{development} und entworfen von Sacha Greifversion %{version}" diff --git a/config/locales/admin_ui.en.yml b/config/locales/admin_ui.en.yml index 9bad502f..82e2f862 100644 --- a/config/locales/admin_ui.en.yml +++ b/config/locales/admin_ui.en.yml @@ -22,6 +22,7 @@ en: messages: confirm: Are you sure ? + sending_form: Your form is being submitted shared: header: @@ -48,6 +49,7 @@ en: create: Create update: Save send: Send + disable_with: Pending... list: untranslated: untranslated footer: @@ -193,6 +195,7 @@ en: index: title: Listing theme files help: "The theme files section is the place where you manage the files needed by your layout, snippets...etc. If you need to manage an image gallery, create a new content type instead.
Warning: you may not see all the assets depending on your rights." + quick_upload: Quick upload new: new file snippets: Snippets css_and_js: Style and javascript diff --git a/config/locales/admin_ui.es.yml b/config/locales/admin_ui.es.yml index 1a3d00a9..42ba21d9 100644 --- a/config/locales/admin_ui.es.yml +++ b/config/locales/admin_ui.es.yml @@ -37,6 +37,7 @@ es: account: Mi Cuenta site: Sitio theme_assets: Ficheros del Tema + disable_with: "locomotive.disable_with.form_actions" footer: who_is_behind: "Servicio desarrollado por %{development} y diseñado por Sacha Greif" form_actions: diff --git a/config/locales/admin_ui.fr.yml b/config/locales/admin_ui.fr.yml index d8f31f53..df9bda20 100644 --- a/config/locales/admin_ui.fr.yml +++ b/config/locales/admin_ui.fr.yml @@ -31,6 +31,7 @@ fr: messages: confirm: "Êtes-vous sûr(e) ?" + sending_form: "Votre formulaire est en cours d'envoi" shared: header: @@ -57,6 +58,7 @@ fr: create: Créer update: Mettre à jour send: Envoyer + disable_with: En cours... notifications: new_content_entry: diff --git a/config/locales/admin_ui.it.yml b/config/locales/admin_ui.it.yml index 2ba82a42..37f094b2 100644 --- a/config/locales/admin_ui.it.yml +++ b/config/locales/admin_ui.it.yml @@ -34,6 +34,7 @@ it: create: Crea update: Salva send: Invia + disable_with: "locomotive.disable_with.form_actions" errors: "500": diff --git a/config/locales/admin_ui.nl.yml b/config/locales/admin_ui.nl.yml index 693bc3bb..21c84318 100644 --- a/config/locales/admin_ui.nl.yml +++ b/config/locales/admin_ui.nl.yml @@ -31,6 +31,7 @@ nl: create: Maak update: Update send: Verstuur + disable_with: "locomotive.disable_with.form_actions" errors: "500": diff --git a/config/locales/admin_ui.no.yml b/config/locales/admin_ui.no.yml index a8333e60..46baecb3 100644 --- a/config/locales/admin_ui.no.yml +++ b/config/locales/admin_ui.no.yml @@ -34,6 +34,7 @@ create: Opprett update: Lagre send: Send + disable_with: "locomotive.disable_with.form_actions" errors: "500": diff --git a/config/locales/admin_ui.pt-BR.yml b/config/locales/admin_ui.pt-BR.yml index db05d942..61ac86a4 100644 --- a/config/locales/admin_ui.pt-BR.yml +++ b/config/locales/admin_ui.pt-BR.yml @@ -31,6 +31,7 @@ pt-BR: create: Criar update: Atualizar send: Enviar + disable_with: "locomotive.disable_with.form_actions" errors: "500": diff --git a/config/locales/admin_ui.ru.yml b/config/locales/admin_ui.ru.yml index 951d11cc..c327368b 100644 --- a/config/locales/admin_ui.ru.yml +++ b/config/locales/admin_ui.ru.yml @@ -34,6 +34,7 @@ ru: create: Создать update: Сохранить send: Отправить + disable_with: "locomotive.disable_with.form_actions" errors: "500": diff --git a/doc/TODO b/doc/TODO index 6c11b652..50d53ed6 100644 --- a/doc/TODO +++ b/doc/TODO @@ -124,11 +124,11 @@ x override sort for contents x unable to remove a field x "back to admin" link does not work if inline editor disabled x unable to delete memberships + x disallow to click twice on the submit form button (spinner ?) + x weird behaviour when changing the default locale of a site - editable_elements does not display the first time they get created (and if there are no existing ones) - display by categories does not work when localized - - disallow to click twice on the submit form button (spinner ?) - message to notify people if their browser is too old - - weird behaviour when changing the default locale of a site ? install a site by default at the first installation (without asking) diff --git a/lib/locomotive/action_controller/responder.rb b/lib/locomotive/action_controller/responder.rb index 4afa475f..c516e54b 100644 --- a/lib/locomotive/action_controller/responder.rb +++ b/lib/locomotive/action_controller/responder.rb @@ -9,6 +9,14 @@ module Locomotive super || has_errors? end + def options + super.merge({ + :current_site => self.controller.send(:current_site), + :current_account => self.controller.send(:current_locomotive_account), + :ability => self.controller.send(:current_ability) + }) + end + def to_json if get? display resource diff --git a/lib/locomotive/haml.rb b/lib/locomotive/haml.rb index 8071853e..0d7140da 100644 --- a/lib/locomotive/haml.rb +++ b/lib/locomotive/haml.rb @@ -6,8 +6,6 @@ module ActionView # Only preserve whitespace in the tag's content: https://github.com/nex3/haml/pull/503 def content_tag_with_haml_and_preserve(name, content_or_options_with_block = nil, *args, &block) - Rails.logger.debug("[content_tag_with_haml_and_preserve / ENGINE] #{name} / #{respond_to?(:content_tag_with_haml)} / #{respond_to?(:content_tag_without_haml)}") - return content_tag_without_haml(name, content_or_options_with_block, *args, &block) unless is_haml? preserve = haml_buffer.options[:preserve].include?(name.to_s) diff --git a/vendor/assets/javascripts/locomotive/form_submit_notification.js b/vendor/assets/javascripts/locomotive/form_submit_notification.js new file mode 100644 index 00000000..f39579c0 --- /dev/null +++ b/vendor/assets/javascripts/locomotive/form_submit_notification.js @@ -0,0 +1,39 @@ +/** + * Version 0.0.1 + * Display a message letting the user know the form is being submitted + * Didier Lafforgue + */ +$.fn.formSubmitNotification = function(settings) { + + function show() { + $('#form-submit-notification').fadeIn() + } + + function hide() { + $('#form-submit-notification').fadeOut() + } + + function create(message) { + if ($('#form-submit-notification').size() == 0) { + var element = $("
" + message + "
").hide(); + $('body').append(element); + } + } + + return this.each(function() { + var form = $(this); + var message = form.attr('data-sending-form-message'); + + if (typeof(message) == 'undefined') + message = form.find('input[type=submit]').attr('data-sending-form-message'); + + if (typeof(message) == 'undefined') + return ; + + create(message); + + form.bind('ajax:beforeSend', function(event) { show() }); + form.bind('ajax:complete', function(event) { hide() }); + + }); +} \ No newline at end of file From b25332b2626d9a62eb4fb03f0e7c8f4e5c3dbda7 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 16 Apr 2012 11:49:04 +0200 Subject: [PATCH 26/65] disable the inline editor launch button if the page to display enabled the cache (quick patch for #353) --- lib/locomotive/render.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index c6ad7d9f..3e23d3bc 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -88,7 +88,8 @@ module Locomotive fresh_when :etag => @page, :last_modified => @page.updated_at.utc, :public => true if @page.cache_strategy != 'simple' # varnish - response.cache_control[:max_age] = @page.cache_strategy + response.headers['Editable'] = '' + response.cache_control[:max_age] = @page.cache_strategy end end From 3eb521ba7511d45d5b027e3e138c1e6c43a6acf5 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 16 Apr 2012 12:36:30 +0200 Subject: [PATCH 27/65] upgrade FOG --- Gemfile.lock | 19 ++++++++++--------- locomotive_cms.gemspec | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 30ca762b..70960963 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,7 @@ PATH devise (~> 1.5.3) dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) - fog (~> 1.1.2) + fog (~> 1.3.1) formtastic (~> 2.0.2) haml (~> 3.1.4) highline (~> 1.6.2) @@ -124,7 +124,7 @@ GEM childprocess (0.3.1) ffi (~> 1.0.6) chunky_png (1.2.5) - codemirror-rails (2.22) + codemirror-rails (2.23) railties (~> 3.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -153,7 +153,7 @@ GEM rack ejs (1.0.0) erubis (2.7.0) - excon (0.9.6) + excon (0.13.4) execjs (1.3.0) multi_json (~> 1.0) factory_girl (2.5.2) @@ -164,12 +164,12 @@ GEM ffi (1.0.11) flash_cookie_session (1.1.3) rails (~> 3.0) - fog (1.1.2) + fog (1.3.1) builder - excon (~> 0.9.0) + excon (~> 0.13.0) formatador (~> 0.2.0) mime-types - multi_json (~> 1.0.3) + multi_json (~> 1.0) net-scp (~> 1.0.4) net-ssh (>= 2.1.3) nokogiri (~> 1.5.0) @@ -221,8 +221,8 @@ GEM activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) - multi_json (1.0.4) - multi_xml (0.4.2) + multi_json (1.3.0) + multi_xml (0.4.3) net-scp (1.0.4) net-ssh (>= 1.99.1) net-ssh (2.3.0) @@ -296,7 +296,8 @@ GEM libwebsocket (~> 0.1.3) multi_json (~> 1.0) rubyzip - shoulda-matchers (1.0.0) + shoulda-matchers (1.1.0) + activesupport (>= 3.0.0) sprockets (2.1.2) hike (~> 1.2) rack (~> 1.0) diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index d6af690e..0b6c828e 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -54,7 +54,7 @@ Gem::Specification.new do |s| s.add_dependency 'rmagick', '~> 2.12.2' s.add_dependency 'carrierwave-mongoid', '~> 0.1.3' s.add_dependency 'carrierwave', '~> 0.6.0' - s.add_dependency 'fog', '~> 1.1.2' + s.add_dependency 'fog', '~> 1.3.1' s.add_dependency 'dragonfly', '~> 0.9.8' s.add_dependency 'rack-cache', '~> 1.1' s.add_dependency 'mimetype-fu', '~> 0.1.2' From 26662acae99a15f2b98b3ccfad47481e0a2a66fa Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 16 Apr 2012 20:50:07 +0200 Subject: [PATCH 28/65] force version of the multi_json gem (1.2.0) --- Gemfile.lock | 9 +++++---- locomotive_cms.gemspec | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 70960963..16d2720a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,6 +55,7 @@ PATH mimetype-fu (~> 0.1.2) mongo (~> 1.5.2) mongoid (~> 2.4.6) + multi_json (= 1.2.0) rack-cache (~> 1.1) rails (~> 3.2.3) rails-backbone (~> 0.6.1) @@ -221,8 +222,8 @@ GEM activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) - multi_json (1.3.0) - multi_xml (0.4.3) + multi_json (1.2.0) + multi_xml (0.4.4) net-scp (1.0.4) net-ssh (>= 1.99.1) net-ssh (2.3.0) @@ -290,11 +291,11 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.21.0) + selenium-webdriver (2.21.1) childprocess (>= 0.2.5) ffi (~> 1.0) libwebsocket (~> 0.1.3) - multi_json (~> 1.0) + multi_json (< 1.3) rubyzip shoulda-matchers (1.1.0) activesupport (>= 3.0.0) diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 0b6c828e..9202b52a 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -59,6 +59,7 @@ Gem::Specification.new do |s| s.add_dependency 'rack-cache', '~> 1.1' s.add_dependency 'mimetype-fu', '~> 0.1.2' + s.add_dependency 'multi_json', '1.2.0' s.add_dependency 'httparty', '~> 0.8.1' s.add_dependency 'actionmailer-with-request', '~> 0.3.0' From a74a0045a3df7e05a4625184e517c58a3152bcdf Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Tue, 17 Apr 2012 02:44:19 +0400 Subject: [PATCH 29/65] Wrong arguments order fixed. --- app/models/locomotive/content_entry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index 8273c46f..d42bbb79 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -148,7 +148,7 @@ module Locomotive self.site.accounts.each do |account| next unless self.content_type.public_submission_accounts.map(&:to_s).include?(account._id.to_s) - Locomotive::Notifications.new_content_entry(account, self).deliver + Locomotive::Notifications.new_content_entry(self, account).deliver end end From 60df273e4ba3dc5f4fed19284f93414900840834 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 03:02:31 +0200 Subject: [PATCH 30/65] fix tests for issue #366 --- app/mailers/locomotive/notifications.rb | 2 +- app/models/locomotive/content_entry.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/mailers/locomotive/notifications.rb b/app/mailers/locomotive/notifications.rb index 88926776..c0ebd019 100644 --- a/app/mailers/locomotive/notifications.rb +++ b/app/mailers/locomotive/notifications.rb @@ -3,7 +3,7 @@ module Locomotive default :from => Locomotive.config.mailer_sender - def new_content_entry(entry, account) + def new_content_entry(account, entry) @account, @entry, @type = account, entry, entry.content_type subject = t('locomotive.notifications.new_content_entry.subject', :type => @type.name, :locale => account.locale) diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index d42bbb79..8273c46f 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -148,7 +148,7 @@ module Locomotive self.site.accounts.each do |account| next unless self.content_type.public_submission_accounts.map(&:to_s).include?(account._id.to_s) - Locomotive::Notifications.new_content_entry(self, account).deliver + Locomotive::Notifications.new_content_entry(account, self).deliver end end From bc919ed544a2e617e8f4b9f845ee49a8acdf67ba Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 03:09:17 +0200 Subject: [PATCH 31/65] bump version to 2.0.0.rc5 --- lib/locomotive/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locomotive/version.rb b/lib/locomotive/version.rb index 84625dda..169058b0 100644 --- a/lib/locomotive/version.rb +++ b/lib/locomotive/version.rb @@ -1,3 +1,3 @@ module Locomotive #:nodoc - VERSION = '2.0.0.rc4' + VERSION = '2.0.0.rc5' end From 39bb85d163245487a31f534f7f79efd27058f153 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 03:11:09 +0200 Subject: [PATCH 32/65] forgot to push the Gemfile.lock too --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 16d2720a..8524a42d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,7 +28,7 @@ GIT PATH remote: . specs: - locomotive_cms (2.0.0.rc4) + locomotive_cms (2.0.0.rc5) RedCloth (~> 4.2.8) actionmailer-with-request (~> 0.3.0) bson_ext (~> 1.5.2) From 67c36191d2f456e124eb19d64d161f6d2acea623 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 13:53:15 +0200 Subject: [PATCH 33/65] was breaking the API (tests are coming) --- lib/locomotive/action_controller/responder.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/locomotive/action_controller/responder.rb b/lib/locomotive/action_controller/responder.rb index c516e54b..8fedd51f 100644 --- a/lib/locomotive/action_controller/responder.rb +++ b/lib/locomotive/action_controller/responder.rb @@ -10,10 +10,14 @@ module Locomotive end def options + current_site = self.controller.send(:current_site) + current_account = self.controller.send(:current_locomotive_account) + ability = current_account.nil? ? nil : self.controller.send(:current_ability) + super.merge({ - :current_site => self.controller.send(:current_site), - :current_account => self.controller.send(:current_locomotive_account), - :ability => self.controller.send(:current_ability) + :current_site => current_site, + :current_account => current_account, + :ability => ability }) end From 1d19d606b86927d7c4a11f37d3242dd763398db8 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 16:13:21 +0200 Subject: [PATCH 34/65] closing textarea tags do not break the page form anymore --- Gemfile | 2 ++ Gemfile.lock | 10 +++++++--- features/support/env.rb | 2 ++ lib/locomotive/haml.rb | 4 +++- locomotive_cms.gemspec | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 36cc1b67..5c881251 100755 --- a/Gemfile +++ b/Gemfile @@ -45,5 +45,7 @@ group :test do gem 'xpath', '~> 0.1.4' + gem 'json_spec' + gem 'database_cleaner' end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 8524a42d..da5447f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,7 @@ PATH dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) fog (~> 1.3.1) - formtastic (~> 2.0.2) + formtastic (~> 2.2.0) haml (~> 3.1.4) highline (~> 1.6.2) httparty (~> 0.8.1) @@ -176,8 +176,8 @@ GEM nokogiri (~> 1.5.0) ruby-hmac formatador (0.2.1) - formtastic (2.0.2) - rails (~> 3.0) + formtastic (2.2.0) + actionpack (>= 3.0) fssm (0.2.9) gherkin (2.9.3) json (>= 1.4.6) @@ -193,6 +193,9 @@ GEM railties (~> 3.0) thor (~> 0.14) json (1.6.6) + json_spec (1.0.0) + multi_json (~> 1.0) + rspec (~> 2.0) kaminari (0.13.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -335,6 +338,7 @@ DEPENDENCIES custom_fields! database_cleaner factory_girl_rails (~> 1.6.0) + json_spec launchy locomotive_cms! mocha (= 0.9.12) diff --git a/features/support/env.rb b/features/support/env.rb index cbbdcb91..6439baa0 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -19,6 +19,8 @@ require 'capybara/rails' require 'capybara/cucumber' require 'capybara/session' +require 'json_spec/cucumber' + require 'resolv' require 'uri' diff --git a/lib/locomotive/haml.rb b/lib/locomotive/haml.rb index 0d7140da..b0920c0c 100644 --- a/lib/locomotive/haml.rb +++ b/lib/locomotive/haml.rb @@ -17,7 +17,9 @@ module ActionView content_tag_without_haml(name, content_or_options_with_block, *args, &block) end else - if preserve && content_or_options_with_block + if name == 'textarea' + tab_down(haml_buffer.tabulation) + elsif preserve && content_or_options_with_block content_or_options_with_block = Haml::Helpers.preserve(content_or_options_with_block) end content_tag_without_haml(name, content_or_options_with_block, *args, &block) diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 9202b52a..8441c683 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| s.add_dependency 'flash_cookie_session', '~> 1.1.1' s.add_dependency 'locomotive_liquid', '2.2.2' - s.add_dependency 'formtastic', '~> 2.0.2' + s.add_dependency 'formtastic', '~> 2.2.0' s.add_dependency 'responders', '~> 0.6.4' s.add_dependency 'cells', '~> 3.8.0' s.add_dependency 'RedCloth', '~> 4.2.8' From 47015d34731f8d2e25ffdf4ab48b26c63452b8bf Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 17:48:42 +0200 Subject: [PATCH 35/65] write cucumber tests to illustrate how to deal with a contact form + fix a tiny bug about it --- Gemfile.lock | 6 +- .../public/content_entries_controller.rb | 3 + features/public/contact_form.feature | 62 +++++++++++++++++++ .../step_definitions/content_types_steps.rb | 8 +++ features/step_definitions/page_steps.rb | 3 +- locomotive_cms.gemspec | 2 +- 6 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 features/public/contact_form.feature diff --git a/Gemfile.lock b/Gemfile.lock index da5447f2..a21d2eaf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,7 @@ PATH dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) fog (~> 1.3.1) - formtastic (~> 2.2.0) + formtastic (~> 2.0.2) haml (~> 3.1.4) highline (~> 1.6.2) httparty (~> 0.8.1) @@ -176,8 +176,8 @@ GEM nokogiri (~> 1.5.0) ruby-hmac formatador (0.2.1) - formtastic (2.2.0) - actionpack (>= 3.0) + formtastic (2.0.2) + rails (~> 3.0) fssm (0.2.9) gherkin (2.9.3) json (>= 1.4.6) diff --git a/app/controllers/locomotive/public/content_entries_controller.rb b/app/controllers/locomotive/public/content_entries_controller.rb index 8544cac1..605c15a6 100644 --- a/app/controllers/locomotive/public/content_entries_controller.rb +++ b/app/controllers/locomotive/public/content_entries_controller.rb @@ -8,6 +8,8 @@ module Locomotive skip_before_filter :verify_authenticity_token + skip_load_and_authorize_resource + self.responder = Locomotive::ActionController::PublicResponder # custom responder respond_to :html, :json @@ -15,6 +17,7 @@ module Locomotive def create @entry = @content_type.entries.create(params[:entry] || params[:content]) flash[@content_type.slug.singularize] = @entry.to_presenter(:include_errors => true).as_json + Rails.logger.debug @entry.to_presenter(:include_errors => true).as_json respond_with @entry, :location => self.callback_url end diff --git a/features/public/contact_form.feature b/features/public/contact_form.feature new file mode 100644 index 00000000..cf1a3897 --- /dev/null +++ b/features/public/contact_form.feature @@ -0,0 +1,62 @@ +Feature: Contact form + As a visitor + In order to keep in touch with the site + I want to be able to send them a message + + Background: + Given I have the site: "test site" set up + And I have a custom model named "Messages" with + | label | type | required | + | Email | string | true | + | Message | text | true | + And I enable the public submission of the "Messages" model + And a page named "contact" with the template: + """ + + + +
+ + + + + {% if message.errors.email %}Email is required{% endif %} + + + +
+ + + """ + And a page named "success" with the template: + """ + Thanks {{ message.email }} + """ + + Scenario: Setting the right url for the contact form + When I view the rendered page at "/contact" + Then the rendered output should look like: + """ +
+ """ + + Scenario: Prevents users to post messages if the public submission option is disabled + Given I disable the public submission of the "Messages" model + When I view the rendered page at "/contact" + And I fill in "E-Mail Address" with "did@locomotivecms.com" + And I fill in "Message" with "LocomotiveCMS rocks" + And I press "Submit" + Then I should not see "Thanks did@locomotivecms.com" + + Scenario: Sending a message with success + When I view the rendered page at "/contact" + And I fill in "E-Mail Address" with "did@locomotivecms.com" + And I fill in "Message" with "LocomotiveCMS rocks" + And I press "Submit" + Then I should see "Thanks did@locomotivecms.com" + + Scenario: Display errors + When I view the rendered page at "/contact" + And I fill in "Message" with "LocomotiveCMS rocks" + And I press "Submit" + Then I should see "Email is required" diff --git a/features/step_definitions/content_types_steps.rb b/features/step_definitions/content_types_steps.rb index c904d564..8852c0b6 100644 --- a/features/step_definitions/content_types_steps.rb +++ b/features/step_definitions/content_types_steps.rb @@ -39,6 +39,14 @@ Given %r{^I have entries for "([^"]*)" with$} do |name, entries| content_type.save.should be_true end +Given %r{^I (enable|disable) the public submission of the "([^"]*)" model$} do |action, name| + enabled = action == 'enable' + content_type = Locomotive::ContentType.where(:name => name).first + content_type.public_submission_enabled = enabled + content_type.public_submission_accounts = enabled ? [Locomotive::Account.first._id] : [] + content_type.save.should be_true +end + When %r{^I change the presentation of the "([^"]*)" model by grouping items by "([^"]*)"$} do |name, field| content_type = Locomotive::ContentType.where(:name => name).first field = content_type.entries_custom_fields.detect { |f| f.label == field } diff --git a/features/step_definitions/page_steps.rb b/features/step_definitions/page_steps.rb index c4d46fdb..45e5b807 100644 --- a/features/step_definitions/page_steps.rb +++ b/features/step_definitions/page_steps.rb @@ -54,7 +54,8 @@ end # checks if the rendered body matches a string Then /^the rendered output should look like:$/ do |body_contents| - page.source.should == body_contents + # page.source.should == body_contents + page.source.index(body_contents).should_not be_nil end Then /^I should see delete page buttons$/ do diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 8441c683..9202b52a 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| s.add_dependency 'flash_cookie_session', '~> 1.1.1' s.add_dependency 'locomotive_liquid', '2.2.2' - s.add_dependency 'formtastic', '~> 2.2.0' + s.add_dependency 'formtastic', '~> 2.0.2' s.add_dependency 'responders', '~> 0.6.4' s.add_dependency 'cells', '~> 3.8.0' s.add_dependency 'RedCloth', '~> 4.2.8' From b053ba5a267ce6ec408323aa0ab5a2a038f350f7 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 18:42:27 +0200 Subject: [PATCH 36/65] bump version to 2.0.0.rc6 --- lib/locomotive/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locomotive/version.rb b/lib/locomotive/version.rb index 169058b0..6a4543b6 100644 --- a/lib/locomotive/version.rb +++ b/lib/locomotive/version.rb @@ -1,3 +1,3 @@ module Locomotive #:nodoc - VERSION = '2.0.0.rc5' + VERSION = '2.0.0.rc6' end From 792ebd142b7d3ede6ba280884d3fea69a96d0ece Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Tue, 17 Apr 2012 18:43:14 +0200 Subject: [PATCH 37/65] bump version to 2.0.0.rc6 (forgot something) --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index a21d2eaf..3ceb1da5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,7 +28,7 @@ GIT PATH remote: . specs: - locomotive_cms (2.0.0.rc5) + locomotive_cms (2.0.0.rc6) RedCloth (~> 4.2.8) actionmailer-with-request (~> 0.3.0) bson_ext (~> 1.5.2) From 9f2cab94cbc81e0c18ec3051bc263fec2ea2374b Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Wed, 18 Apr 2012 02:07:48 +0200 Subject: [PATCH 38/65] the very first tests for the API --- features/api/authentication.feature | 19 +++++++++++++ features/api/pages.feature | 29 ++++++++++++++++++++ features/step_definitions/api_steps.rb | 38 ++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 features/api/authentication.feature create mode 100644 features/api/pages.feature create mode 100644 features/step_definitions/api_steps.rb diff --git a/features/api/authentication.feature b/features/api/authentication.feature new file mode 100644 index 00000000..88e67926 --- /dev/null +++ b/features/api/authentication.feature @@ -0,0 +1,19 @@ +Feature: Authentication + In order to consume the API + As an admin + I need to get an authentication token + + Background: + Given I have the site: "test site" set up + + Scenario: Fail to get a token without an email and a password + When I post to "/locomotive/api/tokens.json" + Then the JSON response at "message" should be "The request must contain the user email and password." + + Scenario: Get a token + When I post to "/locomotive/api/tokens.json" with: + """ + { "email": "admin@locomotiveapp.org", "password": "easyone" } + """ + Then the JSON response at "token" should be a string + And the JSON response should not have "message" \ No newline at end of file diff --git a/features/api/pages.feature b/features/api/pages.feature new file mode 100644 index 00000000..1dec1085 --- /dev/null +++ b/features/api/pages.feature @@ -0,0 +1,29 @@ +Feature: Pages + In order to access the Page resources + As an admin + I will perform the basic RESTFUL actions on them + + Background: + Given I have the site: "test site" set up + And I have an "admin" API token + And a page named "hello world" with the template: + """ + Hello world :-) + """ + And a page named "goodbye-world" with the template: + """ + Goodbye world :-( + """ + + Scenario: Protect the pages resources if not authenticated + Given I do not have an API token + When I visit "/locomotive/api/pages.json" + Then the JSON response at "error" should be "You need to sign in or sign up before continuing." + + Scenario: Accessing pages + When I visit "/locomotive/api/pages.json" + Then the JSON should have the following: + | 0/fullpath | "index" | + | 1/fullpath | "hello-world" | + | 2/fullpath | "404" | + | 3/fullpath | "goodbye-world" | \ No newline at end of file diff --git a/features/step_definitions/api_steps.rb b/features/step_definitions/api_steps.rb new file mode 100644 index 00000000..d46ee3fc --- /dev/null +++ b/features/step_definitions/api_steps.rb @@ -0,0 +1,38 @@ +def last_json + @json_response.try(:body) || page.source +end + +Given /^I have an? "([^"]*)" API token$/ do |role| + @membership = Locomotive::Site.first.memberships.where(:role => role.downcase).first \ + || FactoryGirl.create(role.downcase.to_sym, :site => Locomotive::Site.first) + + login_params = { + 'email' => @membership.account.email, + 'password' => 'easyone' + } + + response = post("http://#{@site.domains.first}/locomotive/api/tokens.json", login_params.to_json, { 'CONTENT_TYPE' => 'application/json' }) + + if response.status == 200 + @auth_token = JSON.parse(response.body)['token'] + else + raise JSON.parse(response.body)['message'] + end +end + +Given /^I do not have an API token$/ do + @auth_token = nil +end + +When /^I visit "([^"]*)"$/ do |path| + @json_response = get("http://#{@site.domains.first}#{path}", { auth_token: @auth_token }, { 'CONTENT_TYPE' => 'application/json' }) +end + +# http://stackoverflow.com/questions/9009392/racktest-put-method-with-json-fails-to-convert-json-to-params +When /^I post to "([^"]*)"$/ do |path| + @json_response = post("http://#{@site.domains.first}#{path}", '', { 'CONTENT_TYPE' => 'application/json' }) +end + +When /^I post to "([^"]*)" with:$/ do |path, json_string| + @json_response = post("http://#{@site.domains.first}#{path}", json_string, { 'CONTENT_TYPE' => 'application/json' }) +end \ No newline at end of file From 0719a8bb76286e8733e3be3f1e839baa86118cb1 Mon Sep 17 00:00:00 2001 From: PitOn Date: Wed, 18 Apr 2012 16:14:01 +0400 Subject: [PATCH 39/65] added missing ru translations for upcoming 2.0 version --- config/locales/admin_ui.ru.yml | 105 +++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 43 deletions(-) diff --git a/config/locales/admin_ui.ru.yml b/config/locales/admin_ui.ru.yml index c327368b..653d1554 100644 --- a/config/locales/admin_ui.ru.yml +++ b/config/locales/admin_ui.ru.yml @@ -7,9 +7,22 @@ ru: new_item: "+ добавить" switch_to_site: Сайт delete: "Удалить" + close: "Закрыть" + + locales: + en: Английский + de: Немецкий + fr: Французский + pt-BR: "Бразильский - Португальский" + it: Итальянский + nl: Голландский + "no": Норвежский + es: Испанский + ru: Русский messages: confirm: Вы уверены ? + sending_form: Ваша форма отправляется shared: header: @@ -27,6 +40,10 @@ ru: account: Аккаунт site: Сайт theme_assets: Файлы темы + form: + change_file: изменить + delete_file: удалить + cancel: отменить footer: who_is_behind: "Service developed by %{development} and designed by Sacha Greif" form_actions: @@ -34,7 +51,9 @@ ru: create: Создать update: Сохранить send: Отправить - disable_with: "locomotive.disable_with.form_actions" + disable_with: В ожидании... + list: + untranslated: непереведено errors: "500": @@ -66,9 +85,15 @@ ru: delete_file: Удалить файл has_many: empty: Пусто - index: - is_required: является обязательным + new_entry: + Добавить новый элемент + many_to_many: + empty: Список пуст. Добавьте элемент из селекта ниже. + form: + required: Обязательное + optional: Опциональное default_label: Название поля + select_options: + ask_name: "Введите название элемента" sessions: new: @@ -105,7 +130,9 @@ ru: help: "Заголовок страницы может быть изменен, если кликнуть на нем. Чтобы применить изменения, нажмите кнопку \"Сохранить\"." ask_for_title: "Пожалуйста введите новое имя страницы" form: + change_file: Изменить delete_file: Удалить файл + cancel: Отмена default_block: По умолчанию cache_strategy: none: Нет @@ -134,11 +161,11 @@ ru: new: title: Новый сайт help: "Заполните форму, приведенную ниже, чтобы создать новый сайт." + domains: + empty: "Пока нет ни одного домена, привязанного к этому сайту. Просто добавьте домены ниже. Не забудьте обновить ваши DNS." current_site: edit: - export: экспорт - import: импорт new_membership: добавить аккаунт help: "Название сайта может быть изменено, если кликнуть на нем. Чтобы применить изменения, нажмите кнопку \"Save\"." ask_for_name: "Пожалуйста введите новое имя сайта" @@ -161,20 +188,13 @@ ru: edit: help: "Вы можете изменить логин просто кликнув на нем. Чтобы применить изменения, нажмите кнопку \"Сохранить\"." new_site: новый сайт - en: Английский - de: Немецкий - fr: Французский - pt-BR: "Бразильский - Португальский" - it: Итальянский - nl: Голландский - "no": норвежский - es: Испанский ask_for_name: "Пожалуйста введите ваш новый логин" theme_assets: index: title: Список файлов темы help: "Секция файлов темы это место, где вы можете управлять файлами, необходимыми для вашего шаблона, сниппетов и т.д. Если вам необходимо управление галереей изображений, создайте новый тип контента.
Внимание: вы можете не увидеть всех файлов - в зависимости от ваших прав." + quick_upload: Быстрая загрузка new: новый файл snippets: Сниппеты css_and_js: Стили и javascript @@ -197,29 +217,29 @@ ru: picker_link: Вставить файл в код choose_file: Выбрать файл choose_plain_text: Выбрать простой текст - images: - title: Список изображений - no_items: "Пока нет ни одного файла." + image_picker: + title: "Вставить изображение" + no_items: "Нет ни одного изображения." + upload: "Upload theme images" - assets: - new: - title: Новый файл - help: "Заполните форму, приведенную ниже, для создания файла (asset)." - edit: - title: Редактировать файл - help: "Заполните форму, приведенную ниже, для изменения файла." + content_assets: + picker: + title: "Вставьте медиа-файл" + no_items: "Нет ни одного медиа-файла." + upload: "Загрузить медиа" content_types: index: new: новая модель + edit: редактировать модель new: title: Новая модель help: "Создайте ваши собственные модели данных (Проекты, Персоны, ...и т.д.). Модель должна иметь по крайней мере одно поле. Элементы, созданные из этого типа содержимого, будут иметь первое поле как обязательное." edit: title: Редактирование модели help: "Ваша модель должна иметь по крайней мере одно поле. Элементы, созданные из этого типа содержимого, будут иметь это поле как обязательное." - show_items: смотреть элементы - new_item: новый элемент + show_entries: смотреть элементы + new_entry: новый элемент form: order_by: created_at: 'По дате создания' @@ -257,23 +277,6 @@ ru: title: Кроссдоменная аутентификация notice: Вы будете перенаправлены на вебсайт в течение нескольких секунд. - import: - new: - title: Импортировать шаблон сайта - help: "Будьте осторожны при загрузке нового шаблона для существующего сайта, ваши текущие данные могут быть изменены или даже удалены." - show: - title: Выполняется импорт - help: "Ваш сайт обновляется из zip файла темы, который вы только что загрузили. Это займет несколько секунд." - steps: - site: Информация сайта - content_types: Пользовательские типы содержимого - assets: Файлы темы - snippets: Сниппеты - pages: Страницы - messages: - success: "Ваш сайт был успешно обновлен." - failure: "Импорт не работает." - installation: common: title: Первая установка Locomotive @@ -289,5 +292,21 @@ ru: step_2: title: "Шаг 2/2 — Создайте первый сайт" explanations: "Если вы уже загрузили шаблон сайта по умолчанию (см. инструкцию), вы можете использовать его прямо сейчас. Или вы можете загрузить шаблон сайта как zip файл (доступные бесплатные шаблоны здесь)." - back_to_default_template: "Нажмите здесь для выбора шаблона сайта по умолчанию" + default_site_locale: Локаль сайта по умолчанию + default_site_locales_hints: Вы всегда можете добавить больше локалей в разделе Настройки. next: Создать сайт + + public: + pages: + show_toolbar: + statuses: + loading: "Загрузка...." + disabled: "Встроенный редактор отключен" + labels: + save_changes: "Сохранить изменения: " + editing_mode: "Режим редактирования: " + lang: "Язык: " + buttons: + back: Назад в админку + confirm: Подтвердить + cancel: Отменить From 23f162f0b3a5ccc9e3d5785e1641410c786bde71 Mon Sep 17 00:00:00 2001 From: PitOn Date: Wed, 18 Apr 2012 16:16:46 +0400 Subject: [PATCH 40/65] added missing ru translations for upcoming 2.0 version --- config/locales/default.ru.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/config/locales/default.ru.yml b/config/locales/default.ru.yml index 58fc5f8b..8e1433d7 100644 --- a/config/locales/default.ru.yml +++ b/config/locales/default.ru.yml @@ -1,5 +1,4 @@ ru: - errors: messages: domain_taken: "%{value} уже занято" @@ -8,16 +7,15 @@ ru: protected_page: "Вы не можете удалять стартовую или 404 страницы" extname_changed: "Новый файл не имеет оригинального расширения" array_too_short: "слишком мал (минимальное число элементов %{count})" - liquid_syntax: "Ошибка синтаксиса Liquid ('%{error}')" invalid_theme_file: "не может быть пустым или не является zip файлом" - - too_short: "слишком короткий (не менее %{count} символов)" - blank: "не может быть пустым" - invalid: "имеет неверное значение" - confirmation: "не совпадает с подтверждением" + site: + default_locale_removed: Предыдущая локаль не может быть удалена. page: liquid_syntax: "Ошибка синтаксиса Liquid ('%{error}' в '%{fullpath}')" - liquid_extend: "Страница '%{fullpath}' расширяет шаблон, который не существует" + liquid_extend: "Страница '%{fullpath}' наследует (расширяет) несуществующий шаблон" + liquid_translation: "Страница '%{fullpath}' наследует (расширяет) непереведенный шаблон" + too_few_custom_fields: "По крайней мере одно поле является обязательным" + security: "проблема безопасности" attributes: defaults: From 06c1317acbfc893ff2610df5b0cf5753caab8664 Mon Sep 17 00:00:00 2001 From: PitOn Date: Wed, 18 Apr 2012 16:18:38 +0400 Subject: [PATCH 41/65] added missing ru translations for upcoming 2.0 version --- config/locales/devise.ru.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/locales/devise.ru.yml b/config/locales/devise.ru.yml index cfe28b0a..108e223f 100644 --- a/config/locales/devise.ru.yml +++ b/config/locales/devise.ru.yml @@ -7,7 +7,7 @@ ru: devise: failure: - locomotive: + locomotive_account: unauthenticated: 'Вам необходимо войти или зарегистрироваться перед тем, как продолжить.' unconfirmed: 'Вы должны подтвердить аккаунт перед продолжением.' locked: 'Ваш аккаунт заблокирован.' @@ -17,34 +17,34 @@ ru: timeout: 'Срок действия вашей сессии истек, пожалуйста залогиньтесь для продолжения.' inactive: 'Ваш аккаунт еще не был активирован.' sessions: - locomotive: + locomotive_account: signed_in: 'Вход выполнен успешно.' signed_out: 'Выход выполнен успешно.' passwords: - locomotive: + locomotive_account: send_instructions: 'Вы получите письмо с инструкциями о том, как сбросить ваш пароль, через несколько минут.' updated: 'Ваш пароль был успешно изменен. Вы вошли в систему.' confirmations: - locomotive: + locomotive_account: send_instructions: 'Вы получите письмо с инструкциями о том, как подтвердить ваш аккаунт, через несколько минут.' confirmed: 'Ваша учетная запись была успешно подтверждена. Вы вошли в систему.' registrations: - locomotive: + locomotive_account: signed_up: 'Вы успешно зарегистрировались.' updated: 'Вы успешно обновили ваш аккаунт.' destroyed: 'До свидания! Ваш аккаунт был успешно отменен. Мы надеемся скоро увидеть вас снова.' unlocks: - locomotive: + locomotive_account: send_instructions: 'Вам будет отправлено письмо с инструкциями о том, как разблокировать ваш аккаунт, в течение нескольких минут.' unlocked: 'Ваша учетная запись была успешно разблокирована. Вы вошли в систему.' mailer: - locomotive: + locomotive_account: confirmation_instructions: 'Инструкции подтверждения' reset_password_instructions: 'Инструкции по сбросу пароля' unlock_instructions: 'Инструкции по разблокированию' - - - locomotive: + + + locomotive_account: mailer: common: hello: Здравствуйте From d78f99703e719bde9a3735d9887f838278ab23b8 Mon Sep 17 00:00:00 2001 From: PitOn Date: Wed, 18 Apr 2012 16:20:36 +0400 Subject: [PATCH 42/65] added missing ru translations for upcoming 2.0 version --- config/locales/formtastic.ru.yml | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/config/locales/formtastic.ru.yml b/config/locales/formtastic.ru.yml index 42ce678c..22c1ae25 100644 --- a/config/locales/formtastic.ru.yml +++ b/config/locales/formtastic.ru.yml @@ -33,37 +33,40 @@ ru: custom_fields: field: name: Алиас - import: - new: - source: Файл - samples: Копировать образцы - reset: Сбросить сайт - default_site_template: "Используйте шаблон сайта по умолчанию. Нажмите здесь для загрузки шаблона сайта в виде zip файла." content_type: - item_template: Шаблон элемента - api_accounts: Уведомленные аккаунты + raw_item_template: Шаблон элемента + public_submission_enabled: Публичное представление + public_submission_accounts: Уведомленные аккаунты + "custom_fields/field": + select_options: "Опции" content_entry: _slug: Постоянная ссылка account: edit: + locale: Язык интерфейса пользователя password: Новый пароль password_confirmation: Подтверждение нового пароля page: seo_title: Название + target_klass_name: Model + site: + locales: Языки hints: page: + handle: "Уникальный идентификатор для поиска этой страницы из экземпляра внешнего rails-контроллера" published: "Только аутентифицированным пользователям разрешается просматривать неопубликованные страницы." cache_strategy: "Кэшировать страницу для лучшей производительности. Вариант 'Простое' является хорошим компромиссом." templatized: "Используйте страницу в качестве шаблона для определенной вами модели." listed: "Контролируйте возможность показа страницы из сгенерированных меню." - content_type_id: "Тип содержимого, для которого эта страница будет выступать в качестве шаблона." + target_klass_name: "Тип контента (модели), для которого эта страница будет выступать в качестве шаблона." seo_title: "Определите заголовок страницы, который будет использоваться как значение тэга title в секции head. Оставьте пустым, если вы хотите использовать значение по умолчанию из настроек сайта." meta_keywords: "Переопределяет meta keywords сайта, используемые внутри тэга head страницы. Они разделены запятыми." meta_description: "Переопределяет meta description сайта, используемые внутри тэга head страницы." snippet: slug: "Вам необходимо знать это для вставки сниппета в страницу" site: + locales: "Перетащите и отпустите флаг на первую позицию, чтобы сделать ее локалью по умолчанию." seo_title: "Задайте глобальное значение здесь, которое будет использовано как значение для тэга title в секции head." meta_keywords: "Meta keywords используются внутри тэга head страницы. Они разделяются запятыми. Требуется для SEO." meta_description: "Meta description используются для тэга head страницы. Необходимо для SEO." @@ -79,10 +82,6 @@ ru: source: "Текущий файл доступен здесь %{url}" update: source: "Текущий файл доступен здесь %{url}" - custom_fields: - field: - name: "Свойство, доступное в шаблонах liquid" - hint: "Текст, отображенный в форме модели, находится ниже поля" content_entry: _slug: "Свойство, используемое для генерации ссылки (url) на страницу, работающей как шаблон для этого типа содержимого (ex: \"template_page/{{ your_object._permalink }})\"." seo_title: "Значение, вводимое вами, будет заменять SEO заголовок шаблонизированной страницы, связанной с вашей моделью." @@ -93,7 +92,12 @@ ru: samples: "Если включено, процесс импорта также скопирует содержимое и файлы" reset: "Если включено, все данные вашего сайта будут уничтожены перед импортом нового сайта" content_type: - item_template: "Вы можете задавать текст, отображаемый для каждого элемента в списке. Просто используйте Liquid. Пр.: {{ entry.name }})" - api_enabled: "Это используется для того, чтобы дать людям извне возможность создавать новые экземляры (пример: сообщения в форме контакта)" - api_accounts: "Письмо с уведомлением будет отправлено на каждый аккаунт из списка выше, когда создан новый экземпляр" + name: "Необходимо вводить название модели во множественном числе. Например: Projects, Recipes, Posts, Articles, ...и т.д." + slug: "Поле будет использовано как имя коллекции в шаблонах liquid. Пр.: {{ contents.my_projects }}" + raw_item_template: "Вы можете задавать текст, отображаемый для каждого элемента в списке. Просто используйте Liquid. Пр.: {{ entry.name }})" + public_submission_enabled: "Это используется для того, чтобы дать людям извне возможность создавать новые экземляры (пример: сообщения в форме контакта)" + public_submission_accounts: "Письмо с уведомлением будет отправлено на каждый аккаунт из списка выше каждый раз, когда создается новый экземпляр (если включена опция публичного представления)" + "custom_fields/field": + name: "Имя свойства для шаблонов liquid. Пр.: {{ your_object.<name_of_your_field> }}" + hint: "Текст-подсказка, отображаемый на форме модели под полем" From 9267725c9fff931daed3fdcb2a6b169fb5269c77 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Wed, 18 Apr 2012 14:35:06 +0200 Subject: [PATCH 43/65] clean the upgrade script (v1 -> v2) --- script/upgrade.rb | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/script/upgrade.rb b/script/upgrade.rb index 4de49680..5bed8e39 100755 --- a/script/upgrade.rb +++ b/script/upgrade.rb @@ -5,17 +5,6 @@ rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end -Locomotive::Page.each do |page| - page.editable_elements.each_with_index do |el, index| - next if el._type != 'Locomotive::EditableFile' || el.attributes['source'].is_a?(Hash) - - value = el.attributes['source'] - - page.collection.update({ '_id' => page._id }, { '$set' => { "editable_elements.#{index}.source" => { 'en' => value } } }) - end -end - - # ================ GLOBAL VARIABLES ============== $database = 'locomotive_hosting_production' @@ -24,12 +13,12 @@ $default_locale = 'en' # $locale_exceptions = {} # Example: -$locale_exceptions = { - '4c082a9393d4330812000002' => 'fr', - '4c2330706f40d50ae2000005' => 'fr', - '4dc07643d800a53aea00035a' => 'fr', - '4eb6aca89a976a0001000ebb' => 'fr' -} +# $locale_exceptions = { +# '4c082a9393d4330812000002' => 'fr', +# '4c2330706f40d50ae2000005' => 'fr', +# '4dc07643d800a53aea00035a' => 'fr', +# '4eb6aca89a976a0001000ebb' => 'fr' +# } def get_locale(site_id) $locale_exceptions[site_id.to_s] || $default_locale @@ -42,8 +31,18 @@ require 'mongoid' Mongoid.configure do |config| name = $database host = 'localhost' - config.master = Mongo::Connection.new.db(name) + + # simple connection + # config.master = Mongo::Connection.new.db(name) + + # a more complicated connection # config.master = Mongo::Connection.new('localhost', '27017', :logger => Logger.new($stdout)).db(name) + + # connection with authentication + # db = config.master = Mongo::Connection.new(host, '27019').db(name) + # db.authenticate('username', 'password').tap do |auth| + # puts auth.inspect + # end end db = Mongoid.config.master @@ -305,6 +304,17 @@ if collection = db.collections.detect { |c| c.name == 'pages' } modifications["editable_elements.#{index}.source"] = { locale => editable_element['source_filename'] } removals["editable_elements.#{index}.source_filename"] = '1' end + + # FIXME: do not remember why I needed to run this code. + # Locomotive::Page.each do |page| + # page.editable_elements.each_with_index do |el, index| + # next if el._type != 'Locomotive::EditableFile' || el.attributes['source'].is_a?(Hash) + # + # value = el.attributes['source'] + # + # page.collection.update({ '_id' => page._id }, { '$set' => { "editable_elements.#{index}.source" => { 'en' => value } } }) + # end + # end end if page['depth'] == 0 && page['fullpath'] == '404' From b0a552dfcf96d34c0c1a4688448310352996557e Mon Sep 17 00:00:00 2001 From: PitOn Date: Wed, 18 Apr 2012 16:41:24 +0400 Subject: [PATCH 44/65] added missing ru translations for upcoming 2.0 version --- config/locales/admin_ui.ru.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/admin_ui.ru.yml b/config/locales/admin_ui.ru.yml index 653d1554..c6dc911b 100644 --- a/config/locales/admin_ui.ru.yml +++ b/config/locales/admin_ui.ru.yml @@ -13,7 +13,7 @@ ru: en: Английский de: Немецкий fr: Французский - pt-BR: "Бразильский - Португальский" + pt-BR: "Браз. - Португальский" it: Итальянский nl: Голландский "no": Норвежский From 9b4fc56e82a90f681f53e8fa61f7d93d3e24c83e Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Thu, 19 Apr 2012 16:30:16 +0200 Subject: [PATCH 45/65] fix issue #360 --- Gemfile | 4 ++-- Gemfile.lock | 20 +++++++++---------- lib/locomotive/liquid/drops/content_entry.rb | 7 ++----- locomotive_cms.gemspec | 2 +- .../liquid/drops/content_entry_spec.rb | 7 +++---- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 5c881251..99091b1d 100755 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,8 @@ gemspec # Include gemspec dependencies # The rest of the dependencies are for use when in the locomotive development environment group :development do - # gem 'custom_fields', :path => '../gems/custom_fields' # for Developers - gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => '2.0.0.rc' # Branch on Github + gem 'custom_fields', :path => '../gems/custom_fields' # for Developers + # gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => '2.0.0.rc' # Branch on Github gem 'rspec-rails', '~> 2.8.0' # In order to have rspec tasks and generators gem 'rspec-cells' diff --git a/Gemfile.lock b/Gemfile.lock index 3ceb1da5..b484e925 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,16 +15,6 @@ GIT fssm (>= 0.2.7) sass (~> 3.1) -GIT - remote: git://github.com/locomotivecms/custom_fields.git - revision: 5b0e68859eaca41ac9d7a0231c6cd68ad66018b8 - branch: 2.0.0.rc - specs: - custom_fields (2.0.0.rc9) - activesupport (~> 3.2.1) - carrierwave-mongoid (~> 0.1.3) - mongoid (~> 2.4.7) - PATH remote: . specs: @@ -37,7 +27,7 @@ PATH carrierwave-mongoid (~> 0.1.3) cells (~> 3.8.0) codemirror-rails (~> 2.21) - custom_fields (~> 2.0.0.rc9) + custom_fields (~> 2.0.0.rc10) devise (~> 1.5.3) dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) @@ -65,6 +55,14 @@ PATH sanitize (~> 2.0.3) unidecoder (~> 1.1.1) +PATH + remote: ../gems/custom_fields + specs: + custom_fields (2.0.0.rc10) + activesupport (~> 3.2.1) + carrierwave-mongoid (~> 0.1.3) + mongoid (~> 2.4.7) + GEM remote: http://rubygems.org/ specs: diff --git a/lib/locomotive/liquid/drops/content_entry.rb b/lib/locomotive/liquid/drops/content_entry.rb index 99420387..237292b4 100644 --- a/lib/locomotive/liquid/drops/content_entry.rb +++ b/lib/locomotive/liquid/drops/content_entry.rb @@ -63,12 +63,9 @@ module Locomotive conditions = HashWithIndifferentAccess.new(@context['with_scope']) order_by = conditions.delete(:order_by).try(:split) - if order_by.nil? - list.where(conditions).ordered - else - list.where(conditions).order_by(order_by) - end + list.filtered(conditions, order_by) else + # no filter, default order list.ordered end end diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 9202b52a..4463f05d 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |s| s.add_dependency 'mongoid', '~> 2.4.6' s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2' - s.add_dependency 'custom_fields', '~> 2.0.0.rc9' + s.add_dependency 'custom_fields', '~> 2.0.0.rc10' s.add_dependency 'kaminari', '~> 0.13.0' diff --git a/spec/lib/locomotive/liquid/drops/content_entry_spec.rb b/spec/lib/locomotive/liquid/drops/content_entry_spec.rb index 0b6cd6a1..2a96bd75 100644 --- a/spec/lib/locomotive/liquid/drops/content_entry_spec.rb +++ b/spec/lib/locomotive/liquid/drops/content_entry_spec.rb @@ -5,6 +5,7 @@ describe Locomotive::Liquid::Drops::ContentEntry do before(:each) do @list = mock('list') @list.stubs(:all).returns(true) + # @list.stubs(:to_liquid).returns(true) @category = Locomotive::Liquid::Drops::ContentEntry.new(mock('category', :projects => @list)) end @@ -21,8 +22,7 @@ describe Locomotive::Liquid::Drops::ContentEntry do it 'filters the list' do template = %({% with_scope order_by: 'name ASC', active: true %}{% for project in category.projects %}{{ project }},{% endfor %}{% endwith_scope %}) - @list.expects(:order_by).with(['name', 'ASC']).returns(%w(a b)) - @list.expects(:where).with({ 'active' => true }).returns(@list) + @list.expects(:filtered).with({ 'active' => true }, ['name', 'ASC']).returns(%w(a b)) render(template, { 'category' => @category }).should == 'a,b,' end @@ -30,8 +30,7 @@ describe Locomotive::Liquid::Drops::ContentEntry do it 'filters the list and uses the default order' do template = %({% with_scope active: true %}{% for project in category.projects %}{{ project }},{% endfor %}{% endwith_scope %}) - @list.expects(:ordered).returns(%w(a b)) - @list.expects(:where).with({ 'active' => true }).returns(@list) + @list.expects(:filtered).with({ 'active' => true }, nil).returns(%w(a b)) render(template, { 'category' => @category }).should == 'a,b,' end From 486c6a12a20da949bba30d0dabe96b3b5ec9790f Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 20 Apr 2012 00:31:48 +0200 Subject: [PATCH 46/65] fix issue #367 --- .../extensions/page/editable_elements.rb | 5 +++ .../liquid/drops/content_entry_spec.rb | 1 - .../extensions/page/editable_elements_spec.rb | 43 +++++++++++++++++++ .../extensions/site/subdomain_domains_spec.rb | 2 + 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 spec/models/locomotive/extensions/page/editable_elements_spec.rb diff --git a/app/models/locomotive/extensions/page/editable_elements.rb b/app/models/locomotive/extensions/page/editable_elements.rb index 31fc0d8f..4137d0bb 100644 --- a/app/models/locomotive/extensions/page/editable_elements.rb +++ b/app/models/locomotive/extensions/page/editable_elements.rb @@ -71,6 +71,11 @@ module Locomotive new_el.copy_attributes_from(el) else existing_el.disabled = false + + # only the type and hint properties can be modified from the parent element + %w(_type hint).each do |attr| + existing_el.send(:"#{attr}=", el.send(attr.to_sym)) + end end end end diff --git a/spec/lib/locomotive/liquid/drops/content_entry_spec.rb b/spec/lib/locomotive/liquid/drops/content_entry_spec.rb index 2a96bd75..65d0214a 100644 --- a/spec/lib/locomotive/liquid/drops/content_entry_spec.rb +++ b/spec/lib/locomotive/liquid/drops/content_entry_spec.rb @@ -5,7 +5,6 @@ describe Locomotive::Liquid::Drops::ContentEntry do before(:each) do @list = mock('list') @list.stubs(:all).returns(true) - # @list.stubs(:to_liquid).returns(true) @category = Locomotive::Liquid::Drops::ContentEntry.new(mock('category', :projects => @list)) end diff --git a/spec/models/locomotive/extensions/page/editable_elements_spec.rb b/spec/models/locomotive/extensions/page/editable_elements_spec.rb new file mode 100644 index 00000000..19d731bb --- /dev/null +++ b/spec/models/locomotive/extensions/page/editable_elements_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Locomotive::Extensions::Page::EditableElements do + + before(:each) do + @site = FactoryGirl.create(:site) + @home = @site.pages.root.first + + @home.update_attributes :raw_template => "{% editable_short_text 'body' %}Lorem ipsum{% endeditable_short_text %}" + + @sub_page_1 = FactoryGirl.create(:page, :slug => 'sub_page_1', :parent => @home, :raw_template => "{% extends 'parent' %}") + @sub_page_2 = FactoryGirl.create(:page, :slug => 'sub_page_2', :parent => @home, :raw_template => "{% extends 'parent' %}") + + @sub_page_1_el = @sub_page_1.editable_elements.first + + @sub_page_1_1 = FactoryGirl.create(:page, :slug => 'sub_page_1_1', :parent => @sub_page_1, :raw_template => "{% extends 'parent' %}") + end + + describe 'modification of an element within the home page' do + + before(:each) do + @home = Locomotive::Page.find(@home._id) + end + + it 'changes the type of the element in all the children' do + @home.update_attributes :raw_template => "{% editable_long_text 'body' %}Lorem ipsum{% endeditable_long_text %}" + @sub_page_1.reload + @sub_page_1.editable_elements.first._type.should == 'Locomotive::EditableLongText' + @sub_page_1_1.reload + @sub_page_1_1.editable_elements.first._type.should == 'Locomotive::EditableLongText' + end + + it 'changes the hint of the element in all the children' do + @home.update_attributes :raw_template => "{% editable_long_text 'body', hint: 'My very useful hint' %}Lorem ipsum{% endeditable_long_text %}" + @sub_page_1.reload + @sub_page_1.editable_elements.first.hint.should == 'My very useful hint' + @sub_page_1_1.reload + @sub_page_1_1.editable_elements.first.hint.should == 'My very useful hint' + end + + end + +end diff --git a/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb b/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb index f9fb33e4..2a6baec8 100644 --- a/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb +++ b/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Locomotive::Extensions::Site::SubdomainDomains do + describe '#subdomain=' do let(:site) { Locomotive::Site.new } @@ -20,4 +21,5 @@ describe Locomotive::Extensions::Site::SubdomainDomains do site.domains.should == ['first.com', 'second.com', 'third.com'] end end + end From f0e8848ffdd3f6f2d2400bd25be51858df265047 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 20 Apr 2012 00:35:14 +0200 Subject: [PATCH 47/65] repair broken build --- Gemfile | 2 +- Gemfile.lock | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 99091b1d..16e83ec8 100755 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gemspec # Include gemspec dependencies # The rest of the dependencies are for use when in the locomotive development environment group :development do - gem 'custom_fields', :path => '../gems/custom_fields' # for Developers + # gem 'custom_fields', :path => '../gems/custom_fields' # for Developers # gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => '2.0.0.rc' # Branch on Github gem 'rspec-rails', '~> 2.8.0' # In order to have rspec tasks and generators diff --git a/Gemfile.lock b/Gemfile.lock index b484e925..d4779eb9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,14 +55,6 @@ PATH sanitize (~> 2.0.3) unidecoder (~> 1.1.1) -PATH - remote: ../gems/custom_fields - specs: - custom_fields (2.0.0.rc10) - activesupport (~> 3.2.1) - carrierwave-mongoid (~> 0.1.3) - mongoid (~> 2.4.7) - GEM remote: http://rubygems.org/ specs: @@ -142,6 +134,10 @@ GEM capybara (>= 1.1.2) cucumber (>= 1.1.8) nokogiri (>= 1.5.0) + custom_fields (2.0.0.rc10) + activesupport (~> 3.2.1) + carrierwave-mongoid (~> 0.1.3) + mongoid (~> 2.4.7) database_cleaner (0.7.2) devise (1.5.3) bcrypt-ruby (~> 3.0) @@ -333,7 +329,6 @@ DEPENDENCIES compass! compass-rails! cucumber-rails - custom_fields! database_cleaner factory_girl_rails (~> 1.6.0) json_spec From 246eadb3fd09256c28bf7c9f189f5c6a29141127 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 20 Apr 2012 13:11:50 +0200 Subject: [PATCH 48/65] fix issue #374 --- .../locomotive/views/editable_elements/file_view.js.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/locomotive/views/editable_elements/file_view.js.coffee b/app/assets/javascripts/locomotive/views/editable_elements/file_view.js.coffee index 821f6f68..400b2ea7 100644 --- a/app/assets/javascripts/locomotive/views/editable_elements/file_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/editable_elements/file_view.js.coffee @@ -38,7 +38,8 @@ class Locomotive.Views.EditableElements.FileView extends Backbone.View on_change: => @$('a:first').hide() & @$('input[type=file]').show() & @$('a.delete').hide() on_cancel: => - @$('a:first').show() & @$('input[type=file]').hide() & @$('a.delete').show() + @model.set(source: null) + @$('a:first').show() & @$('input[type=file]').val('').hide() & @$('a.delete').show() toggle_delete: (event) -> @_toggle event, 'delete', From d6059c2a9b0e152ea81cea2b769a29d10671074f Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 20 Apr 2012 15:42:10 +0200 Subject: [PATCH 49/65] fix issue #373 --- lib/locomotive/dragonfly.rb | 2 ++ .../lib/locomotive/liquid/filters/resize_spec.rb | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/locomotive/dragonfly.rb b/lib/locomotive/dragonfly.rb index 743cdba5..1487e634 100644 --- a/lib/locomotive/dragonfly.rb +++ b/lib/locomotive/dragonfly.rb @@ -7,6 +7,8 @@ module Locomotive if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset source = source['url'] if source.is_a?(Hash) + source.strip! + if source =~ /^http/ file = self.app.fetch_url(source) else diff --git a/spec/lib/locomotive/liquid/filters/resize_spec.rb b/spec/lib/locomotive/liquid/filters/resize_spec.rb index 8ef3097b..1b2056a8 100644 --- a/spec/lib/locomotive/liquid/filters/resize_spec.rb +++ b/spec/lib/locomotive/liquid/filters/resize_spec.rb @@ -17,13 +17,19 @@ describe Locomotive::Liquid::Filters::Resize do @template = Liquid::Template.parse('{{ asset_url | resize: "40x30" }}') end - it 'should return the location of the resized image' do + it 'returns the location of the resized image' do @template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/ end - it 'should use the path in the public folder to generate a location' do + it 'uses the path in the public folder to generate a location' do @template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30') end + + it 'accepts strings with leading and trailing empty characters' do + @context['asset_url'] = " \t #{@context['asset_url']} \n\n " + @template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30') + end + end context 'when a theme asset is given' do @@ -31,11 +37,11 @@ describe Locomotive::Liquid::Filters::Resize do @template = Liquid::Template.parse("{{ theme_asset | resize: '300x400' }}") end - it 'should return the location of the resized image' do + it 'returns the location of the resized image' do @template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/ end - it 'should use the path of the theme asset to generate a location' do + it 'uses the path of the theme asset to generate a location' do @template.render(@context).should == Locomotive::Dragonfly.resize_url(@theme_asset_path, '300x400') end end @@ -45,7 +51,7 @@ describe Locomotive::Liquid::Filters::Resize do @template = Liquid::Template.parse('{{ asset | resize: }}') end - it 'should return a liquid error' do + it 'returns a liquid error' do @template.render(@context).should include 'Liquid error: wrong number of arguments' end end From b87c76bc67010952a756d599818579b1fa21afee Mon Sep 17 00:00:00 2001 From: Annalisa Date: Sat, 21 Apr 2012 00:54:54 +0200 Subject: [PATCH 50/65] added current_user --- lib/locomotive/liquid/drops/current_user.rb | 23 +++++++++++++++++++++ lib/locomotive/render.rb | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/locomotive/liquid/drops/current_user.rb diff --git a/lib/locomotive/liquid/drops/current_user.rb b/lib/locomotive/liquid/drops/current_user.rb new file mode 100644 index 00000000..bfa05c8f --- /dev/null +++ b/lib/locomotive/liquid/drops/current_user.rb @@ -0,0 +1,23 @@ +module Locomotive + module Liquid + module Drops + class CurrentUser < Base + + include ::Rails.application.routes.url_helpers + + def logged_in? + _source.present? + end + + def name + _source.name if logged_in? + end + + def email + _source.email if logged_in? + end + + end + end + end +end diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index 3e23d3bc..821abaaa 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -55,7 +55,8 @@ module Locomotive 'today' => Date.today, 'locale' => I18n.locale, 'default_locale' => current_site.default_locale.to_s, - 'locales' => current_site.locales + 'locales' => current_site.locales, + 'current_user' => Locomotive::Liquid::Drops::CurrentUser.new(current_locomotive_account) } assigns.merge!(Locomotive.config.context_assign_extensions) @@ -105,4 +106,4 @@ module Locomotive end end -end \ No newline at end of file +end From fc380e3e4d0804f00ffe26d3d87c76834c3cc09e Mon Sep 17 00:00:00 2001 From: Annalisa Date: Sat, 21 Apr 2012 01:31:33 +0200 Subject: [PATCH 51/65] strange error --- lib/locomotive/liquid/drops/current_user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locomotive/liquid/drops/current_user.rb b/lib/locomotive/liquid/drops/current_user.rb index bfa05c8f..1ac1bbb7 100644 --- a/lib/locomotive/liquid/drops/current_user.rb +++ b/lib/locomotive/liquid/drops/current_user.rb @@ -3,7 +3,7 @@ module Locomotive module Drops class CurrentUser < Base - include ::Rails.application.routes.url_helpers + include Rails.application.routes.url_helpers def logged_in? _source.present? From 043b78a0616852019a6c1c578eff3bdaaddc957a Mon Sep 17 00:00:00 2001 From: Annalisa Date: Sat, 21 Apr 2012 01:50:37 +0200 Subject: [PATCH 52/65] strange error --- lib/locomotive/liquid/drops/current_user.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/locomotive/liquid/drops/current_user.rb b/lib/locomotive/liquid/drops/current_user.rb index 1ac1bbb7..31b4d00f 100644 --- a/lib/locomotive/liquid/drops/current_user.rb +++ b/lib/locomotive/liquid/drops/current_user.rb @@ -3,8 +3,6 @@ module Locomotive module Drops class CurrentUser < Base - include Rails.application.routes.url_helpers - def logged_in? _source.present? end From 632e16b18e47152a0d882087f76e3b32c8cfd049 Mon Sep 17 00:00:00 2001 From: Annalisa Date: Sat, 21 Apr 2012 11:06:13 +0200 Subject: [PATCH 53/65] issue #321 (current_user) working. url_helpers removed. --- .../locomotive/liquid/drops/current_user.rb | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 spec/lib/locomotive/liquid/drops/current_user.rb diff --git a/spec/lib/locomotive/liquid/drops/current_user.rb b/spec/lib/locomotive/liquid/drops/current_user.rb new file mode 100644 index 00000000..45980a04 --- /dev/null +++ b/spec/lib/locomotive/liquid/drops/current_user.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe Locomotive::Liquid::Drops::CurrentUser do + + before(:each) do + @page = FactoryGirl.build(:sub_page) + + @site = @page.site + @site.pages.expects(:any_in).returns([@page]) + + @controller = Locomotive::TestController.new + @controller.stubs(:flash).returns(ActionDispatch::Flash::FlashHash.new()) + @controller.stubs(:params).returns(:url => '/subpage') + @controller.stubs(:request).returns(OpenStruct.new(:url => '/subpage', :fullpath => '/subpage')) + @controller.current_site = @site + + @admin = FactoryGirl.build(:admin).account + end + + def expect_render(template, text) + @page.raw_template = template + @page.send(:serialize_template) + @controller.expects(:render).with(:text => text, :layout => false, :status => :ok).returns(true) + @controller.send(:render_locomotive_page) + end + + context '#logged_in?' do + it 'returns false when no user is logged in' do + expect_render('{{ current_user.logged_in? }}', 'false') + end + it 'returns true when there is a user logged in' do + @controller.expects(:current_admin).twice.returns(true) + expect_render('{{ current_user.logged_in? }}', 'true') + end + end + + context '#name' do + it 'returns nothing when no user is logged in' do + expect_render('{{ current_user.name }}', '') + end + it 'returns the username when the user is logged in' do + @controller.expects(:current_admin).twice.returns(@admin) + expect_render('{{ current_user.name }}', 'Admin') + end + end + + context '#email' do + it 'returns nothing when no user is logged in' do + expect_render('{{ current_user.email }}', '') + end + it 'returns the username when the user is logged in' do + @controller.expects(:current_admin).twice.returns(@admin) + expect_render('{{ current_user.email }}', 'admin@locomotiveapp.org') + end + end + + context '#logout_path' do + it 'returns the logout url' do + expect_render('{{ current_user.logout_path }}', '/admin/sign_out') + end + end + +end From 08cf381bc35722db5032f84f30a5f6dd3a0570c8 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sun, 22 Apr 2012 01:14:25 +0200 Subject: [PATCH 54/65] simple media plugin for Aloha --- Gemfile | 2 + Gemfile.lock | 4 +- .../custom/locomotive_media/css/image.css | 3 + .../custom/locomotive_media/img/image.gif | Bin 0 -> 621 bytes .../lib/locomotive_media-plugin.js | 96 ++++++++++++++++++ .../custom/locomotive_media/nls/fr/i18n.js | 1 + .../custom/locomotive_media/nls/i18n.js | 4 + .../custom/locomotive_media/package.json | 1 + .../javascripts/locomotive/aloha.js.coffee | 5 + .../locomotive/inline_editor.js.coffee | 1 + .../locomotive/utils/aloha_settings.js.coffee | 5 + .../inline_editor/application_view.js.coffee | 10 +- .../inline_editor/toolbar_view.js.coffee | 4 +- .../backoffice/application.css.scss | 34 ------- .../backoffice/content_assets.css.scss | 4 + .../stylesheets/locomotive/inline_editor.css | 3 + .../locomotive/shared/common.css.scss | 34 +++++++ .../locomotive/content_asset_presenter.rb | 4 +- .../public/pages/show_toolbar.html.haml | 4 +- lib/locomotive/liquid/tags/inline_editor.rb | 2 +- locomotive_cms.gemspec | 2 +- 21 files changed, 176 insertions(+), 47 deletions(-) create mode 100644 app/assets/javascripts/aloha/plugins/custom/locomotive_media/css/image.css create mode 100644 app/assets/javascripts/aloha/plugins/custom/locomotive_media/img/image.gif create mode 100644 app/assets/javascripts/aloha/plugins/custom/locomotive_media/lib/locomotive_media-plugin.js create mode 100644 app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/fr/i18n.js create mode 100644 app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/i18n.js create mode 100644 app/assets/javascripts/aloha/plugins/custom/locomotive_media/package.json create mode 100644 app/assets/stylesheets/locomotive/shared/common.css.scss diff --git a/Gemfile b/Gemfile index 16e83ec8..bd8a8896 100755 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,8 @@ group :development do # gem 'custom_fields', :path => '../gems/custom_fields' # for Developers # gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => '2.0.0.rc' # Branch on Github + # gem 'locomotive-aloha-rails', :path => '../gems/aloha-rails' # for Developers + gem 'rspec-rails', '~> 2.8.0' # In order to have rspec tasks and generators gem 'rspec-cells' diff --git a/Gemfile.lock b/Gemfile.lock index d4779eb9..9b36dfda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,7 +38,7 @@ PATH httparty (~> 0.8.1) jquery-rails (~> 1.0.16) kaminari (~> 0.13.0) - locomotive-aloha-rails (~> 0.20.1.2) + locomotive-aloha-rails (~> 0.20.1.3) locomotive-mongoid-tree (~> 0.6.2) locomotive-tinymce-rails (~> 3.4.7.2) locomotive_liquid (= 2.2.2) @@ -199,7 +199,7 @@ GEM addressable (~> 2.2.6) libwebsocket (0.1.3) addressable - locomotive-aloha-rails (0.20.1.2) + locomotive-aloha-rails (0.20.1.3) actionpack (~> 3.2.1) locomotive-mongoid-tree (0.6.2) mongoid (~> 2.0) diff --git a/app/assets/javascripts/aloha/plugins/custom/locomotive_media/css/image.css b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/css/image.css new file mode 100644 index 00000000..8af94055 --- /dev/null +++ b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/css/image.css @@ -0,0 +1,3 @@ +button.aloha-locomotive-media-insert { + background: url(../img/image.gif) !important; +} \ No newline at end of file diff --git a/app/assets/javascripts/aloha/plugins/custom/locomotive_media/img/image.gif b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/img/image.gif new file mode 100644 index 0000000000000000000000000000000000000000..d5924f4bb36a73a3cd9245b098dba3fd783bd889 GIT binary patch literal 621 zcmZ?wbhEHb6krfwc*el+;q%vwKSo{`2<NYb zUv>7rrlE7qrhvvBp+{c)UwG^PzNi0}-}zs&Ik0krU;WnL?T`LVzxIFq{r?Tyf-Bbh zHtq~Pedglod;d2)_`mZp(4wHTuYpzsS8w#&bnQ^(dcR$df!v^`onbSt|6g$P|CWdU zm)!n8|K|Uy4ZfA@eK$V%-?%-bdV~M=NB>W~`oI6_{}p%suetaC{}YC)4SrP{{hN1% z&%N>g$n*b8Z~t#ybKKE0(kC*%Z0e@a?CyInK0SN$<^TWx3)w2#=%N)wYWTM35t|6wz7aG{KM?ip$%|T4uj8*hRlYgkNu(-26AFGhB)U~i1 ztgMQzLZb3gE{0ETu(O+bO3HHcnhS;oGzEq7{Slay*x19t6=bvE(RnThQI#n@839g? z0{j*d|Ck>nA7hf>l3Nqu)X3D(7Hq(<;?Sh0Y79CSe`Y%sdrg@gP~`M*!kG!@9UB=K FtO3mL_vrut literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/aloha/plugins/custom/locomotive_media/lib/locomotive_media-plugin.js b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/lib/locomotive_media-plugin.js new file mode 100644 index 00000000..0edfc470 --- /dev/null +++ b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/lib/locomotive_media-plugin.js @@ -0,0 +1,96 @@ +define( + ['aloha/jquery', 'aloha/plugin', 'aloha/floatingmenu', 'i18n!aloha/nls/i18n', 'i18n!locomotive_media/nls/i18n', 'css!locomotive_media/css/image.css'], + function(aQuery, Plugin, FloatingMenu, i18nCore, i18n) { + var jQuery = aQuery; + var $ = aQuery; + var GENTICS = window.GENTICS, Aloha = window.Aloha; + + return Plugin.create('locomotive_media', { + init: function() { + FloatingMenu.createScope(this.name, 'Aloha.continuoustext'); + + this._addUIInsertButton(i18nCore.t('floatingmenu.tab.insert')); + }, + + openDialog: function() { + var that = this; + var picker = window.parent.application_view.content_assets_picker_view; + + picker.options.on_select = function(asset) { + if (asset.get('image') == true) + that.insertImg(asset); + else + that.insertLink(asset); + + picker.close(); + } + + picker.render() + }, + + /** + * This method will insert a new image dom element into the dom tree + */ + insertImg: function(asset) { + var range = Aloha.Selection.getRangeObject(), + imageUrl = asset.get('url'), + imagestyle, imagetag, newImg; + + if (range.isCollapsed()) { + imagestyle = "max-width: " + asset.get('width') + "; max-height: " + asset.get('height'); + imagetag = ''; + newImg = jQuery(imagetag); + GENTICS.Utils.Dom.insertIntoDOM(newImg, range, jQuery(Aloha.activeEditable.obj)); + } else { + Aloha.Log.error('media cannot markup a selection'); + } + }, + + /** + * This method will insert a new link dom element into the dom tree + */ + insertLink: function(asset) { + var range = Aloha.Selection.getRangeObject(), + linkText = asset.get('filename'), + linkUrl = asset.get('url'), + linktag, newLink; + + if (range.isCollapsed()) { + linktag = '' + linkText + ''; + newLink = jQuery(linktag); + GENTICS.Utils.Dom.insertIntoDOM(newLink, range, jQuery(Aloha.activeEditable.obj)); + range.startContainer = range.endContainer = newLink.contents().get(0); + range.startOffset = 0; + range.endOffset = linkText.length; + } else { + linktag = ''; + newLink = jQuery(linktag); + GENTICS.Utils.Dom.addMarkup(range, newLink, false); + } + }, + + /** + * Adds the insert button to the floating menu + */ + _addUIInsertButton: function(tabId) { + var that = this; + this.insertMediaButton = new Aloha.ui.Button({ + 'name' : 'insertlocomotivemedia', + 'iconClass': 'aloha-button aloha-locomotive-media-insert', + 'size' : 'small', + 'onclick' : function () { that.openDialog(); }, + 'tooltip' : i18n.t('button.addimg.tooltip'), + 'toggle' : false + }); + + FloatingMenu.addButton( + 'Aloha.continuoustext', + this.insertMediaButton, + tabId, + 1 + ); + }, + + }); + } +); \ No newline at end of file diff --git a/app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/fr/i18n.js b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/fr/i18n.js new file mode 100644 index 00000000..c43891b0 --- /dev/null +++ b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/fr/i18n.js @@ -0,0 +1 @@ +define({ 'button.addimg.tooltip': 'insérer média' }); diff --git a/app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/i18n.js b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/i18n.js new file mode 100644 index 00000000..317d57ce --- /dev/null +++ b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/nls/i18n.js @@ -0,0 +1,4 @@ +define({ + root: { "button.addimg.tooltip": "insert media" }, + fr: true +}); diff --git a/app/assets/javascripts/aloha/plugins/custom/locomotive_media/package.json b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/app/assets/javascripts/aloha/plugins/custom/locomotive_media/package.json @@ -0,0 +1 @@ +{} diff --git a/app/assets/javascripts/locomotive/aloha.js.coffee b/app/assets/javascripts/locomotive/aloha.js.coffee index 2e6a956c..f2d488f2 100644 --- a/app/assets/javascripts/locomotive/aloha.js.coffee +++ b/app/assets/javascripts/locomotive/aloha.js.coffee @@ -1,2 +1,7 @@ #= require ./utils/aloha_settings #= require aloha + + +# r equire_tree ./../aloha/plugins + +# . /.. / aloha / plugins \ No newline at end of file diff --git a/app/assets/javascripts/locomotive/inline_editor.js.coffee b/app/assets/javascripts/locomotive/inline_editor.js.coffee index 51c3057f..6d4e8a48 100644 --- a/app/assets/javascripts/locomotive/inline_editor.js.coffee +++ b/app/assets/javascripts/locomotive/inline_editor.js.coffee @@ -12,6 +12,7 @@ #= require_self #= require_tree ./utils #= require_tree ./models +#= require_tree ./views/content_assets #= require_tree ./views/inline_editor window.Locomotive = diff --git a/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee b/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee index 5beb6b5b..ea2e4b3f 100644 --- a/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee +++ b/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee @@ -23,6 +23,11 @@ window.Aloha.settings = editables: '.editable-short-text': [ ] + image: + ui: + insert: false + crop: false + i18n: available: ['en', 'fr', 'pt-BR', 'es', 'de', 'no', 'ru', 'nl'] diff --git a/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee b/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee index 53002e5e..2e3cb346 100644 --- a/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/inline_editor/application_view.js.coffee @@ -1,8 +1,8 @@ -Locomotive.Views.InlinEditor ||= {} +Locomotive.Views.InlineEditor ||= {} #= require ./toolbar_view -class Locomotive.Views.InlinEditor.ApplicationView extends Backbone.View +class Locomotive.Views.InlineEditor.ApplicationView extends Backbone.View el: 'body' @@ -13,7 +13,9 @@ class Locomotive.Views.InlinEditor.ApplicationView extends Backbone.View _.bindAll(@, '_$') - @toolbar_view = new Locomotive.Views.InlinEditor.ToolbarView(target: @iframe) + @toolbar_view = new Locomotive.Views.InlineEditor.ToolbarView(target: @iframe) + + @content_assets_picker_view = new Locomotive.Views.ContentAssets.PickerView(collection: new Locomotive.Models.ContentAssetsCollection()) render: -> super @@ -74,7 +76,7 @@ class Locomotive.Views.InlinEditor.ApplicationView extends Backbone.View _jQuery('a').each -> link = _jQuery(this) url = link.attr('href') - if url? && url.indexOf('#') != 0 && /^(www|http)/.exec(url) == null && /(\/_edit)$/.exec(url) == null + if url? && url.indexOf('#') != 0 && /^(www|http)/.exec(url) == null && /(\/_edit)$/.exec(url) == null && /^\/sites\//.exec(url) == null url = '/index' if url == '/' unless url.indexOf('_edit') > 0 diff --git a/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee b/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee index 68d9e6c2..e2efbfd7 100644 --- a/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee @@ -1,6 +1,6 @@ -Locomotive.Views.InlinEditor ||= {} +Locomotive.Views.InlineEditor ||= {} -class Locomotive.Views.InlinEditor.ToolbarView extends Backbone.View +class Locomotive.Views.InlineEditor.ToolbarView extends Backbone.View el: '#toolbar .inner' diff --git a/app/assets/stylesheets/locomotive/backoffice/application.css.scss b/app/assets/stylesheets/locomotive/backoffice/application.css.scss index 4f98f454..0f2c51a5 100644 --- a/app/assets/stylesheets/locomotive/backoffice/application.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/application.css.scss @@ -33,24 +33,6 @@ /* ___ list ___ */ -p.no-items { - background: #fffbe6; - border: 5px solid #eee3a8; - @include border-radius(25px); - - padding: 15px 0px; - - text-align: center; - color: #9d8963; - font-size: 16px !important; - @include single-text-shadow(rgba(255, 255, 255, 1), 1px, 1px, 1px); - - a { - @include hover-link; - color: #ff2900; - } -} - ul.list { background: #fff; list-style: none; @@ -346,19 +328,3 @@ p span.code { color: #8B8D9A; @include single-text-shadow(#fff, 0px, 0px, 1px); } - -/* ___ quick upload ___ */ - -form.quick-upload { - display: inline; - - input[type=file] { - visibility: hidden; - } - -} - - - - - diff --git a/app/assets/stylesheets/locomotive/backoffice/content_assets.css.scss b/app/assets/stylesheets/locomotive/backoffice/content_assets.css.scss index 63be3fa1..69b556ee 100644 --- a/app/assets/stylesheets/locomotive/backoffice/content_assets.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/content_assets.css.scss @@ -6,6 +6,10 @@ ul.content-assets { + list-style: none; + margin: 0px; + padding: 0px; + li.asset { position: relative; float: left; diff --git a/app/assets/stylesheets/locomotive/inline_editor.css b/app/assets/stylesheets/locomotive/inline_editor.css index e54c4713..508fbad6 100644 --- a/app/assets/stylesheets/locomotive/inline_editor.css +++ b/app/assets/stylesheets/locomotive/inline_editor.css @@ -3,7 +3,10 @@ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at * the top of the compiled file, but it's generally better to create a new file per style scope. *= require locomotive/blueprint/screen.css + *= require locomotive/jquery *= require locomotive/toggle.css + *= require locomotive/backoffice/dialog_changes.css + *= require locomotive/backoffice/content_assets.css *= require_tree ./shared *= require_tree ./inline_editor */ \ No newline at end of file diff --git a/app/assets/stylesheets/locomotive/shared/common.css.scss b/app/assets/stylesheets/locomotive/shared/common.css.scss new file mode 100644 index 00000000..43f076e8 --- /dev/null +++ b/app/assets/stylesheets/locomotive/shared/common.css.scss @@ -0,0 +1,34 @@ +@import "compass/css3/border-radius"; +@import "compass/css3/text-shadow"; +@import "locomotive/shared/helpers"; + +/* ___ quick upload ___ */ + +form.quick-upload { + display: inline; + + input[type=file] { + visibility: hidden; + } + +} + +/* ___ list ___ */ + +p.no-items { + background: #fffbe6; + border: 5px solid #eee3a8; + @include border-radius(25px); + + padding: 15px 0px; + + text-align: center; + color: #9d8963; + font-size: 16px !important; + @include single-text-shadow(rgba(255, 255, 255, 1), 1px, 1px, 1px); + + a { + @include hover-link; + color: #ff2900; + } +} \ No newline at end of file diff --git a/app/presenters/locomotive/content_asset_presenter.rb b/app/presenters/locomotive/content_asset_presenter.rb index 939cd516..afce9e53 100644 --- a/app/presenters/locomotive/content_asset_presenter.rb +++ b/app/presenters/locomotive/content_asset_presenter.rb @@ -1,7 +1,7 @@ module Locomotive class ContentAssetPresenter < BasePresenter - delegate :content_type, :vignette_url, :to => :source + delegate :content_type, :width, :height, :vignette_url, :to => :source def full_filename self.source.source_filename @@ -29,7 +29,7 @@ module Locomotive end def included_methods - super + %w(full_filename filename short_name extname content_type content_type_text url vignette_url) + super + %w(full_filename filename short_name extname content_type content_type_text url vignette_url width height) end end diff --git a/app/views/locomotive/public/pages/show_toolbar.html.haml b/app/views/locomotive/public/pages/show_toolbar.html.haml index 6bc1857e..909ac165 100644 --- a/app/views/locomotive/public/pages/show_toolbar.html.haml +++ b/app/views/locomotive/public/pages/show_toolbar.html.haml @@ -25,11 +25,13 @@ $(document).ready(function() { - window.application_view = new Locomotive.Views.InlinEditor.ApplicationView(); + window.application_view = new Locomotive.Views.InlineEditor.ApplicationView(); window.application_view.render(); }); + = render '/locomotive/content_assets/picker' + %body #page %iframe{ :src => request.fullpath.gsub('_admin', '_edit'), :scrolling => 'no', :frameborder => '0' } diff --git a/lib/locomotive/liquid/tags/inline_editor.rb b/lib/locomotive/liquid/tags/inline_editor.rb index 7b9a87f2..3e429910 100644 --- a/lib/locomotive/liquid/tags/inline_editor.rb +++ b/lib/locomotive/liquid/tags/inline_editor.rb @@ -8,7 +8,7 @@ module Liquid controller = context.registers[:controller] - plugins = 'common/format,common/table,common/list,common/link,common/highlighteditables,common/block,common/undo,common/contenthandler,common/paste,common/commands,common/abbr,common/horizontalruler' + plugins = 'common/format,common/table,common/list,common/link,common/highlighteditables,common/block,common/undo,common/contenthandler,common/paste,common/commands,common/abbr,common/align,common/horizontalruler,custom/locomotive_media' %{ diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 4463f05d..a4e74043 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |s| s.add_dependency 'rails-backbone', '~> 0.6.1' s.add_dependency 'codemirror-rails', '~> 2.21' s.add_dependency 'locomotive-tinymce-rails', '~> 3.4.7.2' - s.add_dependency 'locomotive-aloha-rails', '~> 0.20.1.2' + s.add_dependency 'locomotive-aloha-rails', '~> 0.20.1.3' s.add_dependency 'flash_cookie_session', '~> 1.1.1' s.add_dependency 'locomotive_liquid', '2.2.2' From 57b7cc1ef22cd552029a9cd82af87a171e64229a Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sun, 22 Apr 2012 01:27:07 +0200 Subject: [PATCH 55/65] just a quick test to demonstrate the documentation was wrong (issue #377) --- spec/lib/locomotive/liquid/filters/date_spec.rb | 6 ++++++ spec/lib/locomotive/liquid/filters/resize_spec.rb | 2 ++ 2 files changed, 8 insertions(+) diff --git a/spec/lib/locomotive/liquid/filters/date_spec.rb b/spec/lib/locomotive/liquid/filters/date_spec.rb index 657afd4b..a6ef522b 100644 --- a/spec/lib/locomotive/liquid/filters/date_spec.rb +++ b/spec/lib/locomotive/liquid/filters/date_spec.rb @@ -35,4 +35,10 @@ describe Locomotive::Liquid::Filters::Date do format_date(@date).should == '06/29/2007' end + it 'prints a date within a template (from the documentation)' do + template = Liquid::Template.parse("{{ today | localized_date: '%d %B', 'fr' }}") + context = Liquid::Context.new({}, { 'today' => @date }, {}) + template.render(context).should == '29 juin' + end + end \ No newline at end of file diff --git a/spec/lib/locomotive/liquid/filters/resize_spec.rb b/spec/lib/locomotive/liquid/filters/resize_spec.rb index 1b2056a8..1f8e343d 100644 --- a/spec/lib/locomotive/liquid/filters/resize_spec.rb +++ b/spec/lib/locomotive/liquid/filters/resize_spec.rb @@ -47,6 +47,7 @@ describe Locomotive::Liquid::Filters::Resize do end context 'when no resize string is given' do + before :each do @template = Liquid::Template.parse('{{ asset | resize: }}') end @@ -54,6 +55,7 @@ describe Locomotive::Liquid::Filters::Resize do it 'returns a liquid error' do @template.render(@context).should include 'Liquid error: wrong number of arguments' end + end end end From ce5576da09a8759f1943c8f756cebc3e70f33b71 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sun, 22 Apr 2012 23:25:18 +0200 Subject: [PATCH 56/65] the extends tag was not looking for the right fullpath (when localization is enabled) + sample in order to modify the tinyMCE settings in the back-office --- .../javascripts/locomotive/aloha.js.coffee | 7 +------ lib/locomotive/liquid/tags/extends.rb | 4 +++- .../javascripts/locomotive_misc.js.coffee | 2 ++ .../shared/_main_app_head.html.haml | 1 + .../locomotive/liquid/tags/extends_spec.rb | 20 +++++++++++++++---- 5 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee create mode 100644 spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml diff --git a/app/assets/javascripts/locomotive/aloha.js.coffee b/app/assets/javascripts/locomotive/aloha.js.coffee index f2d488f2..c6c3b0c3 100644 --- a/app/assets/javascripts/locomotive/aloha.js.coffee +++ b/app/assets/javascripts/locomotive/aloha.js.coffee @@ -1,7 +1,2 @@ #= require ./utils/aloha_settings -#= require aloha - - -# r equire_tree ./../aloha/plugins - -# . /.. / aloha / plugins \ No newline at end of file +#= require aloha \ No newline at end of file diff --git a/lib/locomotive/liquid/tags/extends.rb b/lib/locomotive/liquid/tags/extends.rb index 3c49a4f1..634c60c0 100644 --- a/lib/locomotive/liquid/tags/extends.rb +++ b/lib/locomotive/liquid/tags/extends.rb @@ -27,8 +27,10 @@ module Locomotive @context[:parent_page] = @context[:page].parent end else + locale = ::Mongoid::Fields::I18n.locale + @context[:parent_page] = @context[:cached_pages].try(:[], @template_name) || - @context[:site].pages.where(:fullpath => @template_name).first + @context[:site].pages.where("fullpath.#{locale}" => @template_name).first end raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil? diff --git a/spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee b/spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee new file mode 100644 index 00000000..b3d4aca8 --- /dev/null +++ b/spec/dummy/app/assets/javascripts/locomotive_misc.js.coffee @@ -0,0 +1,2 @@ +# FIXME: just to demonstrate how easy it is to change the tinymce settings for the LocomotiveCMS back-office +# window.Locomotive.tinyMCE.defaultSettings.theme_advanced_buttons2 = 'formatselect,fontselect,fontsizeselect' \ No newline at end of file diff --git a/spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml b/spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml new file mode 100644 index 00000000..0d92fabb --- /dev/null +++ b/spec/dummy/app/views/locomotive/shared/_main_app_head.html.haml @@ -0,0 +1 @@ += javascript_include_tag 'locomotive_misc' diff --git a/spec/lib/locomotive/liquid/tags/extends_spec.rb b/spec/lib/locomotive/liquid/tags/extends_spec.rb index 0a53f54d..bc70568a 100644 --- a/spec/lib/locomotive/liquid/tags/extends_spec.rb +++ b/spec/lib/locomotive/liquid/tags/extends_spec.rb @@ -12,17 +12,29 @@ describe Locomotive::Liquid::Tags::Extends do end it 'works' do - lambda { + page = FactoryGirl.build(:page, :slug => 'sub_page_1', :parent => @home) + parse('parent', page).render.should == 'Hello world' + end + + it 'looks for the index with the right locale' do + ::Mongoid::Fields::I18n.with_locale 'fr' do + @home.raw_template = 'Bonjour le monde' + @home.send :serialize_template + end + + @site.pages.expects(:where).with('fullpath.fr' => 'index').returns([@home]) + + ::Mongoid::Fields::I18n.with_locale 'fr' do page = FactoryGirl.build(:page, :slug => 'sub_page_1', :parent => @home) - parse('parent', page) - }.should_not raise_error + parse('index', page).render.should == 'Bonjour le monde' + end end context '#errors' do it 'raises an error if the source page does not exist' do lambda { - @site.pages.expects(:where).with(:fullpath => 'foo').returns([]) + @site.pages.expects(:where).with('fullpath.en' => 'foo').returns([]) parse('foo') }.should raise_error(Locomotive::Liquid::PageNotFound, "Page with fullpath 'foo' was not found") end From 69c51fbe07fadb2b7301c2afdbc35f73d10ce3fd Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 23 Apr 2012 01:03:21 +0200 Subject: [PATCH 57/65] new aloha-rails gem (fixing a typo in a css when precompiling it) --- Gemfile.lock | 8 ++++---- locomotive_cms.gemspec | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9b36dfda..1c2ab25f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,7 +38,7 @@ PATH httparty (~> 0.8.1) jquery-rails (~> 1.0.16) kaminari (~> 0.13.0) - locomotive-aloha-rails (~> 0.20.1.3) + locomotive-aloha-rails (~> 0.20.1.4) locomotive-mongoid-tree (~> 0.6.2) locomotive-tinymce-rails (~> 3.4.7.2) locomotive_liquid (= 2.2.2) @@ -178,8 +178,8 @@ GEM haml (3.1.4) highline (1.6.11) hike (1.2.1) - httparty (0.8.2) - multi_json + httparty (0.8.3) + multi_json (~> 1.0) multi_xml i18n (0.6.0) journey (1.0.3) @@ -199,7 +199,7 @@ GEM addressable (~> 2.2.6) libwebsocket (0.1.3) addressable - locomotive-aloha-rails (0.20.1.3) + locomotive-aloha-rails (0.20.1.4) actionpack (~> 3.2.1) locomotive-mongoid-tree (0.6.2) mongoid (~> 2.0) diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index a4e74043..e5d6d902 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |s| s.add_dependency 'rails-backbone', '~> 0.6.1' s.add_dependency 'codemirror-rails', '~> 2.21' s.add_dependency 'locomotive-tinymce-rails', '~> 3.4.7.2' - s.add_dependency 'locomotive-aloha-rails', '~> 0.20.1.3' + s.add_dependency 'locomotive-aloha-rails', '~> 0.20.1.4' s.add_dependency 'flash_cookie_session', '~> 1.1.1' s.add_dependency 'locomotive_liquid', '2.2.2' From 0502cf3305286f66d050f189e4e486a6f8c929ed Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 23 Apr 2012 01:04:06 +0200 Subject: [PATCH 58/65] bump version to 2.0.0.rc7 --- Gemfile.lock | 2 +- lib/locomotive/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1c2ab25f..b4ce7be6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,7 +18,7 @@ GIT PATH remote: . specs: - locomotive_cms (2.0.0.rc6) + locomotive_cms (2.0.0.rc7) RedCloth (~> 4.2.8) actionmailer-with-request (~> 0.3.0) bson_ext (~> 1.5.2) diff --git a/lib/locomotive/version.rb b/lib/locomotive/version.rb index 6a4543b6..0a2f57c9 100644 --- a/lib/locomotive/version.rb +++ b/lib/locomotive/version.rb @@ -1,3 +1,3 @@ module Locomotive #:nodoc - VERSION = '2.0.0.rc6' + VERSION = '2.0.0.rc7' end From 9613058b97056e292e4d913d8263e08f4a0fec79 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Wed, 25 Apr 2012 19:09:46 +0200 Subject: [PATCH 59/65] improve the upgrade script (wip) --- script/{upgrade.rb => upgrade_v1.rb} | 133 +++++++++++++++++++++------ 1 file changed, 104 insertions(+), 29 deletions(-) rename script/{upgrade.rb => upgrade_v1.rb} (75%) diff --git a/script/upgrade.rb b/script/upgrade_v1.rb similarity index 75% rename from script/upgrade.rb rename to script/upgrade_v1.rb index 5bed8e39..06fa96f4 100755 --- a/script/upgrade.rb +++ b/script/upgrade_v1.rb @@ -7,10 +7,14 @@ end # ================ GLOBAL VARIABLES ============== -$database = 'locomotive_hosting_production' +$database_name = 'locomotive_engine_dev' +$database_host = 'localhost' +$database_port = '27017' +# $database_username = '' +# $database_password = '' -$default_locale = 'en' -# $locale_exceptions = {} +$default_locale = 'en' +$locale_exceptions = {} # Example: # $locale_exceptions = { @@ -20,33 +24,34 @@ $default_locale = 'en' # '4eb6aca89a976a0001000ebb' => 'fr' # } -def get_locale(site_id) - $locale_exceptions[site_id.to_s] || $default_locale -end +# no amazon S3 +$s3 = false + +# amazon S3 settings +# $s3 = true +# $s3_bucket = '' +# $fog_storage_settings = { +# :provider => 'AWS', +# :aws_secret_access_key => '', +# :aws_access_key_id => '' +# } # ================ MONGODB ============== require 'mongoid' Mongoid.configure do |config| - name = $database - host = 'localhost' - - # simple connection - # config.master = Mongo::Connection.new.db(name) - - # a more complicated connection - # config.master = Mongo::Connection.new('localhost', '27017', :logger => Logger.new($stdout)).db(name) - - # connection with authentication - # db = config.master = Mongo::Connection.new(host, '27019').db(name) - # db.authenticate('username', 'password').tap do |auth| - # puts auth.inspect - # end + db = config.master = Mongo::Connection.new($database_host, $database_port).db($database_name) + if $database_username && $database_password + db.authenticate($database_username, $database_password) + end end db = Mongoid.config.master +def get_locale(site_id) + $locale_exceptions[site_id.to_s] || $default_locale +end puts "***************************************" puts "[LocomotiveCMS] Upgrade from 1.0 to 2.0" @@ -84,15 +89,15 @@ if collection = db.collections.detect { |c| c.name == 'content_types' } locale = get_locale(content_type['site_id']) label_field_name = '' recipe = { 'name' => "Entry#{content_type['_id']}", 'version' => content_type['content_custom_fields_version'], 'rules' => [] } - rule_options = {} operations = { '$set' => {}, '$unset' => {} } contents = content_type['contents'] custom_fields = content_type['entries_custom_fields'] # fields custom_fields.each_with_index do |field, index| - name, type = field['_alias'], field['kind'].downcase - class_name = "Locomotive::Entry#{field['target'][-24,24]}" if field['target'] + name, type = field['_alias'], field['kind'].downcase + rule_options = {} + class_name = "Locomotive::Entry#{field['target'][-24,24]}" if field['target'] case field['kind'] when 'category' @@ -102,14 +107,15 @@ if collection = db.collections.detect { |c| c.name == 'content_types' } type = 'belongs_to' operations['$set'].merge!("entries_custom_fields.#{index}.type" => 'belongs_to') when 'has_many' - if field['reverse_lookup'] + if !field['reverse_lookup'].blank? type = 'has_many' operations['$set'].merge!("entries_custom_fields.#{index}.type" => 'has_many') # reverse_lookup -> inverse_of => hmmmmmmm - if _content_type = collection.find('_id' => BSON::ObjectId(field['target'][-24,24]).first) + if _content_type = collection.find('_id' => BSON::ObjectId(field['target'][-24,24])).first if _field = _content_type['entries_custom_fields'].detect { |f| f['_name'] == field['reverse_lookup'] } operations['$set'].merge!("entries_custom_fields.#{index}.inverse_of" => _field['_alias']) + rule_options['inverse_of'] = _field['_alias'] end end else @@ -124,6 +130,7 @@ if collection = db.collections.detect { |c| c.name == 'content_types' } "entries_custom_fields.#{index}.target" => '1', "entries_custom_fields.#{index}.reverse_lookup" => '1' }) + rule_options['class_name'] = class_name end if content_type['highlighted_field_name'] == field['_name'] @@ -184,7 +191,7 @@ if collection = db.collections.detect { |c| c.name == 'content_types' } # contents (contents || []).each_with_index do |content| - attributes = content.clone.keep_if { |k, v| %w(_id _slug seo_title meta_description meta_keywords _visible created_at updated_at).include?(k) } + attributes = content.clone.keep_if { |k, v| %w(_id _slug _visible created_at updated_at).include?(k) } attributes.merge!({ 'content_type_id' => content_type['_id'], 'site_id' => content_type['site_id'], @@ -194,21 +201,28 @@ if collection = db.collections.detect { |c| c.name == 'content_types' } 'custom_fields_recipe' => recipe }) + # localized attributes + %w(seo_title meta_description meta_keywords).each do |name| + attributes[name] = { locale => content[name] } + end + custom_fields.each do |field| name, _name = field['_alias'], field['_name'] case field['kind'] # string, text, boolean, date, file, category, has_many, has_one - when 'string', 'text', 'boolean', 'date' + when 'string', 'text', 'date' attributes[name] = content[_name] + when 'boolean' + attributes[name] = content[_name] == '1' when 'file' attributes[name] = content["#{_name}_filename"] when 'category', 'has_one' attributes["#{name}_id"] = content[_name] when 'has_many' - if field['reverse_lookup'] + if !field['reverse_lookup'].blank? # nothing to do else - attributes["#{name}_ids"] = content[_name] + attributes["#{name.singularize}_ids"] = (content[_name] || []).map { |_id| BSON::ObjectId(_id) } end end end @@ -286,6 +300,9 @@ if collection = db.collections.detect { |c| c.name == 'pages' } modifications, removals = {}, {} + modifications['locales'] = [locale] + modifications['response_type'] = 'text/html' + %w(title slug fullpath raw_template serialized_template template_dependencies snippet_dependencies seo_title meta_keywords meta_description).each do |attr| modifications[attr] = { locale => page[attr] } end @@ -299,6 +316,7 @@ if collection = db.collections.detect { |c| c.name == 'pages' } (page['editable_elements'] || []).each_with_index do |editable_element, index| modifications["editable_elements.#{index}._type"] = "Locomotive::#{editable_element['_type']}" modifications["editable_elements.#{index}.content"] = { locale => editable_element['content'] } + modifications["editable_elements.#{index}.locales"] = [locale] if editable_element['_type'] == 'EditableFile' modifications["editable_elements.#{index}.source"] = { locale => editable_element['source_filename'] } @@ -343,3 +361,60 @@ end %w(asset_collections liquid_templates delayed_backend_mongoid_jobs).each do |name| db.drop_collection name end + +# content entry assets +# +# Example: +# old sites/4c34fc86cc85f01e47000005/contents/content_instance/4dc15162ceedba763500011a/files/didier_plate.png +# new sites/4c34fc86cc85f01e47000005/content_entry{content_type_id}/4dc15162ceedba763500011a/files/didier_plate.png + +collection = db.collections.detect { |c| c.name == 'locomotive_content_entries' } + +if $s3 + # Amazon S3 (AWS) + require 'fog' + + connection = Fog::Storage.new($fog_storage_settings) + + bucket = connection.directories.detect { |d| d.key == $s3_bucket } + + bucket.files.each do |file| + if file.key =~ /^sites\/([a-f0-9]+)\/contents\/content_instance\/([a-f0-9]+)\/files/ + content_type_id = collection.find('_id' => BSON::ObjectId($2)).first['content_type_id'].to_s + new_key = file.key.gsub('contents/content_instance', "content_entry#{content_type_id}") + + puts "new file #{new_key}" + + # rename file by copying the original file to its new folder + bucket.files.create( + :key => new_key, + :body => file.body, + :public => true + ) + + file.destroy # delete the file forever + end + end +else + Dir[File.join(File.dirname(__FILE__), '..', 'public', 'sites', '**/*')].each do |path| + next if File.directory?(path) + + if path =~ /public\/sites\/([a-f0-9]+)\/contents\/content_instance\/([a-f0-9]+)\/files/ + content_type_id = collection.find('_id' => BSON::ObjectId($2)).first['content_type_id'].to_s + new_path = path.gsub('contents/content_instance', "content_entry#{content_type_id}") + + puts "new file #{new_path}" + + # create the target folder + FileUtils.mkdir_p(File.dirname(new_path)) + + FileUtils.mv(path, new_path) + end + end + + # do some cleaning + Dir[File.join(File.dirname(__FILE__), '..', 'public', 'sites', '*', 'contents')].each do |folder| + puts "remove folder #{folder}" + FileUtils.rm_rf folder + end +end From 23600edb1f4511b5e8da03dcc8c521c2ef740b2b Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Thu, 26 Apr 2012 03:39:23 +0200 Subject: [PATCH 60/65] performance improvements as described in #383 --- Gemfile.lock | 6 +++--- .../views/shared/fields/many_to_many_view.js.coffee | 4 ---- app/helpers/locomotive/content_types_helper.rb | 4 ++++ app/models/locomotive/content_entry.rb | 2 +- app/models/locomotive/extensions/page/tree.rb | 13 +++++++++++++ app/models/locomotive/site.rb | 6 +++++- app/presenters/locomotive/membership_presenter.rb | 9 +++++++-- app/presenters/locomotive/site_presenter.rb | 5 +++++ .../custom_fields/types/_many_to_many.html.haml | 10 +++++----- app/views/locomotive/shared/_head.html.haml | 2 +- locomotive_cms.gemspec | 2 +- spec/dummy/config/mongoid.yml | 3 +++ spec/models/locomotive/content_type_spec.rb | 11 +++++++++-- spec/models/locomotive/page_spec.rb | 5 +++-- spec/spec_helper.rb | 4 ++++ 15 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b4ce7be6..75a976bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,7 +44,7 @@ PATH locomotive_liquid (= 2.2.2) mimetype-fu (~> 0.1.2) mongo (~> 1.5.2) - mongoid (~> 2.4.6) + mongoid (~> 2.4.9) multi_json (= 1.2.0) rack-cache (~> 1.1) rails (~> 3.2.3) @@ -115,7 +115,7 @@ GEM childprocess (0.3.1) ffi (~> 1.0.6) chunky_png (1.2.5) - codemirror-rails (2.23) + codemirror-rails (2.24) railties (~> 3.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -215,7 +215,7 @@ GEM mocha (0.9.12) mongo (1.5.2) bson (= 1.5.2) - mongoid (2.4.8) + mongoid (2.4.9) activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) diff --git a/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee b/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee index 01c5c681..ab94fad7 100644 --- a/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee @@ -24,10 +24,6 @@ class Locomotive.Views.Shared.Fields.ManyToManyView extends Backbone.View @collection = @model.get(@options.name) @all_entries = @options.all_entries - window.collection = @collection - window.bar = @all_entries - window.model = @model - render: -> $(@el).html(@template()()) diff --git a/app/helpers/locomotive/content_types_helper.rb b/app/helpers/locomotive/content_types_helper.rb index 20eb07cf..443cde41 100644 --- a/app/helpers/locomotive/content_types_helper.rb +++ b/app/helpers/locomotive/content_types_helper.rb @@ -27,6 +27,10 @@ module Locomotive end visible << content_type + + end.each do |content_type| + # make sure to have a fresh copy of the content types because for now we don't have the full content types (ie: content_types.only(...)) + ::Mongoid::IdentityMap.remove(content_type) end if visible.size > 0 diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index 8273c46f..5be95ed7 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -86,7 +86,7 @@ module Locomotive end def as_json(options = {}) - self.to_presenter.as_json + self.to_presenter(options).as_json end protected diff --git a/app/models/locomotive/extensions/page/tree.rb b/app/models/locomotive/extensions/page/tree.rb index a1f97fa4..9edd58d3 100644 --- a/app/models/locomotive/extensions/page/tree.rb +++ b/app/models/locomotive/extensions/page/tree.rb @@ -19,6 +19,9 @@ module Locomotive ## indexes ## index :position index [[:depth, Mongo::ASCENDING], [:position, Mongo::ASCENDING]] + + alias_method_chain :rearrange, :identity_map + alias_method_chain :rearrange_children, :identity_map end module ClassMethods @@ -101,6 +104,16 @@ module Locomotive protected + def rearrange_with_identity_map + ::Mongoid::IdentityMap.clear + rearrange_without_identity_map + end + + def rearrange_children_with_identity_map + self.children.reset + rearrange_children_without_identity_map + end + def persist_depth self.attributes['depth'] = self.depth self.depth_will_change! diff --git a/app/models/locomotive/site.rb b/app/models/locomotive/site.rb index 51e3c5e2..b67db836 100644 --- a/app/models/locomotive/site.rb +++ b/app/models/locomotive/site.rb @@ -54,8 +54,12 @@ module Locomotive Locomotive::Liquid::Drops::Site.new(self) end + def to_presenter(options = {}) + Locomotive::SitePresenter.new(self, options) + end + def as_json(options = {}) - Locomotive::SitePresenter.new(self, options).as_json + self.to_presenter(options).as_json end protected diff --git a/app/presenters/locomotive/membership_presenter.rb b/app/presenters/locomotive/membership_presenter.rb index e0d82227..06b592b5 100644 --- a/app/presenters/locomotive/membership_presenter.rb +++ b/app/presenters/locomotive/membership_presenter.rb @@ -1,7 +1,7 @@ module Locomotive class MembershipPresenter < BasePresenter - delegate :role, :to => :source + delegate :role, :account_id, :to => :source def name self.source.account.name @@ -26,8 +26,13 @@ module Locomotive end def included_methods - super + %w(name email role role_name can_update grant_admin) + super + %w(account_id name email role role_name can_update grant_admin) end + # def light_as_json + # methods = included_methods.clone - %w(name email) + # self.as_json(methods) + # end + end end \ No newline at end of file diff --git a/app/presenters/locomotive/site_presenter.rb b/app/presenters/locomotive/site_presenter.rb index 272571be..406002ee 100644 --- a/app/presenters/locomotive/site_presenter.rb +++ b/app/presenters/locomotive/site_presenter.rb @@ -15,5 +15,10 @@ module Locomotive super + %w(name locales domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships) end + def as_json_for_html_view + methods = included_methods.clone - %w(memberships) + self.as_json(methods) + end + end end \ No newline at end of file diff --git a/app/views/locomotive/custom_fields/types/_many_to_many.html.haml b/app/views/locomotive/custom_fields/types/_many_to_many.html.haml index 0aef925b..6680b1fa 100644 --- a/app/views/locomotive/custom_fields/types/_many_to_many.html.haml +++ b/app/views/locomotive/custom_fields/types/_many_to_many.html.haml @@ -1,10 +1,10 @@ - if field.ui_enabled? - target_content_type = Locomotive::ContentType.class_name_to_content_type(field.class_name, current_site) - = f.input name.to_sym, - :label => field.label, - :hint => field.hint, - :as => :'Locomotive::Empty', + = f.input name.to_sym, + :label => field.label, + :hint => field.hint, + :as => :'Locomotive::Empty', :wrapper_html => { :id => "content_entry_#{name}_input", :class => 'empty relationship input' } - content_for :head do @@ -38,4 +38,4 @@ - content_for :backbone_view_data do :plain - , all_#{name}_entries: #{target_content_type.list_or_group_entries.to_json} \ No newline at end of file + , all_#{name}_entries: #{target_content_type.list_or_group_entries.to_json(:depth => 1)} \ No newline at end of file diff --git a/app/views/locomotive/shared/_head.html.haml b/app/views/locomotive/shared/_head.html.haml index fb89e923..754413bd 100644 --- a/app/views/locomotive/shared/_head.html.haml +++ b/app/views/locomotive/shared/_head.html.haml @@ -19,7 +19,7 @@ window.locale = '#{I18n.locale}'; window.content_locale = '#{::Mongoid::Fields::I18n.locale}'; - Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_json}); + Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_presenter.as_json_for_html_view.to_json}); Locomotive.current_account = new Locomotive.Models.Account(#{current_locomotive_account.to_json}); $(document).ready(function() { diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index e5d6d902..8f58273b 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| s.add_dependency 'mongo', '~> 1.5.2' s.add_dependency 'bson_ext', '~> 1.5.2' - s.add_dependency 'mongoid', '~> 2.4.6' + s.add_dependency 'mongoid', '~> 2.4.9' s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2' s.add_dependency 'custom_fields', '~> 2.0.0.rc10' diff --git a/spec/dummy/config/mongoid.yml b/spec/dummy/config/mongoid.yml index 17611c5e..dabbe6ca 100644 --- a/spec/dummy/config/mongoid.yml +++ b/spec/dummy/config/mongoid.yml @@ -10,11 +10,14 @@ defaults: &defaults development: <<: *defaults database: locomotive_engine_dev + identity_map_enabled: true test: <<: *defaults database: locomotive_engine_test + identity_map_enabled: true production: <<: *defaults + identity_map_enabled: true database: locomotive_engine_production diff --git a/spec/models/locomotive/content_type_spec.rb b/spec/models/locomotive/content_type_spec.rb index b3114230..0e7911f9 100644 --- a/spec/models/locomotive/content_type_spec.rb +++ b/spec/models/locomotive/content_type_spec.rb @@ -131,7 +131,7 @@ describe Locomotive::ContentType do it 'updates the information about the order of a has_many relationship if the target class changes its order' do @content_type.order_by = 'description'; @content_type.order_direction = 'ASC'; @content_type.save! - @category_1 = @category_1.class.find(@category_1._id) + @category_1 = safe_find(@category_1.class, @category_1._id) @category_1.projects.metadata.order.should == %w(description ASC) @category_1.projects.map(&:name).should == %w(LocomotiveCMS RubyOnRails) @@ -139,7 +139,9 @@ describe Locomotive::ContentType do it 'uses the order by position if the UI option is enabled' do field = @category_content_type.entries_custom_fields.where(:name => 'projects').first - field.ui_enabled = true; @category_content_type.save!; @category_1 = @category_1.class.find(@category_1._id) + field.ui_enabled = true; + + @category_content_type.save!; @category_1 = safe_find(@category_1.class, @category_1._id) @category_1.projects.metadata.order.to_s.should == 'position_in_category' @category_1.projects.map(&:name).should == %w(LocomotiveCMS RubyOnRails) @@ -337,6 +339,11 @@ describe Locomotive::ContentType do end end + def safe_find(klass, id) + Mongoid::IdentityMap.clear + klass.find(id) + end + def build_content_entry(content_type) content_type.entries.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true) end diff --git a/spec/models/locomotive/page_spec.rb b/spec/models/locomotive/page_spec.rb index cbcf4ea6..b02075ad 100644 --- a/spec/models/locomotive/page_spec.rb +++ b/spec/models/locomotive/page_spec.rb @@ -143,8 +143,8 @@ describe Locomotive::Page do describe 'tree organization' do before(:each) do - @home = FactoryGirl.create(:page) - @child_1 = FactoryGirl.create(:page, :title => 'Subpage 1', :slug => 'foo', :parent_id => @home._id, :site => @home.site) + @home = FactoryGirl.create(:page) + @child_1 = FactoryGirl.create(:page, :title => 'Subpage 1', :slug => 'foo', :parent_id => @home._id, :site => @home.site) end it 'adds root elements' do @@ -390,4 +390,5 @@ describe Locomotive::Page do def fake_bson_id(id) BSON::ObjectId(id.to_s.rjust(24, '0')) end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7256eb21..de9380c0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,6 +27,10 @@ RSpec.configure do |config| DatabaseCleaner.orm = 'mongoid' end + config.before(:each) do + Mongoid::IdentityMap.clear + end + config.before(:each) do DatabaseCleaner.clean end From f9a6155c19ccff333836da2dc65d4711e3f691ef Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Thu, 26 Apr 2012 04:00:46 +0200 Subject: [PATCH 61/65] content types can auto-reference them (in a many_to_many relationship for instance) --- app/helpers/locomotive/custom_fields_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/locomotive/custom_fields_helper.rb b/app/helpers/locomotive/custom_fields_helper.rb index 712884d2..1a46e8a3 100644 --- a/app/helpers/locomotive/custom_fields_helper.rb +++ b/app/helpers/locomotive/custom_fields_helper.rb @@ -44,7 +44,7 @@ module Locomotive def options_for_content_type current_site.content_types.map do |c| - c != @content_type ? [c.name, c.klass_with_custom_fields(:entries).to_s] : nil + [c.name, c.klass_with_custom_fields(:entries).to_s] end.compact end From a8646e7ef3cefb5786ad973f0d4fefc8ff5c890a Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Thu, 26 Apr 2012 12:12:55 +0200 Subject: [PATCH 62/65] date picker was not correctly displayed in the popup form (has_many relationship) + previous form errors remained even within a fresh new popup --- .../views/content_entries/_popup_form_view.js.coffee | 2 ++ .../stylesheets/locomotive/backoffice/datepicker.css.scss | 2 +- .../locomotive/backoffice/dialog_changes.css.scss | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/locomotive/views/content_entries/_popup_form_view.js.coffee b/app/assets/javascripts/locomotive/views/content_entries/_popup_form_view.js.coffee index 975e587a..b7c8f94c 100644 --- a/app/assets/javascripts/locomotive/views/content_entries/_popup_form_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/content_entries/_popup_form_view.js.coffee @@ -50,6 +50,8 @@ class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.Con parent_el.find('.new-section').hide() parent_el.find('.edit-section').show() + @clear_errors() + $(@el).dialog('open') close: (event) -> diff --git a/app/assets/stylesheets/locomotive/backoffice/datepicker.css.scss b/app/assets/stylesheets/locomotive/backoffice/datepicker.css.scss index 81dc01d3..d1fcfa32 100644 --- a/app/assets/stylesheets/locomotive/backoffice/datepicker.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/datepicker.css.scss @@ -8,7 +8,7 @@ width: auto; - z-index: 999 !important; + z-index: 1001 !important; background: #f1f1f1; diff --git a/app/assets/stylesheets/locomotive/backoffice/dialog_changes.css.scss b/app/assets/stylesheets/locomotive/backoffice/dialog_changes.css.scss index c400569d..bf719788 100644 --- a/app/assets/stylesheets/locomotive/backoffice/dialog_changes.css.scss +++ b/app/assets/stylesheets/locomotive/backoffice/dialog_changes.css.scss @@ -84,6 +84,12 @@ width: 530px; } } // li.string + + li.date { + input[type=text] { + width: 90px; + } + } // li.string } } } // .form.formtastic From f42fb1afe1fe95cbd8670e9334247a32cc2385e0 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sat, 5 May 2012 11:17:18 +0200 Subject: [PATCH 63/65] finally the new version of the multi_json gem (issue #387) --- Gemfile.lock | 26 +++++++++++++------------- locomotive_cms.gemspec | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 75a976bc..5c90f438 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ PATH mimetype-fu (~> 0.1.2) mongo (~> 1.5.2) mongoid (~> 2.4.9) - multi_json (= 1.2.0) + multi_json (~> 1.3.4) rack-cache (~> 1.1) rails (~> 3.2.3) rails-backbone (~> 0.6.1) @@ -88,7 +88,7 @@ GEM activesupport (3.2.3) i18n (~> 0.6) multi_json (~> 1.0) - addressable (2.2.7) + addressable (2.2.8) arel (3.0.2) bcrypt-ruby (3.0.1) bson (1.5.2) @@ -112,7 +112,7 @@ GEM cells (3.8.3) actionpack (~> 3.0) railties (~> 3.0) - childprocess (0.3.1) + childprocess (0.3.2) ffi (~> 1.0.6) chunky_png (1.2.5) codemirror-rails (2.24) @@ -149,7 +149,7 @@ GEM ejs (1.0.0) erubis (2.7.0) excon (0.13.4) - execjs (1.3.0) + execjs (1.3.1) multi_json (~> 1.0) factory_girl (2.5.2) activesupport (>= 2.3.9) @@ -186,8 +186,8 @@ GEM jquery-rails (1.0.19) railties (~> 3.0) thor (~> 0.14) - json (1.6.6) - json_spec (1.0.0) + json (1.7.0) + json_spec (1.0.3) multi_json (~> 1.0) rspec (~> 2.0) kaminari (0.13.0) @@ -219,7 +219,7 @@ GEM activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) - multi_json (1.2.0) + multi_json (1.3.4) multi_xml (0.4.4) net-scp (1.0.4) net-ssh (>= 1.99.1) @@ -280,23 +280,23 @@ GEM railties (>= 3.0) rspec (~> 2.8.0) ruby-hmac (0.4.0) - rubyzip (0.9.7) + rubyzip (0.9.8) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) - sass (3.1.15) + sass (3.1.17) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.21.1) + selenium-webdriver (2.21.2) childprocess (>= 0.2.5) ffi (~> 1.0) libwebsocket (~> 0.1.3) - multi_json (< 1.3) + multi_json (~> 1.0) rubyzip shoulda-matchers (1.1.0) activesupport (>= 3.0.0) - sprockets (2.1.2) + sprockets (2.1.3) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) @@ -310,7 +310,7 @@ GEM uglifier (1.2.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) - unicorn (4.2.1) + unicorn (4.3.1) kgio (~> 2.6) rack raindrops (~> 0.7) diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index 8f58273b..0f465c96 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -59,7 +59,7 @@ Gem::Specification.new do |s| s.add_dependency 'rack-cache', '~> 1.1' s.add_dependency 'mimetype-fu', '~> 0.1.2' - s.add_dependency 'multi_json', '1.2.0' + s.add_dependency 'multi_json', '~> 1.3.4' s.add_dependency 'httparty', '~> 0.8.1' s.add_dependency 'actionmailer-with-request', '~> 0.3.0' From e225ad22782b6d344dc41facc879e617b833152a Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Mon, 7 May 2012 00:31:59 +0200 Subject: [PATCH 64/65] fix issue #385 --- .../locomotive/extensions/content_type/default_values.rb | 2 +- spec/models/locomotive/content_type_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/locomotive/extensions/content_type/default_values.rb b/app/models/locomotive/extensions/content_type/default_values.rb index 9fee52b7..e70f0053 100644 --- a/app/models/locomotive/extensions/content_type/default_values.rb +++ b/app/models/locomotive/extensions/content_type/default_values.rb @@ -27,7 +27,7 @@ module Locomotive def set_label_field if @new_label_field_name.present? - self.label_field_id = self.entries_custom_fields.detect { |f| f.name == @new_label_field_name.underscore }._id + self.label_field_id = self.entries_custom_fields.detect { |f| f.name == @new_label_field_name.underscore }.try(:_id) end # unknown label_field_name, get the first one instead diff --git a/spec/models/locomotive/content_type_spec.rb b/spec/models/locomotive/content_type_spec.rb index 0e7911f9..4cda81d5 100644 --- a/spec/models/locomotive/content_type_spec.rb +++ b/spec/models/locomotive/content_type_spec.rb @@ -284,6 +284,13 @@ describe Locomotive::ContentType do lambda { asset.active_at }.should raise_error end + it 'removes the field used as the label when setting the original label_field_name value before' do + @content_type.label_field_name = 'name' + @content_type.entries_custom_fields.destroy_all :conditions => { :name => @content_type.label_field_name } + @content_type.save + @content_type.label_field_name.should == 'description' + end + it 'renames field label' do @content_type.entries_custom_fields[1].label = 'Simple description' @content_type.entries_custom_fields[1].name = nil From c0627bf8a70450e77b702be1303f13040a4d4f1f Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Tue, 8 May 2012 22:31:20 -0500 Subject: [PATCH 65/65] Fixed typo for bootstrap setting: `data-toogle` to `data-toggle` --- lib/locomotive/liquid/tags/nav.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locomotive/liquid/tags/nav.rb b/lib/locomotive/liquid/tags/nav.rb index 7dd2fbbe..f327e19d 100644 --- a/lib/locomotive/liquid/tags/nav.rb +++ b/lib/locomotive/liquid/tags/nav.rb @@ -95,7 +95,7 @@ module Locomotive if render_children_for_page?(page, depth) && bootstrap? css += ' dropdown' - link_options = %{ class="dropdown-toggle" data-toogle="dropdown"} + link_options = %{ class="dropdown-toggle" data-toggle="dropdown"} href = '#' caret = %{ } end