implement the mechanism to pick a different locale for content types + implement multi-language for content types + rename scss files to css.scss
This commit is contained in:
commit
0489bbe4c2
11
Gemfile
11
Gemfile
@ -6,25 +6,24 @@ gem 'rake', '0.9.2'
|
||||
|
||||
gem 'rails', '~> 3.1.3'
|
||||
|
||||
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'# FIXME: waiting for the new devise gem coming soon
|
||||
gem 'devise', '~> 1.5.3'
|
||||
gem 'cancan', '~> 1.6.7'
|
||||
|
||||
gem 'bson_ext', '~> 1.4.0'
|
||||
gem 'mongoid', '~> 2.3.3'
|
||||
gem 'mongo', '~> 1.5.2'
|
||||
gem 'bson_ext', '~> 1.5.2'
|
||||
gem 'mongoid', '~> 2.4.0'
|
||||
gem 'locomotive_mongoid_acts_as_tree', :git => 'git@github.com:locomotivecms/mongoid_acts_as_tree.git'
|
||||
# gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git'
|
||||
gem 'custom_fields', :path => '../gems/custom_fields' # DEV
|
||||
# gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => 'experimental'
|
||||
gem 'kaminari'
|
||||
|
||||
gem 'haml', '~> 3.1.3'
|
||||
gem 'sass-rails', '~> 3.1.4'
|
||||
gem "compass", :git => 'git://github.com/chriseppstein/compass.git'
|
||||
gem 'coffee-script', '~> 2.2.0'
|
||||
gem 'uglifier', '~> 1.0.4'
|
||||
gem 'compass', '~> 0.12.alpha.4'
|
||||
gem 'jquery-rails', '~> 1.0.16'
|
||||
gem 'rails-backbone', '0.5.4'
|
||||
gem 'handlebars-rails', :git => 'git://github.com/yabawock/handlebars-rails.git'
|
||||
gem 'codemirror-rails'
|
||||
gem 'tinymce-rails'
|
||||
gem 'flash_cookie_session', '~> 1.1.1'
|
||||
|
121
Gemfile.lock
121
Gemfile.lock
@ -1,27 +1,3 @@
|
||||
GIT
|
||||
remote: git://github.com/chriseppstein/compass.git
|
||||
revision: 79d94647f9a00b06c4a83db02e86f5d404569baf
|
||||
specs:
|
||||
compass (0.12.alpha.1.79d9464)
|
||||
chunky_png (~> 1.2)
|
||||
fssm (>= 0.2.7)
|
||||
sass (~> 3.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/plataformatec/devise.git
|
||||
revision: ede004169c6af7416f8c4e3fc29a653bee133f60
|
||||
specs:
|
||||
devise (1.5.1)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.0.3)
|
||||
warden (~> 1.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/yabawock/handlebars-rails.git
|
||||
revision: a09077aa91f10e08403af84586b2f2f0b38d9e2f
|
||||
specs:
|
||||
handlebars-rails (0.9.1)
|
||||
|
||||
GIT
|
||||
remote: git@github.com:locomotivecms/mongoid_acts_as_tree.git
|
||||
revision: ca494d22c3d7946385aba1153c017d9c30e9f9d3
|
||||
@ -34,12 +10,12 @@ PATH
|
||||
custom_fields (2.0.0.rc1)
|
||||
activesupport (~> 3.1.3)
|
||||
carrierwave-mongoid (~> 0.1.3)
|
||||
mongoid (~> 2.3.4)
|
||||
mongoid (~> 2.4.0)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
RedCloth (4.2.8)
|
||||
RedCloth (4.2.9)
|
||||
SystemTimer (1.2.3)
|
||||
ZenTest (4.6.2)
|
||||
actionmailer (3.1.3)
|
||||
@ -77,8 +53,9 @@ GEM
|
||||
autotest (4.4.6)
|
||||
ZenTest (>= 4.4.1)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bson (1.4.0)
|
||||
bson_ext (1.4.0)
|
||||
bson (1.5.2)
|
||||
bson_ext (1.5.2)
|
||||
bson (= 1.5.2)
|
||||
builder (3.0.0)
|
||||
bushido (0.0.35)
|
||||
highline (>= 1.6.1)
|
||||
@ -101,23 +78,28 @@ GEM
|
||||
cells (3.7.1)
|
||||
actionpack (~> 3.0)
|
||||
railties (~> 3.0)
|
||||
childprocess (0.2.2)
|
||||
childprocess (0.2.8)
|
||||
ffi (~> 1.0.6)
|
||||
chunky_png (1.2.5)
|
||||
codemirror-rails (0.3.1)
|
||||
codemirror-rails (0.3.2)
|
||||
railties (~> 3.0)
|
||||
coffee-script (2.2.0)
|
||||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.1.3)
|
||||
cucumber (1.1.3)
|
||||
coffee-script-source (1.2.0)
|
||||
compass (0.12.alpha.4)
|
||||
chunky_png (~> 1.2)
|
||||
fssm (>= 0.2.7)
|
||||
sass (~> 3.1)
|
||||
cucumber (1.1.4)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (>= 1.1.2)
|
||||
gherkin (~> 2.6.7)
|
||||
gherkin (~> 2.7.1)
|
||||
json (>= 1.4.6)
|
||||
term-ansicolor (>= 1.0.6)
|
||||
cucumber-rails (1.2.0)
|
||||
capybara (>= 1.1.1)
|
||||
cucumber (>= 1.1.1)
|
||||
cucumber-rails (1.2.1)
|
||||
capybara (>= 1.1.2)
|
||||
cucumber (>= 1.1.3)
|
||||
nokogiri (>= 1.5.0)
|
||||
database_cleaner (0.7.0)
|
||||
delayed_job (3.0.0)
|
||||
@ -125,15 +107,19 @@ GEM
|
||||
delayed_job_mongoid (1.0.8)
|
||||
delayed_job (~> 3.0.0)
|
||||
mongoid (>= 2.0)
|
||||
devise (1.5.3)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.0.3)
|
||||
warden (~> 1.1)
|
||||
diff-lcs (1.1.3)
|
||||
dragonfly (0.9.8)
|
||||
dragonfly (0.9.9)
|
||||
rack
|
||||
ejs (1.0.0)
|
||||
erubis (2.7.0)
|
||||
excon (0.7.8)
|
||||
execjs (1.2.9)
|
||||
excon (0.7.12)
|
||||
execjs (1.2.13)
|
||||
multi_json (~> 1.0)
|
||||
factory_girl (2.3.1)
|
||||
factory_girl (2.3.2)
|
||||
activesupport
|
||||
factory_girl_rails (1.4.0)
|
||||
factory_girl (~> 2.3.0)
|
||||
@ -154,25 +140,26 @@ GEM
|
||||
formatador (0.2.1)
|
||||
formtastic (2.0.2)
|
||||
rails (~> 3.0)
|
||||
fssm (0.2.7)
|
||||
gherkin (2.6.8)
|
||||
fssm (0.2.8.1)
|
||||
gherkin (2.7.2)
|
||||
json (>= 1.4.6)
|
||||
growl-glue (1.0.7)
|
||||
haml (3.1.3)
|
||||
highline (1.6.8)
|
||||
haml (3.1.4)
|
||||
highline (1.6.9)
|
||||
hike (1.2.1)
|
||||
httparty (0.8.1)
|
||||
multi_json
|
||||
multi_xml
|
||||
i18n (0.6.0)
|
||||
jquery-rails (1.0.18)
|
||||
jquery-rails (1.0.19)
|
||||
railties (~> 3.0)
|
||||
thor (~> 0.14)
|
||||
json (1.6.1)
|
||||
json_pure (1.6.1)
|
||||
kaminari (0.12.4)
|
||||
rails (>= 3.0.0)
|
||||
kgio (2.6.0)
|
||||
json (1.6.4)
|
||||
kaminari (0.13.0)
|
||||
actionpack (>= 3.0.0)
|
||||
activesupport (>= 3.0.0)
|
||||
railties (>= 3.0.0)
|
||||
kgio (2.7.2)
|
||||
launchy (2.0.5)
|
||||
addressable (~> 2.2.6)
|
||||
locomotive_liquid (2.2.2)
|
||||
@ -183,13 +170,13 @@ GEM
|
||||
mime-types (1.17.2)
|
||||
mimetype-fu (0.1.2)
|
||||
mocha (0.9.12)
|
||||
mongo (1.4.0)
|
||||
bson (= 1.4.0)
|
||||
mongoid (2.3.4)
|
||||
mongo (1.5.2)
|
||||
bson (= 1.5.2)
|
||||
mongoid (2.4.0)
|
||||
activemodel (~> 3.1)
|
||||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
multi_json (1.0.3)
|
||||
multi_json (1.0.4)
|
||||
multi_xml (0.4.1)
|
||||
net-scp (1.0.4)
|
||||
net-ssh (>= 1.99.1)
|
||||
@ -200,7 +187,7 @@ GEM
|
||||
cucumber (>= 0.8)
|
||||
rake
|
||||
polyglot (0.3.3)
|
||||
rack (1.3.5)
|
||||
rack (1.3.6)
|
||||
rack-cache (1.1)
|
||||
rack (>= 0.4)
|
||||
rack-mount (0.8.3)
|
||||
@ -230,7 +217,7 @@ GEM
|
||||
thor (~> 0.14.6)
|
||||
raindrops (0.8.0)
|
||||
rake (0.9.2)
|
||||
rdoc (3.11)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
responders (0.6.4)
|
||||
rest-client (1.6.7)
|
||||
@ -240,7 +227,7 @@ GEM
|
||||
rspec-core (~> 2.6.0)
|
||||
rspec-expectations (~> 2.6.0)
|
||||
rspec-mocks (~> 2.6.0)
|
||||
rspec-cells (0.1.0)
|
||||
rspec-cells (0.1.1)
|
||||
rails (~> 3.0)
|
||||
rspec-rails (~> 2.2)
|
||||
rspec-core (2.6.4)
|
||||
@ -253,19 +240,19 @@ GEM
|
||||
railties (~> 3.0)
|
||||
rspec (~> 2.6.0)
|
||||
ruby-hmac (0.4.0)
|
||||
rubyzip (0.9.4)
|
||||
rubyzip (0.9.5)
|
||||
sanitize (2.0.3)
|
||||
nokogiri (>= 1.4.4, < 1.6)
|
||||
sass (3.1.10)
|
||||
sass (3.1.12)
|
||||
sass-rails (3.1.5)
|
||||
actionpack (~> 3.1.0)
|
||||
railties (~> 3.1.0)
|
||||
sass (~> 3.1.10)
|
||||
tilt (~> 1.3.2)
|
||||
selenium-webdriver (2.13.0)
|
||||
childprocess (>= 0.2.1)
|
||||
selenium-webdriver (2.16.0)
|
||||
childprocess (>= 0.2.5)
|
||||
ffi (~> 1.0.9)
|
||||
json_pure
|
||||
multi_json (~> 1.0.4)
|
||||
rubyzip
|
||||
sprockets (2.0.3)
|
||||
hike (~> 1.2)
|
||||
@ -301,7 +288,7 @@ DEPENDENCIES
|
||||
ZenTest
|
||||
actionmailer-with-request (~> 0.3.0)
|
||||
autotest
|
||||
bson_ext (~> 1.4.0)
|
||||
bson_ext (~> 1.5.2)
|
||||
bushido (= 0.0.35)
|
||||
cancan (~> 1.6.7)
|
||||
capybara
|
||||
@ -309,12 +296,12 @@ DEPENDENCIES
|
||||
cells (~> 3.7.1)
|
||||
codemirror-rails
|
||||
coffee-script (~> 2.2.0)
|
||||
compass!
|
||||
compass (~> 0.12.alpha.4)
|
||||
cucumber-rails
|
||||
custom_fields!
|
||||
database_cleaner
|
||||
delayed_job_mongoid (~> 1.0.8)
|
||||
devise!
|
||||
devise (~> 1.5.3)
|
||||
dragonfly (~> 0.9.8)
|
||||
factory_girl_rails (~> 1.1)
|
||||
flash_cookie_session (~> 1.1.1)
|
||||
@ -322,7 +309,6 @@ DEPENDENCIES
|
||||
formtastic (~> 2.0.2)
|
||||
growl-glue
|
||||
haml (~> 3.1.3)
|
||||
handlebars-rails!
|
||||
highline (~> 1.6.2)
|
||||
httparty (~> 0.8.1)
|
||||
jquery-rails (~> 1.0.16)
|
||||
@ -332,7 +318,8 @@ DEPENDENCIES
|
||||
locomotive_mongoid_acts_as_tree!
|
||||
mimetype-fu (~> 0.1.2)
|
||||
mocha (= 0.9.12)
|
||||
mongoid (~> 2.3.3)
|
||||
mongo (~> 1.5.2)
|
||||
mongoid (~> 2.4.0)
|
||||
pickle
|
||||
rack-cache (~> 1.1)
|
||||
rails (~> 3.1.3)
|
||||
|
@ -48,7 +48,7 @@ h2. Community
|
||||
h2. Team
|
||||
|
||||
* Developers: "Didier Lafforgue":http://www.nocoffee.fr, "Jacques Crocker":http://www.railsjedi.com, "Mario Visic":http://www.mariovisic.com
|
||||
* Contributors: "Dirk Kelly":http://www.dirkkelly.com, "Raphael Costa":http://raphaelcosta.net (Brazilian Portuguese translation), "Bernd Hauser":http://www.designhunger.de (German translation), "Andrea Frigido":http://www.frisoft.it (Italian translation), "Enrique García":https://github.com/kikito (Spanish translation), "Lars Smit":https://github.com/larssmit (Dutch translation), "PitOn":https://github.com/GarPit (Russian translation)
|
||||
* Contributors: "Dirk Kelly":http://www.dirkkelly.com, "Raphael Costa":http://raphaelcosta.net (Brazilian Portuguese translation), "Bernd Hauser":http://www.designhunger.de (German translation), "Andrea Frigido":http://www.frisoft.it (Italian translation), "Enrique García":https://github.com/kikito (Spanish translation), "Lars Smit":https://github.com/larssmit (Dutch translation), "PitOn":https://github.com/GarPit (Russian translation), "paulsponagl":https://github.com/paulsponagl
|
||||
* UI Designer: "Sacha Greif":http://www.sachagreif.com
|
||||
* IE maintainer: "Alex Sanford":https://github.com/alexsanford
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
//= require jquery-ui
|
||||
//= require jquery_ujs
|
||||
//= require underscore
|
||||
//= require handlebars
|
||||
//= require backbone
|
||||
//= require codemirror
|
||||
//= require tinymce-jquery
|
||||
|
@ -3,13 +3,11 @@
|
||||
#= require_tree ./utils
|
||||
#= require_tree ./models
|
||||
#= require_tree ./views
|
||||
#= require_tree ./routers
|
||||
|
||||
window.Locomotive =
|
||||
mount_on: '/locomotive'
|
||||
Models: {}
|
||||
Collections: {}
|
||||
Routers: {}
|
||||
Views: {}
|
||||
|
||||
window.Locomotive.Views.Memberships = {}
|
@ -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', '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
|
||||
|
||||
|
@ -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('&');
|
||||
}
|
||||
})();
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -14,8 +14,6 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
||||
initialize: ->
|
||||
@model = new Locomotive.Models.ContentEntry(@options.content_entry)
|
||||
|
||||
console.log(@model.urlRoot)
|
||||
|
||||
window.foo = @model
|
||||
|
||||
Backbone.ModelBinding.bind @
|
||||
@ -61,7 +59,6 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
||||
@$('li.input.highlighted > input[type=text]').slugify(target: @$('#content_entry__slug'))
|
||||
|
||||
refresh_file_fields: ->
|
||||
console.log('refresh_file_fields')
|
||||
_.each @_file_field_views, (view) => view.refresh()
|
||||
|
||||
remove: ->
|
||||
|
@ -23,7 +23,7 @@ class Locomotive.Views.ContentTypes.FormView extends Locomotive.Views.Shared.For
|
||||
|
||||
@enable_liquid_editing() # turn textarea into editable liquid code zone
|
||||
|
||||
@enable_public_form_checkbox()
|
||||
@enable_public_submission_checkbox()
|
||||
|
||||
@enable_order_by_toggler()
|
||||
|
||||
@ -48,10 +48,10 @@ class Locomotive.Views.ContentTypes.FormView extends Locomotive.Views.Shared.For
|
||||
theme: 'default medium'
|
||||
onChange: (editor) => @model.set(raw_item_template: editor.getValue())
|
||||
|
||||
enable_public_form_checkbox: ->
|
||||
@_enable_checkbox 'public_form_enabled',
|
||||
on_callback: => @$('#content_type_public_form_accounts_input').show()
|
||||
off_callback: => @$('#content_type_public_form_accounts_input').hide()
|
||||
enable_public_submission_checkbox: ->
|
||||
@_enable_checkbox 'public_submission_enabled',
|
||||
on_callback: => @$('#content_type_public_submission_accounts_input').show()
|
||||
off_callback: => @$('#content_type_public_submission_accounts_input').hide()
|
||||
|
||||
enable_order_by_toggler: ->
|
||||
@$('#content_type_order_by_input').bind 'change', (event) =>
|
||||
|
@ -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: ->
|
||||
|
@ -13,19 +13,39 @@ class Locomotive.Views.CurrentSite.EditView extends Locomotive.Views.Shared.Form
|
||||
initialize: ->
|
||||
@model = new Locomotive.Models.CurrentSite(@options.site)
|
||||
|
||||
Backbone.ModelBinding.bind @
|
||||
Backbone.ModelBinding.bind @, checkbox: 'class'
|
||||
|
||||
window.foo = @model
|
||||
|
||||
render: ->
|
||||
super()
|
||||
|
||||
@add_toggle_mode_for_locales()
|
||||
|
||||
@make_locales_sortable()
|
||||
|
||||
@render_domains()
|
||||
|
||||
@render_memberships()
|
||||
|
||||
@enable_liquid_editing()
|
||||
|
||||
add_toggle_mode_for_locales: ->
|
||||
@$('#site_locales_input .list input[type=checkbox]').bind 'change', (event) ->
|
||||
el = $(event.target)
|
||||
if el.is(':checked')
|
||||
el.closest('.entry').addClass('selected')
|
||||
else
|
||||
el.closest('.entry').removeClass('selected')
|
||||
|
||||
make_locales_sortable: ->
|
||||
@sortable_locales_list = @$('#site_locales_input .list').sortable
|
||||
items: '.entry'
|
||||
tolerance: 'pointer'
|
||||
update: =>
|
||||
list = _.map @$('#site_locales_input .list input:checked'), (el) => $(el).val()
|
||||
@model.set locales: list
|
||||
|
||||
render_domains: ->
|
||||
@domains_view = new Locomotive.Views.Sites.DomainsView model: @model, errors: @options.errors
|
||||
|
||||
|
@ -17,7 +17,6 @@ class Locomotive.Views.Import.ShowView extends Backbone.View
|
||||
@refresh_steps
|
||||
|
||||
refresh_steps: (data) =>
|
||||
console.log 'refresh_steps: ....'
|
||||
window.foo = data
|
||||
window.bar = @
|
||||
|
||||
|
@ -2,15 +2,15 @@
|
||||
@import "compass/css3/border-radius";
|
||||
@import "helpers";
|
||||
|
||||
#sites-picker {
|
||||
@mixin picker {
|
||||
|
||||
position: absolute;
|
||||
top: 97px;
|
||||
// top: 97px;
|
||||
|
||||
margin: 5px 0 0 0;
|
||||
// margin: 5px 0 0 0;
|
||||
padding: 0 0 0 0;
|
||||
min-width: 160px;
|
||||
z-index: 999;
|
||||
// min-width: 160px;
|
||||
// z-index: 999;
|
||||
|
||||
@include border-radius(4px);
|
||||
border: 1px solid #000;
|
@ -0,0 +1,85 @@
|
||||
@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: 4px;
|
||||
}
|
||||
|
||||
span.text {
|
||||
position: relative;
|
||||
|
||||
// position: relative;
|
||||
// top: -6px;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -279,6 +279,63 @@ form.formtastic {
|
||||
}
|
||||
} // li.string, li.password
|
||||
|
||||
&.locale, &.locales {
|
||||
.list {
|
||||
margin-left: 150px;
|
||||
}
|
||||
|
||||
&.locales {
|
||||
label {
|
||||
color: #8B8D9A;
|
||||
}
|
||||
}
|
||||
|
||||
.entry {
|
||||
float: left;
|
||||
width: 212px;
|
||||
|
||||
margin-left: 10px;
|
||||
|
||||
&:first-child {
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
label {
|
||||
float: none;
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
position: relative;
|
||||
|
||||
padding-left: 31px;
|
||||
margin-left: 8px;
|
||||
|
||||
font-weight: normal;
|
||||
|
||||
img {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
&.selected {
|
||||
label {
|
||||
color: #585A69;
|
||||
}
|
||||
&:first-child {
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
} // .entry.selected
|
||||
|
||||
} // .entry
|
||||
|
||||
.inline-hints {
|
||||
clear: both;
|
||||
}
|
||||
} // > li.locale, li.locales
|
||||
|
||||
&.code {
|
||||
|
||||
textarea, .CodeMirror-scroll {
|
||||
@ -521,35 +578,6 @@ form.formtastic {
|
||||
}
|
||||
} // > li#site_memberships_input
|
||||
|
||||
&#account_locale_input {
|
||||
.entry {
|
||||
float: left;
|
||||
width: 212px;
|
||||
|
||||
margin-right: 10px;
|
||||
|
||||
&:nth-child(3n) {
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
label {
|
||||
float: none;
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
position: relative;
|
||||
|
||||
padding-left: 31px;
|
||||
margin-left: 8px;
|
||||
|
||||
img {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // > li#account_locale_input
|
||||
|
||||
&#account_sites_input {
|
||||
.entry {
|
||||
strong {
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
12
app/assets/stylesheets/locomotive/sites_picker.css.scss
Normal file
12
app/assets/stylesheets/locomotive/sites_picker.css.scss
Normal file
@ -0,0 +1,12 @@
|
||||
@import "picker";
|
||||
|
||||
#sites-picker {
|
||||
|
||||
@include picker;
|
||||
|
||||
top: 97px;
|
||||
|
||||
margin: 5px 0 0 0;
|
||||
min-width: 160px;
|
||||
z-index: 999;
|
||||
}
|
@ -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
|
17
app/cells/locomotive/content_locale_picker_cell.rb
Normal file
17
app/cells/locomotive/content_locale_picker_cell.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class Locomotive::ContentLocalePickerCell < Cell::Base
|
||||
|
||||
def show(args)
|
||||
site = args[:site]
|
||||
locale = args[:locale].to_s
|
||||
|
||||
logger.debug "site.locales = #{site.locales.inspect}"
|
||||
|
||||
if site.locales.empty? || site.locales.size < 2
|
||||
''
|
||||
else
|
||||
@locales = site.locales - [locale]
|
||||
render
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,61 +0,0 @@
|
||||
module Locomotive
|
||||
class ApiContentsController < ActionController::Base
|
||||
|
||||
# FIXME: NEED REFACTORING
|
||||
|
||||
include Locomotive::Routing::SiteDispatcher
|
||||
|
||||
before_filter :require_site
|
||||
|
||||
before_filter :set_content_type
|
||||
|
||||
before_filter :block_content_type_with_disabled_api
|
||||
|
||||
before_filter :sanitize_content_params, :only => :create
|
||||
|
||||
def create
|
||||
@entry = @content_type.entries.build(params[:entry])
|
||||
|
||||
respond_to do |format|
|
||||
if @entry.save
|
||||
format.json { render :json => { :entry => @entry } }
|
||||
format.html do
|
||||
flash[@content_type.slug.singularize] = @entry.aliased_attributes
|
||||
redirect_to params[:success_callback]
|
||||
end
|
||||
else
|
||||
format.json { render :json => { :entry => @content, :errors => @content.errors } }
|
||||
format.html do
|
||||
flash[@content_type.slug.singularize] = @content.aliased_attributes
|
||||
flash['errors'] = @content.errors_to_hash
|
||||
redirect_to params[:error_callback]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_content_type
|
||||
@content_type = current_site.content_types.where(:slug => params[:slug]).first
|
||||
end
|
||||
|
||||
def block_content_type_with_disabled_api
|
||||
unless @content_type.api_enabled?
|
||||
respond_to do |format|
|
||||
format.json { render :json => { :error => 'Api not enabled' }, :status => :forbidden }
|
||||
format.html { render :text => 'Api not enabled', :status => :forbidden }
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def sanitize_content_params
|
||||
(params[:content] || {}).each do |key, value|
|
||||
next unless value.is_a?(String)
|
||||
params[:content][key] = Sanitize.clean(value, Sanitize::Config::BASIC)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -3,6 +3,8 @@ module Locomotive
|
||||
|
||||
include Locomotive::Routing::SiteDispatcher
|
||||
|
||||
include Locomotive::ActionController::Helpers
|
||||
|
||||
layout '/locomotive/layouts/application'
|
||||
|
||||
before_filter :require_account
|
||||
@ -13,19 +15,17 @@ 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
|
||||
|
||||
helper_method :sections, :current_site_public_url, :switch_to_site_url, :public_page_url, :current_ability
|
||||
helper_method :sections, :current_ability
|
||||
|
||||
# https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in
|
||||
helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper #, Locomotive::BoxHelper
|
||||
# Dir[File.dirname(__FILE__) + "/../../helpers/**/*_helper.rb"].each do |file|
|
||||
# helper "locomotive/#{File.basename(file, '.rb').gsub(/_helper$/, '')}"
|
||||
# end
|
||||
helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper
|
||||
|
||||
self.responder = Locomotive::Responder # custom responder
|
||||
self.responder = Locomotive::ActionController::Responder # custom responder
|
||||
|
||||
respond_to :html
|
||||
|
||||
@ -44,8 +44,8 @@ module Locomotive
|
||||
protected
|
||||
|
||||
def set_current_thread_variables
|
||||
Thread.current[:account] = current_locomotive_account
|
||||
Thread.current[:site] = current_site
|
||||
Thread.current[:account] = current_locomotive_account
|
||||
Thread.current[:site] = current_site
|
||||
end
|
||||
|
||||
def current_ability
|
||||
@ -56,51 +56,5 @@ module Locomotive
|
||||
authenticate_locomotive_account!
|
||||
end
|
||||
|
||||
def self.sections(main, sub = nil)
|
||||
before_filter do |c|
|
||||
sub = sub.call(c) if sub.respond_to?(:call)
|
||||
sections = { :main => main, :sub => sub }
|
||||
c.instance_variable_set(:@locomotive_sections, sections)
|
||||
end
|
||||
end
|
||||
|
||||
def sections(key = nil)
|
||||
if !key.nil? && key.to_sym == :sub
|
||||
@locomotive_sections[:sub] || self.controller_name.dasherize
|
||||
else
|
||||
@locomotive_sections[:main]
|
||||
end
|
||||
end
|
||||
|
||||
def set_locale
|
||||
I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale
|
||||
end
|
||||
|
||||
# ___ site/page urls builder ___
|
||||
|
||||
def current_site_public_url
|
||||
request.protocol + request.host_with_port
|
||||
end
|
||||
|
||||
def switch_to_site_url(site, options = {})
|
||||
options = { :fullpath => true, :protocol => true }.merge(options)
|
||||
|
||||
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
||||
url += ":#{request.port}" if request.port != 80
|
||||
|
||||
url = File.join(url, request.fullpath) if options[:fullpath]
|
||||
url = "http://#{url}" if options[:protocol]
|
||||
url
|
||||
end
|
||||
|
||||
def public_page_url(page, options = {})
|
||||
if content = options.delete(:content)
|
||||
File.join(current_site_public_url, page.fullpath.gsub('content_type_template', ''), content._slug)
|
||||
else
|
||||
File.join(current_site_public_url, page.fullpath)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -7,6 +7,8 @@ module Locomotive
|
||||
|
||||
load_and_authorize_resource :class => 'Site'
|
||||
|
||||
helper 'Locomotive::Sites'
|
||||
|
||||
before_filter :filter_attributes
|
||||
|
||||
respond_to :json, :only => :update
|
||||
|
19
app/controllers/locomotive/public/base_controller.rb
Normal file
19
app/controllers/locomotive/public/base_controller.rb
Normal file
@ -0,0 +1,19 @@
|
||||
module Locomotive
|
||||
module Public
|
||||
class BaseController < ApplicationController
|
||||
|
||||
include Locomotive::Routing::SiteDispatcher
|
||||
|
||||
include Locomotive::ActionController::Helpers
|
||||
|
||||
before_filter :require_site
|
||||
|
||||
protected
|
||||
|
||||
def set_locale
|
||||
logger.info "[public/set_locale] TODO"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,50 @@
|
||||
module Locomotive
|
||||
module Public
|
||||
class ContentEntriesController < BaseController
|
||||
|
||||
before_filter :set_content_type
|
||||
|
||||
before_filter :sanitize_entry_params, :only => :create
|
||||
|
||||
skip_before_filter :verify_authenticity_token
|
||||
|
||||
self.responder = Locomotive::ActionController::PublicResponder # custom responder
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
def create
|
||||
@entry = @content_type.entries.create(params[:entry])
|
||||
flash[@content_type.slug.singularize] = @entry.to_presenter(:include_errors => true).as_json
|
||||
respond_with @entry, :location => self.callback_url
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_content_type
|
||||
@content_type = current_site.content_types.where(:slug => params[:slug]).first
|
||||
|
||||
# check if ability to receive public submissions
|
||||
unless @content_type.public_submission_enabled?
|
||||
respond_to do |format|
|
||||
format.json { render :json => { :error => 'Public submissions not accepted' }, :status => :forbidden }
|
||||
format.html { render :text => 'Public submissions not accepted', :status => :forbidden }
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def callback_url
|
||||
@entry.errors.empty? ? params[:success_callback] : params[:error_callback]
|
||||
end
|
||||
|
||||
def sanitize_entry_params
|
||||
entry_params = params[:entry] || params[:content] || {}
|
||||
entry_params.each do |key, value|
|
||||
next unless value.is_a?(String)
|
||||
entry_params[key] = Sanitize.clean(value, Sanitize::Config::BASIC)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
26
app/controllers/locomotive/public/rendering_controller.rb
Normal file
26
app/controllers/locomotive/public/rendering_controller.rb
Normal file
@ -0,0 +1,26 @@
|
||||
module Locomotive
|
||||
module Public
|
||||
class RenderingController < ApplicationController
|
||||
|
||||
include Locomotive::Routing::SiteDispatcher
|
||||
|
||||
include Locomotive::Render
|
||||
|
||||
before_filter :require_site
|
||||
|
||||
before_filter :authenticate_admin!, :only => [:edit]
|
||||
|
||||
before_filter :validate_site_membership, :only => [:edit]
|
||||
|
||||
def show
|
||||
render_locomotive_page
|
||||
end
|
||||
|
||||
def edit
|
||||
@editing = true
|
||||
render_locomotive_page
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
16
app/controllers/locomotive/public/robots_controller.rb
Normal file
16
app/controllers/locomotive/public/robots_controller.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module Locomotive
|
||||
module Public
|
||||
class RobotsController < BaseController
|
||||
|
||||
include Locomotive::Render
|
||||
|
||||
respond_to :txt
|
||||
|
||||
def show
|
||||
template = ::Liquid::Template.parse(current_site.robots_txt)
|
||||
render :text => template.render('request_host' => self.request.host.downcase)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
14
app/controllers/locomotive/public/sitemaps_controller.rb
Normal file
14
app/controllers/locomotive/public/sitemaps_controller.rb
Normal file
@ -0,0 +1,14 @@
|
||||
module Locomotive
|
||||
module Public
|
||||
class SitemapsController < BaseController
|
||||
|
||||
respond_to :xml
|
||||
|
||||
def show
|
||||
@pages = current_site.pages.published
|
||||
respond_with @pages
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -1,22 +0,0 @@
|
||||
module Locomotive
|
||||
class RenderingController < ActionController::Base
|
||||
|
||||
include Locomotive::Routing::SiteDispatcher
|
||||
|
||||
include Locomotive::Render
|
||||
|
||||
before_filter :require_site
|
||||
before_filter :authenticate_admin!, :only => [:edit]
|
||||
before_filter :validate_site_membership, :only => [:edit]
|
||||
|
||||
def show
|
||||
render_locomotive_page
|
||||
end
|
||||
|
||||
def edit
|
||||
@editing = true
|
||||
render_locomotive_page
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,18 +0,0 @@
|
||||
module Locomotive
|
||||
class RobotsController < ActionController::Base
|
||||
|
||||
include Locomotive::Routing::SiteDispatcher
|
||||
|
||||
include Locomotive::Render
|
||||
|
||||
before_filter :require_site
|
||||
|
||||
respond_to :txt
|
||||
|
||||
def show
|
||||
template = ::Liquid::Template.parse(current_site.robots_txt)
|
||||
render :text => template.render('request_host' => self.request.host.downcase)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,18 +0,0 @@
|
||||
module Locomotive
|
||||
class SitemapsController < BaseController
|
||||
|
||||
skip_before_filter :require_account, :validate_site_membership, :set_locale
|
||||
|
||||
before_filter :require_site
|
||||
|
||||
respond_to :xml
|
||||
|
||||
skip_load_and_authorize_resource
|
||||
|
||||
def show
|
||||
@pages = current_site.pages.published
|
||||
respond_with @pages
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -36,14 +36,6 @@ module Locomotive::BaseHelper
|
||||
end
|
||||
end
|
||||
|
||||
# def collection_to_js(collection, options = {}) # FIXME: DEPRECATED
|
||||
# js = collection.collect { |object| object.to_json }
|
||||
#
|
||||
# options_to_js = ActiveSupport::JSON.encode(options).gsub(/^\{/, '').gsub(/\}$/, '')
|
||||
#
|
||||
# "new Object({ \"collection\": [#{js.join(', ')}], #{options_to_js} })"
|
||||
# end
|
||||
|
||||
def flash_message
|
||||
if not flash.empty?
|
||||
first_key = flash.keys.first
|
||||
|
@ -1,23 +1,50 @@
|
||||
module Locomotive::ContentTypesHelper
|
||||
|
||||
def each_content_type_menu_item(&block)
|
||||
current_site.content_types.ordered.only(:site_id, :name, :slug, :label_field_name).each do |content_type|
|
||||
next unless content_type.persisted?
|
||||
# Iterates over the content types with the following rules
|
||||
# - content types are ordered by the updated_at date (DESC)
|
||||
# - each content type has its own submenu if saved recently
|
||||
# - if there are more than ui.max_content_types content types, the extra ones go under "..."
|
||||
# - if a content type is selected and it is part of the extra content types, then
|
||||
# it will be moved to the first position in the displayed list (with its own submenu)
|
||||
#
|
||||
# @param [ Block ] block The statements responsible to display the menu item from a content type or a list of content types
|
||||
#
|
||||
def each_content_type(&block)
|
||||
visible, others = [], []
|
||||
|
||||
item_on = (content_type.slug == @content_type.slug) rescue nil
|
||||
current_site.content_types.ordered.only(:site_id, :name, :slug, :label_field_name).each_with_index do |content_type, index|
|
||||
next if !content_type.persisted?
|
||||
|
||||
label = truncate(content_type.name, :length => 15)
|
||||
url = content_entries_url(content_type.slug)
|
||||
css = @content_type && content_type.slug == @content_type.slug ? 'on' : ''
|
||||
|
||||
html = submenu_entry(label, url, :i18n => false, :css => css) do
|
||||
yield(content_type)
|
||||
if index >= Locomotive.config.ui.max_content_types
|
||||
if self.is_content_type_selected(content_type)
|
||||
others << visible.delete_at(Locomotive.config.ui.max_content_types - 1) # swap content types
|
||||
visible.insert(0, content_type)
|
||||
else
|
||||
others << content_type # fills the "..." menu
|
||||
end
|
||||
next
|
||||
end
|
||||
|
||||
haml_concat(html)
|
||||
visible << content_type
|
||||
end
|
||||
|
||||
visible.map { |c| yield(c) }
|
||||
yield(others)
|
||||
end
|
||||
|
||||
def is_content_type_selected(content_type)
|
||||
@content_type && content_type.slug == @content_type.slug
|
||||
end
|
||||
|
||||
# Renders the label of a content type entry. If no raw_item_template filled in the content type,
|
||||
# it just calls the _label method of the entry (based on the label_field_id). Otherwise, it
|
||||
# parses and renders the liquid template.
|
||||
#
|
||||
# @param [ ContentType ] content_type The content type for better performance
|
||||
# @param [ ContentEntry] entry The entry we want to display the label
|
||||
#
|
||||
# @return [ String ] The label of the content type entry
|
||||
#
|
||||
def entry_label(content_type, entry)
|
||||
if content_type.raw_item_template.blank?
|
||||
entry._label # default one
|
||||
@ -34,90 +61,4 @@ module Locomotive::ContentTypesHelper
|
||||
end
|
||||
end
|
||||
|
||||
# MAX_DISPLAYED_CONTENTS = 4
|
||||
#
|
||||
# def fetch_content_types
|
||||
# return @content_types if @content_types
|
||||
#
|
||||
# @content_types = current_site.content_types.ordered.
|
||||
# limit(:contents => Locomotive.config.lastest_items_nb).
|
||||
# only(:site_id, :name, :slug, :highlighted_field_name, :contents_custom_fields_version, :order_by, :serialized_item_template, :raw_item_template).to_a
|
||||
#
|
||||
# if @content_type && @content_type.persisted? && @content_types.index(@content_type) >= MAX_DISPLAYED_CONTENTS
|
||||
# @content_types.delete(@content_type)
|
||||
# @content_types.insert(0, @content_type)
|
||||
# end
|
||||
#
|
||||
# # be sure, we've got the custom klass up-to-date, otherwise it will fail miserably
|
||||
# @content_types.each do |content_type|
|
||||
# if content_type.content_klass_out_of_date?
|
||||
# content_type.reload
|
||||
# content_type.invalidate_content_klass
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# @content_types
|
||||
# end
|
||||
#
|
||||
# def each_content_type_menu_item(which = :first, &block)
|
||||
# types = fetch_content_types
|
||||
# sliced = []
|
||||
#
|
||||
# if which == :first
|
||||
# sliced = types[0..MAX_DISPLAYED_CONTENTS - 1]
|
||||
# elsif types.size > MAX_DISPLAYED_CONTENTS
|
||||
# sliced = types[MAX_DISPLAYED_CONTENTS, types.size - MAX_DISPLAYED_CONTENTS]
|
||||
# end
|
||||
#
|
||||
# return [] if sliced.empty?
|
||||
#
|
||||
# sliced.each do |content_type|
|
||||
# next if content_type.new_record?
|
||||
# item_on = (content_type.slug == @content_type.slug) rescue nil
|
||||
#
|
||||
# label = truncate(content_type.name, :length => 15)
|
||||
# url = contents_url(content_type.slug)
|
||||
# css = @content_type && content_type.slug == @content_type.slug ? 'on' : ''
|
||||
#
|
||||
# html = submenu_entry(label, url, :i18n => false, :css => css) do
|
||||
# yield(content_type)
|
||||
# end
|
||||
#
|
||||
# haml_concat(html)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def other_content_types(&block)
|
||||
# types = fetch_content_types
|
||||
#
|
||||
# if types.size > MAX_DISPLAYED_CONTENTS
|
||||
# sliced = types[MAX_DISPLAYED_CONTENTS, types.size - MAX_DISPLAYED_CONTENTS]
|
||||
#
|
||||
# html = submenu_entry('...', '#', :i18n => false) do
|
||||
# yield(sliced)
|
||||
# end
|
||||
#
|
||||
# haml_concat(html)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def content_label_for(content)
|
||||
# if content._parent.raw_item_template.blank?
|
||||
# content._label # default one
|
||||
# else
|
||||
# assigns = {
|
||||
# 'site' => current_site,
|
||||
# 'content' => content.to_liquid
|
||||
# }
|
||||
#
|
||||
# registers = {
|
||||
# :controller => self,
|
||||
# :site => current_site,
|
||||
# :current_locomotive_account => current_locomotive_account
|
||||
# }
|
||||
#
|
||||
# preserve(content._parent.item_template.render(::Liquid::Context.new({}, assigns, registers)))
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
@ -1,11 +1,7 @@
|
||||
module Locomotive::SitesHelper
|
||||
|
||||
# def error_on_domain(site, name)
|
||||
# if (error = (site.errors[:domains] || []).detect { |n| n.include?(name) })
|
||||
# content_tag(:span, error, :class => 'inline-errors')
|
||||
# else
|
||||
# ''
|
||||
# end
|
||||
# end
|
||||
def ordered_current_site_locales
|
||||
current_site.locales + (Locomotive.config.site_locales - current_site.locales)
|
||||
end
|
||||
|
||||
end
|
||||
|
59
app/inputs/locomotive/locales_input.rb
Normal file
59
app/inputs/locomotive/locales_input.rb
Normal file
@ -0,0 +1,59 @@
|
||||
module Locomotive
|
||||
class LocalesInput < ::Formtastic::Inputs::CheckBoxesInput
|
||||
|
||||
def to_html
|
||||
input_wrapping do
|
||||
label_html <<
|
||||
choices_group_wrapping do
|
||||
collection.map { |choice|
|
||||
choice_wrapping(choice_wrapping_html_options(choice)) do
|
||||
choice_html(choice)
|
||||
end
|
||||
}.join("\n").html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def choices_group_wrapping(&block)
|
||||
template.content_tag(:div,
|
||||
template.capture(&block),
|
||||
choices_group_wrapping_html_options
|
||||
)
|
||||
end
|
||||
|
||||
def choice_wrapping(html_options, &block)
|
||||
template.content_tag(:div,
|
||||
template.capture(&block),
|
||||
html_options
|
||||
)
|
||||
end
|
||||
|
||||
def choice_html(choice)
|
||||
check_box_without_hidden_input(choice) <<
|
||||
template.content_tag(:label,
|
||||
choice_label(choice),
|
||||
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
|
||||
)
|
||||
end
|
||||
|
||||
def choice_label(choice)
|
||||
text = I18n.t("locomotive.my_account.edit.#{choice}")
|
||||
template.image_tag("locomotive/icons/flags/#{choice}.png", :alt => text) << text
|
||||
end
|
||||
|
||||
def choices_group_wrapping_html_options
|
||||
{ :class => 'list' }
|
||||
end
|
||||
|
||||
def choice_wrapping_html_options(choice)
|
||||
super.tap do |options|
|
||||
options[:class] = "entry #{checked?(choice) ? 'selected' : ''}"
|
||||
end
|
||||
end
|
||||
|
||||
def hidden_fields?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -4,9 +4,9 @@ module Locomotive
|
||||
default :from => Locomotive.config.mailer_sender
|
||||
|
||||
def new_content_entry(account, entry)
|
||||
@account, @entry = account, entry
|
||||
@account, @entry, @type = account, entry.to_presenter, entry.content_type
|
||||
|
||||
subject = t('locomotive.notifications.new_content_entry.subject', :type => entry.content_type.name, :locale => account.locale)
|
||||
subject = t('locomotive.notifications.new_content_entry.subject', :type => @type.name, :locale => account.locale)
|
||||
|
||||
mail :subject => subject, :to => account.email
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ module Locomotive
|
||||
|
||||
## named scopes ##
|
||||
scope :visible, :where => { :_visible => true }
|
||||
scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.lastest_entries_nb
|
||||
scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.ui.lastest_entries_nb
|
||||
|
||||
## methods ##
|
||||
|
||||
@ -64,8 +64,8 @@ module Locomotive
|
||||
Locomotive::Liquid::Drops::ContentEntry.new(self)
|
||||
end
|
||||
|
||||
def to_presenter
|
||||
Locomotive::ContentEntryPresenter.new(self)
|
||||
def to_presenter(options = {})
|
||||
Locomotive::ContentEntryPresenter.new(self, options)
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
@ -119,10 +119,10 @@ module Locomotive
|
||||
end
|
||||
|
||||
def send_notifications
|
||||
return if !self.content_type.public_form_enabled? || self.content_type.public_form_accounts.blank?
|
||||
return if !self.content_type.public_submission_enabled? || self.content_type.public_submission_accounts.blank?
|
||||
|
||||
self.content_type.site.accounts.each do |account|
|
||||
next unless self.content_type.public_form_accounts.include?(account._id.to_s)
|
||||
next unless self.content_type.public_submission_accounts.include?(account._id.to_s)
|
||||
|
||||
Locomotive::Notifications.new_content_entry(account, self).deliver
|
||||
end
|
||||
|
@ -11,13 +11,13 @@ module Locomotive
|
||||
field :name
|
||||
field :description
|
||||
field :slug
|
||||
field :label_field_id, :type => BSON::ObjectId
|
||||
field :label_field_id, :type => BSON::ObjectId
|
||||
field :label_field_name
|
||||
field :group_by_field_id, :type => BSON::ObjectId
|
||||
field :group_by_field_id, :type => BSON::ObjectId
|
||||
field :order_by
|
||||
field :order_direction, :default => 'asc'
|
||||
field :public_form_enabled, :type => Boolean, :default => false
|
||||
field :public_form_accounts, :type => Array
|
||||
field :order_direction, :default => 'asc'
|
||||
field :public_submission_enabled, :type => Boolean, :default => false
|
||||
field :public_submission_accounts, :type => Array
|
||||
|
||||
## associations ##
|
||||
belongs_to :site, :class_name => 'Locomotive::Site'
|
||||
@ -53,8 +53,8 @@ module Locomotive
|
||||
[order_by_attribute, direction]
|
||||
end
|
||||
|
||||
def ordered_entries
|
||||
self.entries.order_by([order_by_definition])
|
||||
def ordered_entries(conditions = {})
|
||||
self.entries.order_by([order_by_definition]).where(conditions)
|
||||
end
|
||||
|
||||
def groupable?
|
||||
@ -81,71 +81,6 @@ module Locomotive
|
||||
self.to_presenter.as_json
|
||||
end
|
||||
|
||||
# def list_or_group_contents
|
||||
# if self.groupable?
|
||||
# groups = self.contents.klass.send(:"group_by_#{self.group_by_field._alias}", :ordered_contents)
|
||||
#
|
||||
# # look for items with no category or unknown ones
|
||||
# items_without_category = self.contents.find_all { |c| !self.group_by_field.category_ids.include?(c.send(self.group_by_field_name)) }
|
||||
# if not items_without_category.empty?
|
||||
# groups << { :name => nil, :items => items_without_category }
|
||||
# else
|
||||
# groups
|
||||
# end
|
||||
# else
|
||||
# self.ordered_contents
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def latest_updated_contents
|
||||
# self.contents.latest_updated.reject { |c| !c.persisted? }
|
||||
# end
|
||||
#
|
||||
# def ordered_contents(conditions = {})
|
||||
# column = self.order_by.to_sym
|
||||
#
|
||||
# list = (if conditions.nil? || conditions.empty?
|
||||
# self.contents
|
||||
# else
|
||||
# conditions_with_names = {}
|
||||
#
|
||||
# conditions.each do |key, value|
|
||||
# # convert alias (key) to name
|
||||
# field = self.entries_custom_fields.detect { |f| f._alias == key }
|
||||
#
|
||||
# case field.kind.to_sym
|
||||
# when :category
|
||||
# if (category_item = field.category_items.where(:name => value).first).present?
|
||||
# conditions_with_names[field._name.to_sym] = category_item._id
|
||||
# end
|
||||
# else
|
||||
# conditions_with_names[field._name.to_sym] = value
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self.contents.where(conditions_with_names)
|
||||
# end).sort { |a, b| (a.send(column) && b.send(column)) ? (a.send(column) || 0) <=> (b.send(column) || 0) : 0 }
|
||||
#
|
||||
# return list if self.order_manually?
|
||||
#
|
||||
# self.asc_order? ? list : list.reverse
|
||||
# end
|
||||
#
|
||||
# def sort_contents!(ids)
|
||||
# ids.each_with_index do |id, position|
|
||||
# self.contents.find(BSON::ObjectId(id))._position_in_list = position
|
||||
# end
|
||||
# self.save
|
||||
# end
|
||||
#
|
||||
# def highlighted_field
|
||||
# self.entries_custom_fields.detect { |f| f._name == self.highlighted_field_name }
|
||||
# end
|
||||
#
|
||||
# def group_by_field
|
||||
# @group_by_field ||= self.entries_custom_fields.detect { |f| f._name == self.group_by_field_name }
|
||||
# end
|
||||
|
||||
protected
|
||||
|
||||
def order_by_attribute
|
||||
@ -155,7 +90,8 @@ module Locomotive
|
||||
|
||||
def set_default_values
|
||||
self.order_by ||= 'created_at'
|
||||
field = self.entries_custom_fields.find(self.label_field_id) rescue self.entries_custom_fields.first
|
||||
self.label_field_id = self.entries_custom_fields.first._id if self.label_field_id.blank?
|
||||
field = self.entries_custom_fields.find(self.label_field_id)
|
||||
self.label_field_name = field.name
|
||||
end
|
||||
|
||||
@ -177,3 +113,64 @@ module Locomotive
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# def list_or_group_contents
|
||||
# if self.groupable?
|
||||
# groups = self.contents.klass.send(:"group_by_#{self.group_by_field._alias}", :ordered_contents)
|
||||
#
|
||||
# # look for items with no category or unknown ones
|
||||
# items_without_category = self.contents.find_all { |c| !self.group_by_field.category_ids.include?(c.send(self.group_by_field_name)) }
|
||||
# if not items_without_category.empty?
|
||||
# groups << { :name => nil, :items => items_without_category }
|
||||
# else
|
||||
# groups
|
||||
# end
|
||||
# else
|
||||
# self.ordered_contents
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def latest_updated_contents
|
||||
# self.contents.latest_updated.reject { |c| !c.persisted? }
|
||||
# end
|
||||
#
|
||||
# def ordered_contents(conditions = {})
|
||||
# column = self.order_by.to_sym
|
||||
#
|
||||
# list = (if conditions.nil? || conditions.empty?
|
||||
# self.contents
|
||||
# else
|
||||
# conditions_with_names = {}
|
||||
#
|
||||
# conditions.each do |key, value|
|
||||
# # convert alias (key) to name
|
||||
# field = self.entries_custom_fields.detect { |f| f._alias == key }
|
||||
#
|
||||
# case field.kind.to_sym
|
||||
# when :category
|
||||
# if (category_item = field.category_items.where(:name => value).first).present?
|
||||
# conditions_with_names[field._name.to_sym] = category_item._id
|
||||
# end
|
||||
# else
|
||||
# conditions_with_names[field._name.to_sym] = value
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self.contents.where(conditions_with_names)
|
||||
# end).sort { |a, b| (a.send(column) && b.send(column)) ? (a.send(column) || 0) <=> (b.send(column) || 0) : 0 }
|
||||
#
|
||||
# return list if self.order_manually?
|
||||
#
|
||||
# self.asc_order? ? list : list.reverse
|
||||
# end
|
||||
#
|
||||
# def sort_contents!(ids)
|
||||
# ids.each_with_index do |id, position|
|
||||
# self.contents.find(BSON::ObjectId(id))._position_in_list = position
|
||||
# end
|
||||
# self.save
|
||||
# end
|
||||
#
|
||||
# def group_by_field
|
||||
# @group_by_field ||= self.entries_custom_fields.detect { |f| f._name == self.group_by_field_name }
|
||||
# end
|
57
app/models/locomotive/extensions/site/i18n.rb
Normal file
57
app/models/locomotive/extensions/site/i18n.rb
Normal file
@ -0,0 +1,57 @@
|
||||
module Locomotive
|
||||
module Extensions
|
||||
module Site
|
||||
module I18n
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
## fields ##
|
||||
field :locales, :type => 'RawArray', :default => []
|
||||
|
||||
## callbacks ##
|
||||
# after_validation :add_missing_locales_for_all_pages
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def locales=(array)
|
||||
array = [] if array.blank?; super(array)
|
||||
end
|
||||
|
||||
def default_locale
|
||||
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
|
||||
# if self.locales_changed?
|
||||
# list = self.pages.to_a
|
||||
#
|
||||
# while !list.empty? do
|
||||
# page = list.pop
|
||||
# begin
|
||||
# page.send(:set_slug_and_fullpath_for_all_locales, self.locales)
|
||||
#
|
||||
# page.save
|
||||
#
|
||||
# rescue TypeError => e
|
||||
# list.insert(0, page)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -41,7 +41,7 @@ module Locomotive
|
||||
validates_exclusion_of :slug, :in => Locomotive.config.reserved_slugs, :if => Proc.new { |p| p.depth == 0 }
|
||||
|
||||
## named scopes ##
|
||||
scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_entries_nb
|
||||
scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.ui.lastest_entries_nb
|
||||
scope :root, :where => { :slug => 'index', :depth => 0 }
|
||||
scope :not_found, :where => { :slug => '404', :depth => 0 }
|
||||
scope :published, :where => { :published => true }
|
||||
@ -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
|
||||
|
@ -4,9 +4,10 @@ module Locomotive
|
||||
include Locomotive::Mongoid::Document
|
||||
|
||||
## Extensions ##
|
||||
extend Extensions::Site::SubdomainDomains
|
||||
extend Extensions::Site::FirstInstallation
|
||||
extend Extensions::Site::SubdomainDomains
|
||||
extend Extensions::Site::FirstInstallation
|
||||
include Extensions::Shared::Seo
|
||||
include Extensions::Site::I18n
|
||||
|
||||
## fields ##
|
||||
field :name
|
||||
|
@ -1,7 +1,7 @@
|
||||
class Locomotive::BasePresenter
|
||||
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
||||
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
||||
include ActionView::Helpers::TextHelper
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
@ -20,8 +20,6 @@ class Locomotive::BasePresenter
|
||||
|
||||
def id
|
||||
self.source.persisted? || self.source.embedded? ? self.source._id.to_s : nil
|
||||
# self.persisted? ? self.source._id.to_s : nil
|
||||
# self.source._id.to_s
|
||||
end
|
||||
|
||||
def ability?
|
||||
@ -35,8 +33,8 @@ class Locomotive::BasePresenter
|
||||
def as_json(methods = nil)
|
||||
methods ||= self.included_methods
|
||||
{}.tap do |hash|
|
||||
methods.map(&:to_sym).each do |meth|
|
||||
hash[meth] = self.send(meth) rescue nil
|
||||
methods.each do |meth|
|
||||
hash[meth] = self.send(meth.to_sym) rescue nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,20 +3,33 @@ module Locomotive
|
||||
|
||||
delegate :_slug, :_position, :seo_title, :meta_keywords, :meta_description, :to => :source
|
||||
|
||||
# Returns the value of a field in the context of the current entry.
|
||||
#
|
||||
# @params [ CustomFields::Field ] field The field
|
||||
#
|
||||
# @returns [ Object ] The value of the field for the entry
|
||||
#
|
||||
def value_for(field)
|
||||
getter = [*self.getters_for(field.name, field.type)].first.to_sym
|
||||
self.source.send(getter)
|
||||
end
|
||||
|
||||
# Returns the list of getters for an entry
|
||||
#
|
||||
# @returns [ List ] a list of method names (string)
|
||||
#
|
||||
def custom_fields_methods
|
||||
source.custom_fields_recipe['rules'].map do |rule|
|
||||
case rule['type']
|
||||
when 'select' then [rule['name'], "#{rule['name']}_id"]
|
||||
when 'date' then "formatted_#{rule['name']}"
|
||||
when 'file' then "#{rule['name']}_url"
|
||||
else
|
||||
rule['name']
|
||||
end
|
||||
self.source.custom_fields_recipe['rules'].map do |rule|
|
||||
self.getters_for rule['name'], rule['type']
|
||||
end.flatten
|
||||
end
|
||||
|
||||
# Lists of all the attributes editable by a html form
|
||||
#
|
||||
# @returns [ List ] a list of attributes (string)
|
||||
#
|
||||
def safe_attributes
|
||||
source.custom_fields_recipe['rules'].map do |rule|
|
||||
self.source.custom_fields_recipe['rules'].map do |rule|
|
||||
case rule['type']
|
||||
when 'select' then "#{rule['name']}_id"
|
||||
when 'date' then "formatted_#{rule['name']}"
|
||||
@ -27,6 +40,10 @@ module Locomotive
|
||||
end.flatten + %w(_slug seo_title meta_keywords meta_description)
|
||||
end
|
||||
|
||||
def errors
|
||||
self.source.errors.to_hash.stringify_keys
|
||||
end
|
||||
|
||||
def content_type_slug
|
||||
self.source.content_type.slug
|
||||
end
|
||||
@ -36,7 +53,9 @@ module Locomotive
|
||||
end
|
||||
|
||||
def included_methods
|
||||
super + self.custom_fields_methods + %w(_slug _position content_type_slug _file_fields safe_attributes persisted)
|
||||
default_list = %w(_slug _position content_type_slug _file_fields safe_attributes)
|
||||
default_list << 'errors' if !!self.options[:include_errors]
|
||||
super + self.custom_fields_methods + default_list
|
||||
end
|
||||
|
||||
def method_missing(meth, *arguments, &block)
|
||||
@ -47,5 +66,24 @@ module Locomotive
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Gets the names of the getter methods for a field.
|
||||
# The names depend on the field type.
|
||||
#
|
||||
# @params [ String ] name Name of the field
|
||||
# @params [ String ] type Type of the field
|
||||
#
|
||||
# @returns [ Object ] A string or an array of names
|
||||
def getters_for(name, type)
|
||||
case type
|
||||
when 'select' then [name, "#{name}_id"]
|
||||
when 'date' then "formatted_#{name}"
|
||||
when 'file' then "#{name}_url"
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
module Locomotive
|
||||
class SitePresenter < BasePresenter
|
||||
|
||||
delegate :name, :subdomain, :domains, :robots_txt, :seo_title, :meta_keywords, :meta_description, :domains_without_subdomain, :to => :source
|
||||
delegate :name, :locales, :subdomain, :domains, :robots_txt, :seo_title, :meta_keywords, :meta_description, :domains_without_subdomain, :to => :source
|
||||
|
||||
def domain_name
|
||||
Locomotive.config.domain
|
||||
@ -12,7 +12,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def included_methods
|
||||
super + %w(name domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships)
|
||||
super + %w(name locales domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -33,6 +33,6 @@
|
||||
|
||||
= f.input :order_direction, :as => :select, :collection => options_for_order_direction, :include_blank => false, :wrapper_html => { :style => "#{'display: none' if @content_type.order_manually?}" }
|
||||
|
||||
= f.input :public_form_enabled, :as => :'Locomotive::Toggle'
|
||||
= f.input :public_submission_enabled, :as => :'Locomotive::Toggle'
|
||||
|
||||
= f.input :public_form_accounts, :as => :select, :collection => options_for_account, :include_blank => false, :multiple => true, :wrapper_html => { :class => 'multiple', :style => (@content_type.public_form_enabled? ? '' : 'display: none') }
|
||||
= f.input :public_submission_accounts, :as => :select, :collection => options_for_account, :include_blank => false, :multiple => true, :wrapper_html => { :class => 'multiple', :style => (@content_type.public_submission_enabled? ? '' : 'display: none') }
|
||||
|
@ -7,8 +7,8 @@
|
||||
= render 'locomotive/shared/actions/contents'
|
||||
|
||||
- content_for :buttons do
|
||||
= local_action_button :show_items, content_entries_url(@content_type.slug_was), :class => 'show'
|
||||
= local_action_button :new_item, new_content_entry_url(@content_type.slug_was), :class => 'new'
|
||||
= local_action_button :show_entries, content_entries_url(@content_type.slug_was), :class => 'show'
|
||||
= local_action_button :new_entry, new_content_entry_url(@content_type.slug_was), :class => 'new'
|
||||
|
||||
%p!= t('.help')
|
||||
|
||||
|
@ -6,13 +6,9 @@
|
||||
:plain
|
||||
{ site: #{@site.to_json(:current_account => current_locomotive_account, :current_site => current_site)}, errors: #{@site.errors.to_json} }
|
||||
|
||||
= f.inputs :name => :information, :style => 'display: none' do
|
||||
= f.input :name
|
||||
|
||||
= f.inputs :name => :seo, :class => "inputs foldable #{'folded' if inputs_folded?(@site)}" do
|
||||
= f.input :seo_title
|
||||
= f.input :meta_keywords
|
||||
= f.input :meta_description
|
||||
= f.inputs :name => :information do
|
||||
= f.input :name, :wrapper_html => { :style => 'display: none' }
|
||||
= f.input :locales, :as => '::Locomotive::Locales', :collection => ordered_current_site_locales, :input_html => { :class => 'locales' }
|
||||
|
||||
- if can?(:point, Locomotive::Site)
|
||||
- if manage_subdomain_or_domains?
|
||||
@ -22,6 +18,12 @@
|
||||
- if manage_domains?
|
||||
= f.input :domains, :as => :'Locomotive::Empty'
|
||||
|
||||
|
||||
= f.inputs :name => :seo, :class => "inputs foldable #{'folded' if inputs_folded?(@site)}" do
|
||||
= f.input :seo_title
|
||||
= f.input :meta_keywords
|
||||
= f.input :meta_description
|
||||
|
||||
- if can?(:index, Locomotive::Membership)
|
||||
|
||||
= f.inputs :name => :memberships do
|
||||
|
@ -1,10 +0,0 @@
|
||||
- highlighted_field_name = parent.highlighted_field_name rescue ''
|
||||
|
||||
= form.inputs :name => title || :attributes do
|
||||
- form.object.custom_fields.each do |field|
|
||||
- highlighted = highlighted_field_name == field._name
|
||||
- required = highlighted || field.required
|
||||
|
||||
= render "/admin/custom_fields/types/#{field.kind}", :form => form, :parent => parent, :field => field, :required => required, :highlighted => highlighted
|
||||
|
||||
= render '/admin/custom_fields/category_tmpl'
|
@ -40,9 +40,11 @@
|
||||
|
||||
= 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', :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' }
|
||||
|
||||
%span.actions
|
||||
= link_to 'toggle', '#', :class => 'toggle'
|
||||
|
@ -1 +1,4 @@
|
||||
= f.input name, :label => field.label, :as => :'Locomotive::Toggle', :hint => field.hint
|
||||
= f.input name,
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:as => :'Locomotive::Toggle'
|
@ -1,4 +0,0 @@
|
||||
= form.custom_input field._alias.to_sym, :label => field.label, :hint => field.hint, :css => 'toggle', :required => required do
|
||||
= form.select field._name.to_sym, field.ordered_category_items.collect { |item| [item.name, item.id] }
|
||||
%button.button.light.edit-categories-link{ :type => 'button', :'data-url' => edit_admin_custom_field_path(parent.class.model_name.underscore, parent.slug, field) }
|
||||
%span!= t('.edit_categories')
|
@ -1 +1,5 @@
|
||||
= f.input :"formatted_#{name}", :label => field.label, :hint => field.hint, :input_html => { :maxlength => 10 }, :wrapper_html => { :class => 'date' }
|
||||
= f.input :"formatted_#{name}",
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:wrapper_html => { :class => 'date' },
|
||||
:input_html => { :maxlength => 10 }
|
||||
|
@ -1 +1,4 @@
|
||||
= f.input name, :label => field.label, :hint => field.hint, :as => :'Locomotive::File'
|
||||
= f.input name,
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:as => :'Locomotive::File'
|
@ -1 +1,5 @@
|
||||
= f.input :"#{name}_id", :as => 'select', :collection => field.ordered_select_options.map { |option| [option.name, option.id] }, :label => field.label, :hint => field.hint
|
||||
= f.input :"#{name}_id",
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:as => 'select',
|
||||
:collection => field.ordered_select_options.map { |option| [option.name, option.id] }
|
@ -1 +1,4 @@
|
||||
= f.input name, :label => field.label, :hint => field.hint, :wrapper_html => { :class => "#{'highlighted' if highlighted}" }
|
||||
= f.input name,
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:wrapper_html => { :class => "#{'highlighted' if highlighted}" }
|
@ -1 +1,5 @@
|
||||
= f.input field.name.to_sym, :label => field.label, :hint => field.hint, :as => :'Locomotive::Rte', :input_html => { :class => field.text_formatting }
|
||||
= f.input field.name.to_sym,
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:as => field.text_formatting == 'html' ? :'Locomotive::Rte' : 'text',
|
||||
:input_html => { :class => field.text_formatting }
|
@ -15,7 +15,7 @@
|
||||
= yield :submenu
|
||||
|
||||
- if content_for? :actions
|
||||
.action
|
||||
.actions
|
||||
= yield :actions
|
||||
|
||||
#content
|
||||
|
@ -3,19 +3,20 @@
|
||||
%hr
|
||||
|
||||
%p
|
||||
%b= t('.type', :type => @content_entry.content_type.name, :locale => @account.locale)
|
||||
%b= t('.type', :type => @type.name, :locale => @account.locale)
|
||||
%br
|
||||
%i= @content_entry.content_type.description
|
||||
%i= @type.description
|
||||
|
||||
%hr
|
||||
|
||||
%ul
|
||||
- @content_entry.custom_fields.each do |field|
|
||||
- @type.entries_custom_fields.each do |field|
|
||||
- value = @entry.value_for(field)
|
||||
%li
|
||||
%strong= field.label
|
||||
-
|
||||
%i
|
||||
- if field.file?
|
||||
= link_to File.basename(@content_entry.send(field.name).url), @content_entry.send(field.name).url
|
||||
- if field.type == 'file'
|
||||
= link_to File.basename(value), value
|
||||
- else
|
||||
= @content_entry.send(field.name)
|
||||
= value
|
||||
|
@ -10,9 +10,6 @@
|
||||
= stylesheet_link_tag 'locomotive', :media => 'screen'
|
||||
= javascript_include_tag 'locomotive'
|
||||
|
||||
/ [if IE]
|
||||
= stylesheet_link_tag 'locomotive/ie', :media => 'screen'
|
||||
|
||||
%script{ :type => 'text/javascript' }
|
||||
:plain
|
||||
window.locale = '#{I18n.locale}';
|
||||
|
@ -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
|
@ -1,2 +1,12 @@
|
||||
- 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'
|
||||
|
||||
.action
|
||||
= link_to '#', :id => 'content-locale-picker-link', :class => 'button' do
|
||||
%span.hand
|
||||
|
||||
|
||||
= image_tag "locomotive/icons/flags/#{current_content_locale}.png", :class => 'flag'
|
||||
|
||||
%span.text= current_content_locale
|
@ -11,25 +11,30 @@
|
||||
= link_to truncate(page.title, :length => 25), edit_page_url(page)
|
||||
%span= time_ago_in_words(page.updated_at)
|
||||
|
||||
- each_content_type_menu_item do |content_type|
|
||||
.wrapper
|
||||
.header
|
||||
%p= link_to t('locomotive.content_entries.index.new'), new_content_entry_url(content_type.slug)
|
||||
- each_content_type do |menu_item|
|
||||
-if menu_item.is_a?(Array)
|
||||
- content_types = menu_item
|
||||
= submenu_entry '...', '#', :i18n => false do
|
||||
.wrapper
|
||||
.inner
|
||||
%ul.big-links
|
||||
- content_types.each do |content_type|
|
||||
%li
|
||||
= link_to truncate(content_type.name, :length => 20), content_entries_url(content_type.slug)
|
||||
- else
|
||||
- content_type = menu_item
|
||||
= submenu_entry truncate(content_type.name, :length => 15), content_entries_url(content_type.slug), :i18n => false, :css => "#{'on' if is_content_type_selected(content_type)}" do
|
||||
.wrapper
|
||||
.header
|
||||
%p= link_to t('locomotive.content_entries.index.new'), new_content_entry_url(content_type.slug)
|
||||
|
||||
- if can? :manage, content_type
|
||||
%p.edit= link_to t('locomotive.content_entries.index.edit'), edit_content_type_url(content_type)
|
||||
- if can? :manage, content_type
|
||||
%p.edit= link_to t('locomotive.content_types.index.edit'), edit_content_type_url(content_type)
|
||||
|
||||
.inner
|
||||
%h2!= t('locomotive.content_entries.index.lastest_entries')
|
||||
%ul
|
||||
- content_type.entries.latest_updated.each do |entry|
|
||||
%li
|
||||
= link_to truncate(entry._label(content_type), :length => 20), edit_content_entry_url(content_type.slug, entry)
|
||||
%span= time_ago_in_words(entry.updated_at)
|
||||
|
||||
/ - other_content_types do |content_types|
|
||||
/ .inner
|
||||
/ %ul.big-links
|
||||
/ - content_types.each do |content_type|
|
||||
/ %li
|
||||
/ = link_to truncate(content_type.name, :length => 20), contents_url(content_type.slug)
|
||||
.inner
|
||||
%h2!= t('locomotive.content_entries.index.lastest_entries')
|
||||
%ul
|
||||
- content_type.entries.latest_updated.each do |entry|
|
||||
%li
|
||||
= link_to truncate(entry._label(content_type), :length => 20), edit_content_entry_url(content_type.slug, entry)
|
||||
%span= time_ago_in_words(entry.updated_at)
|
@ -222,14 +222,15 @@ en:
|
||||
content_types:
|
||||
index:
|
||||
new: new model
|
||||
edit: edit model
|
||||
new:
|
||||
title: New model
|
||||
help: "Create your own data model (Projects, People, ...etc). Your model should have one field at least. The items created from this content type would have their first field mandatory."
|
||||
edit:
|
||||
title: Editing model
|
||||
help: "Your model should have one field at least. The items created from this content type would have their first field mandatory."
|
||||
show_items: show items
|
||||
new_item: new item
|
||||
show_entries: show entries
|
||||
new_entry: new entry
|
||||
form:
|
||||
order_by:
|
||||
created_at: 'By creation date'
|
||||
|
@ -41,7 +41,8 @@ en:
|
||||
default_site_template: "Use the default site template. Click <a href='#'>here</a> to upload a site template as a zip file instead."
|
||||
content_type:
|
||||
raw_item_template: Item template
|
||||
public_form_accounts: Notified Accounts
|
||||
public_submission_enabled: Public submission
|
||||
public_submission_accounts: Notified Accounts
|
||||
"custom_fields/field":
|
||||
select_options: "Options"
|
||||
content_entry:
|
||||
@ -53,6 +54,8 @@ en:
|
||||
password_confirmation: New password confirmation
|
||||
page:
|
||||
seo_title: Title
|
||||
site:
|
||||
locales: Languages
|
||||
|
||||
hints:
|
||||
page:
|
||||
@ -67,6 +70,7 @@ en:
|
||||
snippet:
|
||||
slug: "You need to know it in order to insert the snippet inside a page"
|
||||
site:
|
||||
locales: "Drag&drop a flag to the first position to make it the default one."
|
||||
seo_title: "Define a global value here which should be used as the value for the title tag in the head section."
|
||||
meta_keywords: "Meta keywords used within the head tag of the page. They are separated by a comma. Required for SEO."
|
||||
meta_description: "Meta description used within the head tag of the page. Required for SEO."
|
||||
@ -95,8 +99,8 @@ en:
|
||||
name: "We suggest you to type the plural form of the model. Ex: Projects, Recipes, Posts, Articles, ...etc"
|
||||
slug: "It will be used as the name of the collection in the liquid templates. Ex: <span class='code'>{{ contents.my_projects }}</span>"
|
||||
raw_item_template: "You can customize the text displayed for each item in the list. Simply use Liquid. Ex: <span class='code'>{{ entry.name }})</span>"
|
||||
public_form_enabled: "It is used to let people from outside to create new instances (example: messages in a contact form)"
|
||||
public_form_accounts: "A notification email will be sent to each of the accounts listed above when a new instance is created"
|
||||
public_submission_enabled: "It is used to let people from outside to create new entries (example: messages in a contact form)"
|
||||
public_submission_accounts: "If the public submission option is enabled and for each entry created, sends a notification email tothe accounts listed above."
|
||||
"custom_fields/field":
|
||||
name: "Name of the property for liquid templates. Ex: <span class='code'>{{ your_object.<name_of_your_field> }}</span>"
|
||||
hint: "Text displayed in the model form just below the field"
|
||||
|
@ -41,8 +41,6 @@ Locomotive::Engine.routes.draw do
|
||||
put :sort, :on => :collection
|
||||
end
|
||||
|
||||
resources :api_contents, :path => 'api/:slug/contents', :controller => 'api_contents', :only => [:create]
|
||||
|
||||
resources :custom_fields, :path => 'custom/:parent/:slug/fields'
|
||||
|
||||
resources :cross_domain_sessions, :only => [:new, :create]
|
||||
@ -58,13 +56,16 @@ end
|
||||
|
||||
Rails.application.routes.draw do
|
||||
# sitemap
|
||||
match '/sitemap.xml' => 'locomotive/sitemaps#show', :format => 'xml'
|
||||
match '/sitemap.xml' => 'locomotive/public/sitemaps#show', :format => 'xml'
|
||||
|
||||
# robots.txt
|
||||
match '/robots.txt' => 'locomotive/robots#show', :format => 'txt'
|
||||
match '/robots.txt' => 'locomotive/public/robots#show', :format => 'txt'
|
||||
|
||||
# public content entry submissions
|
||||
resources :locomotive_entry_submissions, :controller => 'locomotive/public/content_entries', :path => 'entry_submissions/:slug'
|
||||
|
||||
# magic urls
|
||||
match '/' => 'locomotive/rendering#show'
|
||||
match '*path/edit' => 'locomotive/rendering#edit'
|
||||
match '*path' => 'locomotive/rendering#show'
|
||||
match '/' => 'locomotive/public/rendering#show'
|
||||
match '*path/edit' => 'locomotive/public/rendering#edit'
|
||||
match '*path' => 'locomotive/public/rendering#show'
|
||||
end
|
16
doc/TODO
16
doc/TODO
@ -8,9 +8,9 @@ x bugs:
|
||||
x undefined method `_selector' for #<Locomotive::Page:0x00000107434768>
|
||||
x editable_elements => view + handlebar template
|
||||
x editable_short_text => tinymce
|
||||
- editable_file =>
|
||||
x editable_file =>
|
||||
x backbone / handlebar
|
||||
- new formtastic inputs
|
||||
x new formtastic inputs
|
||||
x menu / submenu in full css3 (no images)
|
||||
x fix css in firefox
|
||||
x update page in ajax
|
||||
@ -49,7 +49,7 @@ x edit my site
|
||||
x show / hide options of a field based on its type
|
||||
x select: add/edit/remove options
|
||||
x text: formatting
|
||||
- change in main menu
|
||||
x change in main menu
|
||||
x manage contents
|
||||
x list (highlighted field)
|
||||
x slugify
|
||||
@ -61,7 +61,15 @@ x edit my site
|
||||
x file
|
||||
x edit
|
||||
x destroy
|
||||
- public_form (previously api something)
|
||||
x public_form (previously api something)
|
||||
x bug text formatting
|
||||
- use list_or_group_entries instead of ordered_entries
|
||||
- bug ui with contents popup
|
||||
- custom_fields: use the appropriate icon to drag select options
|
||||
- i18n
|
||||
x add locales a site responds to
|
||||
- locale switcher
|
||||
- inline editor
|
||||
|
||||
- disallow to click twice on the submit form button (spinner ?)
|
||||
- message to notify people if their browser is too old
|
||||
|
@ -8,10 +8,13 @@
|
||||
- content_types:
|
||||
- category => select
|
||||
- highlighted_field_name => highlighted_field_id (label_field_id)
|
||||
- api_enabled => public_form_enabled
|
||||
- api_accounts => public_form_accounts
|
||||
- api_enabled => public_submission_enabled
|
||||
- api_accounts => public_submission_accounts
|
||||
- contents (content_entries now)
|
||||
- _position_in_list => _position
|
||||
- api_contents:
|
||||
- url => entry_submissions
|
||||
- params[:content] => params[:entries]
|
||||
|
||||
|
||||
collection, selector = Locomotive::ContentType.collection, Locomotive::ContentType.criteria.selector
|
||||
|
@ -44,11 +44,17 @@ Locomotive.configure do |config|
|
||||
config.delayed_job = false
|
||||
|
||||
# configure how many items we display in sub menu in the "Contents" section.
|
||||
# config.lastest_entries_nb = 5
|
||||
# config.ui = {
|
||||
# :lastest_entries_nb => 5,
|
||||
# :max_content_types => 4
|
||||
# }
|
||||
|
||||
# default locale (for now, only en, de, fr, pt-BR and it are supported)
|
||||
config.default_locale = :en
|
||||
|
||||
# available locales suggested to "localize" a site. You will have to pick up at least one among that list.
|
||||
# config.site_locales = %w{en de fr pt-BR it nl no es ru}
|
||||
|
||||
# tell if logs are enabled. Useful for debug purpose.
|
||||
config.enable_logs = true
|
||||
|
||||
|
@ -6,7 +6,6 @@ require 'locomotive/version'
|
||||
require 'locomotive/core_ext'
|
||||
require 'locomotive/configuration'
|
||||
require 'locomotive/logger'
|
||||
|
||||
require 'locomotive/formtastic'
|
||||
require 'locomotive/dragonfly'
|
||||
require 'locomotive/kaminari'
|
||||
@ -15,7 +14,7 @@ require 'locomotive/mongoid'
|
||||
require 'locomotive/carrierwave'
|
||||
require 'locomotive/custom_fields'
|
||||
require 'locomotive/httparty'
|
||||
require 'locomotive/responder'
|
||||
require 'locomotive/action_controller'
|
||||
require 'locomotive/routing'
|
||||
require 'locomotive/regexps'
|
||||
require 'locomotive/render'
|
||||
@ -76,11 +75,11 @@ module Locomotive
|
||||
self.add_middlewares
|
||||
|
||||
# Load all the dynamic classes (custom fields)
|
||||
# begin
|
||||
# ContentType.all.collect(&:fetch_content_klass)
|
||||
# rescue ::Mongoid::Errors::InvalidDatabase => e
|
||||
# # let assume it's because of the first install (meaning no config.yml file)
|
||||
# end
|
||||
begin
|
||||
ContentType.all.collect { |content_type| content_type.klass_with_custom_fields(:entries) }
|
||||
rescue ::Mongoid::Errors::InvalidDatabase => e
|
||||
# let assume it's because of the first install (meaning no config.yml file)
|
||||
end
|
||||
end
|
||||
|
||||
def self.add_middlewares
|
||||
|
3
lib/locomotive/action_controller.rb
Normal file
3
lib/locomotive/action_controller.rb
Normal file
@ -0,0 +1,3 @@
|
||||
require 'locomotive/action_controller/helpers'
|
||||
require 'locomotive/action_controller/responder'
|
||||
require 'locomotive/action_controller/public_responder'
|
91
lib/locomotive/action_controller/helpers.rb
Normal file
91
lib/locomotive/action_controller/helpers.rb
Normal file
@ -0,0 +1,91 @@
|
||||
module Locomotive
|
||||
module ActionController
|
||||
module Helpers
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
helper_method :current_site_public_url, :switch_to_site_url, :public_page_url, :current_content_locale
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
# ___ locales ___
|
||||
|
||||
def current_content_locale
|
||||
::Mongoid::Fields::I18n.locale
|
||||
end
|
||||
|
||||
def set_current_content_locale
|
||||
# I18n.default_site_locale = current_site.default_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)
|
||||
if !key.nil? && key.to_sym == :sub
|
||||
@locomotive_sections[:sub] || self.controller_name.dasherize
|
||||
else
|
||||
@locomotive_sections[:main]
|
||||
end
|
||||
end
|
||||
|
||||
# ___ site/page urls builder ___
|
||||
|
||||
def current_site_public_url
|
||||
request.protocol + request.host_with_port
|
||||
end
|
||||
|
||||
def switch_to_site_url(site, options = {})
|
||||
options = { :fullpath => true, :protocol => true }.merge(options)
|
||||
|
||||
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
||||
url += ":#{request.port}" if request.port != 80
|
||||
|
||||
url = File.join(url, request.fullpath) if options[:fullpath]
|
||||
url = "http://#{url}" if options[:protocol]
|
||||
url
|
||||
end
|
||||
|
||||
def public_page_url(page, options = {})
|
||||
if content = options.delete(:content)
|
||||
File.join(current_site_public_url, page.fullpath.gsub('content_type_template', ''), content._slug)
|
||||
else
|
||||
File.join(current_site_public_url, page.fullpath)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def sections(main, sub = nil)
|
||||
before_filter do |c|
|
||||
sub = sub.call(c) if sub.respond_to?(:call)
|
||||
sections = { :main => main, :sub => sub }
|
||||
c.instance_variable_set(:@locomotive_sections, sections)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
17
lib/locomotive/action_controller/public_responder.rb
Normal file
17
lib/locomotive/action_controller/public_responder.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Locomotive
|
||||
module ActionController
|
||||
class PublicResponder < ::ActionController::Responder
|
||||
|
||||
def navigation_behavior(error)
|
||||
if get?
|
||||
raise error
|
||||
elsif has_errors? && default_action
|
||||
redirect_to navigation_location
|
||||
else
|
||||
redirect_to navigation_location
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
63
lib/locomotive/action_controller/responder.rb
Normal file
63
lib/locomotive/action_controller/responder.rb
Normal file
@ -0,0 +1,63 @@
|
||||
module Locomotive
|
||||
module ActionController
|
||||
class Responder < ::ActionController::Responder
|
||||
|
||||
include ::Responders::FlashResponder
|
||||
|
||||
# by default flash_now messages if the resource has errors
|
||||
def set_flash_now?
|
||||
super || has_errors?
|
||||
end
|
||||
|
||||
def to_json
|
||||
if get?
|
||||
display resource
|
||||
elsif has_errors?
|
||||
with_flash_message(:alert) do
|
||||
display resource.errors, :status => :unprocessable_entity
|
||||
end
|
||||
elsif post?
|
||||
in_header = controller.request.headers['X-Flash'] == 'true'
|
||||
with_flash_message(:notice, in_header) do
|
||||
display resource, :location => api_location
|
||||
end
|
||||
elsif put?
|
||||
with_flash_message do |message|
|
||||
display resource, :status => :ok, :location => api_location
|
||||
end
|
||||
elsif delete?
|
||||
with_flash_message do |message|
|
||||
display resource, :status => :ok, :location => api_location
|
||||
end
|
||||
elsif has_empty_resource_definition?
|
||||
display empty_resource, :status => :ok
|
||||
else
|
||||
with_flash_message do
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def with_flash_message(type = :notice, in_header = true)
|
||||
if in_header
|
||||
set_flash_message!
|
||||
message = controller.flash[type]
|
||||
|
||||
controller.headers['X-Message'] = message
|
||||
controller.headers['X-Message-Type'] = type
|
||||
|
||||
yield if block_given?
|
||||
|
||||
controller.flash.discard # reset flash messages !
|
||||
else
|
||||
set_flash_message!
|
||||
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -8,6 +8,7 @@ module Locomotive
|
||||
# :forbidden_paths => %w{layouts snippets stylesheets javascripts assets admin system api},
|
||||
:reserved_slugs => %w{stylesheets javascripts assets admin images api pages edit},
|
||||
:locales => %w{en de fr pt-BR it nl no es ru},
|
||||
:site_locales => %w{en de fr pt-BR it nl no es ru},
|
||||
:cookie_key => '_locomotive_session',
|
||||
:enable_logs => false,
|
||||
:hosting => :auto,
|
||||
@ -16,7 +17,10 @@ module Locomotive
|
||||
:mailer_sender => 'support@example.com',
|
||||
:manage_subdomain => false,
|
||||
:manage_manage_domains => false,
|
||||
:lastest_entries_nb => 5,
|
||||
:ui => {
|
||||
:lastest_entries_nb => 5,
|
||||
:max_content_types => 2
|
||||
},
|
||||
:rack_cache => {
|
||||
:verbose => true,
|
||||
:metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
|
||||
|
@ -24,7 +24,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
initializer 'locomotive.action_controller' do |app|
|
||||
ActionController::Base.wrap_parameters :format => [:json]
|
||||
::ActionController::Base.wrap_parameters :format => [:json]
|
||||
end
|
||||
|
||||
end
|
||||
|
79
lib/locomotive/liquid/drops/content_types.rb
Normal file
79
lib/locomotive/liquid/drops/content_types.rb
Normal file
@ -0,0 +1,79 @@
|
||||
module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
class ContentTypes < ::Liquid::Drop
|
||||
|
||||
def before_method(meth)
|
||||
type = @context.registers[:site].content_types.where(:slug => meth.to_s).first
|
||||
ProxyCollection.new(type)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ProxyCollection < ::Liquid::Drop
|
||||
|
||||
def initialize(content_type)
|
||||
@content_type = content_type
|
||||
@collection = nil
|
||||
end
|
||||
|
||||
def first
|
||||
self.collection.first
|
||||
end
|
||||
|
||||
def last
|
||||
self.collection.last
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
self.collection.each(&block)
|
||||
end
|
||||
|
||||
def each_with_index(&block)
|
||||
self.collection.each_with_index(&block)
|
||||
end
|
||||
|
||||
def count
|
||||
@count ||= self.collection.count
|
||||
end
|
||||
|
||||
alias :size :count
|
||||
alias :length :count
|
||||
|
||||
def empty?
|
||||
self.collection.empty?
|
||||
end
|
||||
|
||||
def any?
|
||||
self.collection.any?
|
||||
end
|
||||
|
||||
def public_submission_url
|
||||
@context.registers[:controller].main_app.locomotive_entry_submissions_url(@content_type.slug)
|
||||
end
|
||||
|
||||
def before_method(meth)
|
||||
klass = @content_type.entries.klass # delegate to the proxy class
|
||||
|
||||
if (meth.to_s =~ /^group_by_.+$/) == 0
|
||||
klass.send(meth, :ordered_entries)
|
||||
else
|
||||
Rails.logger.warn "[Liquid template] trying to call #{meth} on a content_type object"
|
||||
# klass.send(meth)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def paginate(options = {})
|
||||
@collection.page(options[:page]).per(options[:per_page])
|
||||
end
|
||||
|
||||
def collection
|
||||
@collection ||= @content_type.ordered_entries(@context['with_scope'])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -1,79 +1,81 @@
|
||||
module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
class Contents < ::Liquid::Drop
|
||||
# DEPRECATED
|
||||
|
||||
# TODO: refactoring
|
||||
|
||||
def before_method(meth)
|
||||
type = @context.registers[:site].content_types.where(:slug => meth.to_s).first
|
||||
ProxyCollection.new(type)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ProxyCollection < ::Liquid::Drop
|
||||
|
||||
def initialize(content_type)
|
||||
@content_type = content_type
|
||||
@collection = nil
|
||||
end
|
||||
|
||||
def first
|
||||
self.collection.first
|
||||
end
|
||||
|
||||
def last
|
||||
self.collection.last
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
self.collection.each(&block)
|
||||
end
|
||||
|
||||
def each_with_index(&block)
|
||||
self.collection.each_with_index(&block)
|
||||
end
|
||||
|
||||
def size
|
||||
self.collection.size
|
||||
end
|
||||
|
||||
alias :length :size
|
||||
|
||||
def empty?
|
||||
self.collection.empty?
|
||||
end
|
||||
|
||||
def any?
|
||||
self.collection.any?
|
||||
end
|
||||
|
||||
def api
|
||||
{ 'create' => @context.registers[:controller].send('api_contents_url', @content_type.slug) }
|
||||
end
|
||||
|
||||
def before_method(meth)
|
||||
klass = @content_type.entries.klass # delegate to the proxy class
|
||||
|
||||
if (meth.to_s =~ /^group_by_.+$/) == 0
|
||||
klass.send(meth, :ordered_contents)
|
||||
else
|
||||
klass.send(meth)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def paginate(options = {})
|
||||
@collection = Kaminari.paginate_array(self.collection).page(options[:page]).per(options[:per_page])
|
||||
end
|
||||
|
||||
def collection
|
||||
@collection ||= @content_type.ordered_contents(@context['with_scope'])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
# module Locomotive
|
||||
# module Liquid
|
||||
# module Drops
|
||||
# class Contents < ::Liquid::Drop
|
||||
#
|
||||
# # TODO: refactoring
|
||||
#
|
||||
# def before_method(meth)
|
||||
# type = @context.registers[:site].content_types.where(:slug => meth.to_s).first
|
||||
# ProxyCollection.new(type)
|
||||
# end
|
||||
#
|
||||
# end
|
||||
#
|
||||
# class ProxyCollection < ::Liquid::Drop
|
||||
#
|
||||
# def initialize(content_type)
|
||||
# @content_type = content_type
|
||||
# @collection = nil
|
||||
# end
|
||||
#
|
||||
# def first
|
||||
# self.collection.first
|
||||
# end
|
||||
#
|
||||
# def last
|
||||
# self.collection.last
|
||||
# end
|
||||
#
|
||||
# def each(&block)
|
||||
# self.collection.each(&block)
|
||||
# end
|
||||
#
|
||||
# def each_with_index(&block)
|
||||
# self.collection.each_with_index(&block)
|
||||
# end
|
||||
#
|
||||
# def size
|
||||
# self.collection.size
|
||||
# end
|
||||
#
|
||||
# alias :length :size
|
||||
#
|
||||
# def empty?
|
||||
# self.collection.empty?
|
||||
# end
|
||||
#
|
||||
# def any?
|
||||
# self.collection.any?
|
||||
# end
|
||||
#
|
||||
# def api
|
||||
# { 'create' => @context.registers[:controller].send('api_contents_url', @content_type.slug) }
|
||||
# end
|
||||
#
|
||||
# def before_method(meth)
|
||||
# klass = @content_type.entries.klass # delegate to the proxy class
|
||||
#
|
||||
# if (meth.to_s =~ /^group_by_.+$/) == 0
|
||||
# klass.send(meth, :ordered_contents)
|
||||
# else
|
||||
# klass.send(meth)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# protected
|
||||
#
|
||||
# def paginate(options = {})
|
||||
# @collection = Kaminari.paginate_array(self.collection).page(options[:page]).per(options[:per_page])
|
||||
# end
|
||||
#
|
||||
# def collection
|
||||
# @collection ||= @content_type.ordered_contents(@context['with_scope'])
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
@ -1,3 +1,3 @@
|
||||
require 'locomotive/mongoid/document'
|
||||
require 'locomotive/mongoid/model_extensions'
|
||||
require 'locomotive/mongoid/patches'
|
||||
require 'locomotive/mongoid/patches'
|
@ -2,32 +2,33 @@
|
||||
|
||||
require 'mongoid'
|
||||
|
||||
module Mongoid
|
||||
module Document
|
||||
module Mongoid#:nodoc:
|
||||
module Document #:nodoc:
|
||||
def as_json(options = {})
|
||||
attrs = super(options)
|
||||
attrs["id"] = attrs["_id"]
|
||||
attrs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Limit feature for embedded documents
|
||||
module Fields #:nodoc:
|
||||
module Internal #:nodoc:
|
||||
class RawArray < Mongoid::Fields::Internal::Array
|
||||
def resizable?; false; end
|
||||
end
|
||||
end
|
||||
|
||||
module Mongoid #:nodoc:
|
||||
class RawArray < ::Array; end
|
||||
end
|
||||
|
||||
# without callback feature
|
||||
module Callbacks
|
||||
|
||||
module ClassMethods
|
||||
|
||||
module Callbacks #:nodoc:
|
||||
module ClassMethods #:nodoc:
|
||||
def without_callback(*args, &block)
|
||||
skip_callback(*args)
|
||||
yield
|
||||
set_callback(*args)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -61,7 +61,8 @@ module Locomotive
|
||||
assigns = {
|
||||
'site' => current_site,
|
||||
'page' => @page,
|
||||
'contents' => Locomotive::Liquid::Drops::Contents.new,
|
||||
'models' => Locomotive::Liquid::Drops::ContentTypes.new,
|
||||
'contents' => Locomotive::Liquid::Drops::ContentTypes.new, # DEPRECATED
|
||||
'current_page' => self.params[:page],
|
||||
'params' => self.params,
|
||||
'path' => request.path,
|
||||
@ -72,10 +73,12 @@ module Locomotive
|
||||
|
||||
assigns.merge!(Locomotive.config.context_assign_extensions)
|
||||
|
||||
assigns.merge!(flash.to_hash.stringify_keys) # data from api
|
||||
Rails.logger.debug flash.to_hash.stringify_keys.inspect
|
||||
|
||||
assigns.merge!(flash.to_hash.stringify_keys) # data from public submissions
|
||||
|
||||
if @page.templatized? # add instance from content type
|
||||
assigns['content_entry'] = @content_entry
|
||||
assigns['entry'] = @content_entry
|
||||
assigns[@page.content_type.slug.singularize] = @content_entry # just here to help to write readable liquid code
|
||||
end
|
||||
|
||||
@ -111,7 +114,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def editing_page?
|
||||
@editing
|
||||
!!@editing
|
||||
end
|
||||
|
||||
def page_status
|
||||
|
@ -1,61 +0,0 @@
|
||||
module Locomotive
|
||||
class Responder < ::ActionController::Responder
|
||||
|
||||
include ::Responders::FlashResponder
|
||||
|
||||
# by default flash_now messages if the resource has errors
|
||||
def set_flash_now?
|
||||
super || has_errors?
|
||||
end
|
||||
|
||||
def to_json
|
||||
if get?
|
||||
display resource
|
||||
elsif has_errors?
|
||||
with_flash_message(:alert) do
|
||||
display resource.errors, :status => :unprocessable_entity
|
||||
end
|
||||
elsif post?
|
||||
in_header = controller.request.headers['X-Flash'] == 'true'
|
||||
with_flash_message(:notice, in_header) do
|
||||
display resource, :location => api_location
|
||||
end
|
||||
elsif put?
|
||||
with_flash_message do |message|
|
||||
display resource, :status => :ok, :location => api_location
|
||||
end
|
||||
elsif delete?
|
||||
with_flash_message do |message|
|
||||
display resource, :status => :ok, :location => api_location
|
||||
end
|
||||
elsif has_empty_resource_definition?
|
||||
display empty_resource, :status => :ok
|
||||
else
|
||||
with_flash_message do
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def with_flash_message(type = :notice, in_header = true)
|
||||
if in_header
|
||||
set_flash_message!
|
||||
message = controller.flash[type]
|
||||
|
||||
controller.headers['X-Message'] = message
|
||||
controller.headers['X-Message-Type'] = type
|
||||
|
||||
yield if block_given?
|
||||
|
||||
controller.flash.discard # reset flash messages !
|
||||
else
|
||||
set_flash_message!
|
||||
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user