Merge remote-tracking branch 'origin/rails_3_1' into rails_3_1

This commit is contained in:
Mario Visic 2012-01-15 00:03:06 +10:30
commit a50715091d
43 changed files with 241 additions and 32 deletions

View File

@ -31,7 +31,7 @@ gem 'flash_cookie_session', '~> 1.1.1'
gem 'locomotive_liquid', '2.2.2', :require => 'liquid'
gem 'formtastic', '~> 2.0.2'
gem 'responders', '~> 0.6.4'
gem 'cells', '~> 3.7.0'
gem 'cells', '~> 3.7.1'
gem 'RedCloth', '~> 4.2.8'
gem 'sanitize', '~> 2.0.3'
gem 'highline', '~> 1.6.2'

View File

@ -295,7 +295,7 @@ DEPENDENCIES
cancan (~> 1.6.7)
capybara
carrierwave-mongoid (~> 0.1.3)
cells (~> 3.7.0)
cells (~> 3.7.1)
codemirror-rails
coffee-script (~> 2.2.0)
compass (~> 0.12.alpha.4)

View File

@ -13,8 +13,8 @@ class Locomotive.Models.CustomField extends Backbone.Model
toJSONForSave: ->
_.tap {}, (hash) =>
for key, value of @.toJSON()
hash[key] = value unless _.include(['select_options', 'type_text', 'text_formatting_text', 'created_at', 'updated_at'], key)
hash.select_options_attributes = @get('select_options').toJSONForSave() if @get('select_options')
hash[key] = value unless _.include(['select_options', 'type_text', 'text_formatting_text', 'undefined_text', 'undefined', 'created_at', 'updated_at'], key)
hash.select_options_attributes = @get('select_options').toJSONForSave() if @get('select_options')? && @get('select_options').length > 0
class Locomotive.Models.CustomFieldsCollection extends Backbone.Collection

View File

@ -22,5 +22,26 @@
var avoidDuplicateRegexp = new RegExp('[\\' + sep + ']{2,}', 'g');
return this.replace(/\s/g, sep).replace(alphaNumRegexp, '').replace(avoidDuplicateRegexp, sep).toLowerCase()
}
window.addParameterToURL = function(key, value) { // code from http://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript
key = encodeURIComponent(key); value = encodeURIComponent(value);
var kvp = document.location.search.substr(1).split('&');
var i = kvp.length; var x; while(i--) {
x = kvp[i].split('=');
if (x[0] == key) {
x[1] = value;
kvp[i] = x.join('=');
break;
}
}
if (i < 0) { kvp[kvp.length] = [key,value].join('='); }
//this will reload the page, it's likely better to store this until finished
document.location.search = kvp.join('&');
}
})();

View File

@ -11,6 +11,8 @@ class Locomotive.Views.ApplicationView extends Backbone.View
@enable_sites_picker()
@enable_content_locale_picker()
# render page view
if @options.view?
@view = new @options.view(@options.view_data || {})
@ -66,3 +68,17 @@ class Locomotive.Views.ApplicationView extends Backbone.View
event.stopPropagation() & event.preventDefault()
picker.toggle()
enable_content_locale_picker: ->
link = @$('#content-locale-picker-link')
picker = @$('#content-locale-picker')
return if picker.size() == 0
link.bind 'click', (event) ->
event.stopPropagation() & event.preventDefault()
picker.toggle()
picker.find('li span.text').bind 'click', (event) ->
locale = $(event.target).html()
window.addParameterToURL 'content_locale', locale

View File

@ -12,6 +12,8 @@ class Locomotive.Views.ContentTypes.FormView extends Locomotive.Views.Shared.For
initialize: ->
@model = new Locomotive.Models.ContentType(@options.content_type)
window.foo = @model
Backbone.ModelBinding.bind @
render: ->

View File

@ -28,6 +28,7 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View
return @
enable_behaviours: ->
@$('li.input.toggle input[type=checkbox]').checkToggle()
@render_select_options_view()
switch_to_type: ->

View File

@ -2,15 +2,11 @@
@import "compass/css3/border-radius";
@import "helpers";
#sites-picker {
@mixin picker {
position: absolute;
top: 97px;
margin: 5px 0 0 0;
padding: 0 0 0 0;
min-width: 160px;
z-index: 999;
@include border-radius(4px);
border: 1px solid #000;

View File

@ -5,7 +5,7 @@
margin-top: 13px;
font-size: 12px;
font-size: 13px;
font-weight: normal;
@include background-image(linear-gradient(top, #f0f0f0, #f9f9f9 4px, #f9f9f9 4px, #ffffff 12px, #ffffff));

View File

@ -0,0 +1,82 @@
@import "picker";
#content-locale-picker-link {
position: relative;
padding-left: 10px !important;
padding-right: 25px !important;
cursor: pointer;
.hand {
position: absolute;
top: 7px;
right: 7px;
height: 7px;
width: 12px;
background: transparent image-url("locomotive/menu/icons.png") no-repeat 0px -16px;
}
img.flag {
float: left;
position: relative;
top: 1px;
width: 20px;
height: 20px;
margin-right: 7px;
}
span.text {
position: relative;
color: #fff;
font-size: 11px;
text-shadow: 1px 1px 1px #000;
text-transform: uppercase;
}
.others {
display: none;
}
}
#content-locale-picker {
@include picker;
display: none;
top: 152px;
right: 22px;
min-width: 63px;
z-index: 999;
li {
height: 26px;
padding: 2px 8px !important;
img.flag {
position: relative;
top: 1px;
margin-right: 5px;
}
span.text {
position: relative;
top: -6px;
text-transform: uppercase;
}
&:last-child {
border-bottom: 0px;
@include box-shadow(transparent 0 0 0 0);
}
}
}

View File

@ -56,7 +56,7 @@
@include box-shadow(rgba(0, 0, 0, 0.3) 0px -1px 10px 0px, rgba(0, 0, 0, 0.2) 0px 4px 6px 4px, rgba(255, 255, 255, 0.2) 0 1px 0 0 inset);
@include background-image(linear-gradient(#3f3f45, #23242b));
& > ul > li > a, & > .action a {
& > ul > li > a, & > .actions .button {
border: 1px solid rgba(0, 0, 0, 0.2);
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.6);
@ -72,8 +72,8 @@
}
}
& > .action {
a:hover {
& > .actions {
.button:hover {
border: 1px solid rgba(255, 255, 255, 0.5);
}
}

View File

@ -108,22 +108,29 @@
} // > li
} // > ul
& > .action {
& > .actions {
@include absolute-position(top, 0px, right, 12px);
height: 58px;
padding-left: 20px;
padding-top: 17px;
padding-left: 10px;
z-index: 1;
border-left: 1px solid rgba(0, 0, 0, 0.3);
@include box-shadow(rgba(255, 255, 255, 0.1) 1px 0 0 0 inset);
a {
.action {
display: block;
float: left;
margin-left: 10px;
}
.button {
display: inline-block;
height: 20px;
line-height: 20px;
height: 22px;
line-height: 22px;
margin: 17px 0 0 0;
margin: 0 0 0 0;
padding: 0px 10px 0 15px;
@include border-radius(10px);

View File

@ -0,0 +1,12 @@
@import "picker";
#sites-picker {
@include picker;
top: 97px;
margin: 5px 0 0 0;
min-width: 160px;
z-index: 999;
}

View File

@ -0,0 +1,7 @@
#content-locale-picker
%ul
- @locales.each do |locale|
%li
= image_tag "locomotive/icons/flags/#{locale}.png", :class => 'flag'
%span.text= locale

View File

@ -0,0 +1,15 @@
class Locomotive::ContentLocalePickerCell < Cell::Base
def show(args)
site = args[:site]
locale = args[:locale].to_s
if site.locales.empty? || site.locales.size < 2
''
else
@locales = site.locales - [locale]
render
end
end
end

View File

@ -15,7 +15,9 @@ module Locomotive
load_and_authorize_resource
before_filter :set_locale
before_filter :set_back_office_locale
before_filter :set_current_content_locale
before_filter :set_current_thread_variables

View File

@ -25,6 +25,10 @@ module Locomotive
self.locales.first || Locomotive.config.site_locales.first
end
def locale_fallbacks(locale)
[locale.to_s] + (locales - [locale.to_s])
end
# protected
#
# def add_missing_locales_for_all_pages

View File

@ -98,7 +98,7 @@ module Locomotive
return if self.site.nil? || self.site.destroyed?
if self.index? || self.not_found?
self.errors[:base] << I18n.t('errors.messages.protected_page')
self.errors[:base] << ::I18n.t('errors.messages.protected_page')
end
self.errors.empty?
@ -110,7 +110,7 @@ module Locomotive
end
def set_default_raw_template
self.raw_template ||= I18n.t('attributes.defaults.pages.other.body')
self.raw_template ||= ::I18n.t('attributes.defaults.pages.other.body')
end
end

View File

@ -40,6 +40,8 @@
= g.input :hint, :input_html => { :class => 'hint' }
= g.input :localized, :as => :'Locomotive::Toggle', :input_html => { :class => 'localized' }
= g.input :select_options, :as => :'Locomotive::Empty', :wrapper_html => { :class => 'extra select-options', :style => 'display: none' }
= g.input :text_formatting, :as => :select, :collection => options_for_text_formatting, :include_blank => false, :wrapper_html => { :class => 'extra text-formatting' }, :input_html => { :class => 'text_formatting' }

View File

@ -15,7 +15,7 @@
= yield :submenu
- if content_for? :actions
.action
.actions
= yield :actions
#content

View File

@ -9,7 +9,6 @@ xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
@pages.each do |page|
if not page.index_or_not_found?
if page.templatized?
page.content_type.entries.visible.each do |c|
xml.url do
xml.loc page_url(page, { :content => c, :host => true })

View File

@ -13,4 +13,6 @@
- if can?(:manage, Locomotive::Site)
%p.action
= link_to t('locomotive.sites_picker.new'), new_site_url
= link_to t('locomotive.sites_picker.new'), new_site_url
= render_cell 'locomotive/content_locale_picker', :show, :site => current_site, :locale => current_content_locale

View File

@ -1,2 +1,13 @@
- if can? :manage, Locomotive::ContentType
= link_to content_tag(:em) + content_tag(:span, t('locomotive.content_types.index.new')), new_content_type_url
.action
= link_to content_tag(:em) + content_tag(:span, t('locomotive.content_types.index.new')), new_content_type_url, :class => 'button'
- if current_site.locales.size > 1
.action
= link_to '#', :id => 'content-locale-picker-link', :class => 'button' do
%span.hand
&nbsp;
= image_tag "locomotive/icons/flags/#{current_content_locale}.png", :class => 'flag'
%span.text= current_content_locale

View File

@ -68,8 +68,15 @@ x edit my site
- custom_fields: use the appropriate icon to drag select options
- i18n
x add locales a site responds to
- locale switcher
x locale switcher
- back to default locale (if changed in settings)
- front
- inline editor
- remove inline-editor tag
- rack
- iframe
- bugs:
- unable to toggle the "required" check_boxes for content types
- disallow to click twice on the submit form button (spinner ?)
- message to notify people if their browser is too old

View File

@ -5,13 +5,36 @@ module Locomotive
extend ActiveSupport::Concern
included do
helper_method :current_site_public_url, :switch_to_site_url, :public_page_url
helper_method :current_site_public_url, :switch_to_site_url, :public_page_url, :current_content_locale
end
module InstanceMethods
def set_locale
I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale
# ___ locales ___
def current_content_locale
::Mongoid::Fields::I18n.locale
end
def set_current_content_locale
if params[:content_locale].present?
session[:content_locale] = params[:content_locale]
end
unless current_site.locales.include?(session[:content_locale])
session[:content_locale] = current_site.default_locale
end
::Mongoid::Fields::I18n.locale = session[:content_locale]
(current_site.locales || []).each do |locale|
::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale))
end
logger.debug "*** content locale = #{session[:content_locale]} / #{::Mongoid::Fields::I18n.locale}"
end
def set_back_office_locale
::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale
end
def sections(key = nil)

View File

@ -1,3 +1,3 @@
require 'locomotive/mongoid/document'
require 'locomotive/mongoid/model_extensions'
require 'locomotive/mongoid/patches'
require 'locomotive/mongoid/patches'

View File

@ -1,6 +1,6 @@
Rails.application.routes.draw do
mount Locomotive::Engine => '/locomotive'
mount Locomotive::Engine => '/locomotive', :as => 'locomotive'
match '/foo' => 'foo#index', :as => 'foo'