Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Andrea Frigido 2011-06-06 09:27:35 +02:00
commit 950e59abdc
26 changed files with 169 additions and 45 deletions

View File

@ -9,9 +9,10 @@ gem 'rails', '>= 3.0.7'
gem 'warden'
gem 'devise', '= 1.1.3'
gem 'mongoid', '~> 2.0.1'
gem 'mongoid', '~> 2.0.2'
gem 'bson_ext', '~> 1.3.0'
gem 'locomotive_mongoid_acts_as_tree', '0.1.5.5', :require => 'mongoid_acts_as_tree'
gem 'locomotive_mongoid_acts_as_tree', '0.1.5.7', :require => 'mongoid_acts_as_tree'
# gem 'locomotive_mongoid_acts_as_tree', '0.1.5.7', :require => 'mongoid_acts_as_tree', :path => '../gems/acts_as_tree'
gem 'will_paginate'
gem 'haml', '3.0.25'
@ -22,7 +23,8 @@ gem 'inherited_resources', '~> 1.1.2'
gem 'rmagick', '2.12.2'
gem 'locomotive_carrierwave', '0.5.0.1.beta3', :require => 'carrierwave'
gem 'custom_fields', '1.0.0.beta.13'
gem 'custom_fields', '1.0.0.beta.15'
# gem 'custom_fields', '1.0.0.beta.15', :path => '../gems/custom_fields'
gem 'fog', '0.3.7'
gem 'mimetype-fu'
gem 'actionmailer-with-request', :require => 'actionmailer_with_request'

View File

@ -1,6 +1,6 @@
GIT
remote: git://github.com/did/bushido_stub.git
revision: 6b83b2c4847832ffe7a213e725d2ceb7f864e360
revision: 87f64541b4444dd3ff9fd1c1c44ac20c549ce2c6
specs:
bushido_stub (0.0.1)
activesupport (>= 3.0.7)
@ -65,7 +65,7 @@ GEM
bson (1.3.1)
bson_ext (1.3.1)
builder (2.1.2)
bushido (0.0.14)
bushido (0.0.16)
highline (>= 1.6.1)
json (>= 1.4.6)
rest-client (>= 1.6.1)
@ -93,10 +93,10 @@ GEM
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
culerity (0.2.15)
custom_fields (1.0.0.beta.13)
custom_fields (1.0.0.beta.15)
activesupport (>= 3.0.7)
locomotive_carrierwave
mongoid (~> 2.0.1)
mongoid (= 2.0.2)
daemons (1.1.3)
database_cleaner (0.6.7)
delayed_job (2.1.4)
@ -127,7 +127,7 @@ GEM
nokogiri (~> 1.4.3.1)
ruby-hmac
formatador (0.1.4)
formtastic (1.2.3)
formtastic (1.2.4)
actionpack (>= 2.3.7)
activesupport (>= 2.3.7)
i18n (~> 0.4)
@ -165,8 +165,8 @@ GEM
mimemagic (>= 0.1.7)
s3 (>= 0.3.7)
locomotive_liquid (2.2.2)
locomotive_mongoid_acts_as_tree (0.1.5.5)
mongoid (~> 2.0.0.rc.7)
locomotive_mongoid_acts_as_tree (0.1.5.7)
mongoid (= 2.0.2)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@ -244,7 +244,7 @@ GEM
rubyzip (0.9.4)
s3 (0.3.8)
proxies (~> 0.2.0)
selenium-webdriver (0.2.0)
selenium-webdriver (0.2.1)
childprocess (>= 0.1.7)
ffi (>= 1.0.7)
json_pure
@ -280,7 +280,7 @@ DEPENDENCIES
capybara
cucumber (= 0.8.5)
cucumber-rails
custom_fields (= 1.0.0.beta.13)
custom_fields (= 1.0.0.beta.15)
database_cleaner
delayed_job (= 2.1.4)
delayed_job_mongoid (= 1.0.2)
@ -297,10 +297,10 @@ DEPENDENCIES
locomotive_carrierwave (= 0.5.0.1.beta3)
locomotive_jammit-s3
locomotive_liquid (= 2.2.2)
locomotive_mongoid_acts_as_tree (= 0.1.5.5)
locomotive_mongoid_acts_as_tree (= 0.1.5.7)
mimetype-fu
mocha!
mongoid (~> 2.0.1)
mongoid (~> 2.0.2)
pickle
rails (>= 3.0.7)
rake (= 0.8.7)

View File

@ -20,7 +20,7 @@ h2. Gems
Here is a short list of main gems used in the application.
* Rails 3.0.7
* Mongoid 2.0.1 (with MongoDB 1.6)
* Mongoid 2.0.2 (with MongoDB 1.6)
* Liquid
* Devise
* Carrierwave

View File

@ -7,7 +7,7 @@ module Admin::ContentTypesHelper
@content_types = current_site.content_types.ordered.
limit(:contents => Locomotive.config.lastest_items_nb).
only(:name, :slug, :highlighted_field_name, :content_custom_fields_version, :order_by).to_a
only(:name, :slug, :highlighted_field_name, :content_custom_fields_version, :order_by, :serialized_item_template).to_a
if @content_type && @content_type.persisted? && @content_types.index(@content_type) >= MAX_DISPLAYED_CONTENTS
@content_types.delete(@content_type)
@ -67,4 +67,23 @@ module Admin::ContentTypesHelper
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_admin => current_admin
}
preserve(content._parent.item_template.render(::Liquid::Context.new({}, assigns, registers)))
end
end
end

View File

@ -40,7 +40,9 @@ module Admin::CustomFieldsHelper
end
def options_for_association_target
current_site.content_types.collect { |c| [c.name, c.content_klass.to_s] }
current_site.content_types.collect do |c|
c.persisted? ? [c.name, c.content_klass.to_s] : nil
end.compact
end
def options_for_has_one(field)

View File

@ -2,6 +2,9 @@ class ContentType
include Locomotive::Mongoid::Document
## extensions ##
include Extensions::ContentType::ItemTemplate
## fields ##
field :name
field :description

View File

@ -0,0 +1,57 @@
module Extensions
module ContentType
module ItemTemplate
extend ActiveSupport::Concern
included do
field :raw_item_template
field :serialized_item_template, :type => Binary
before_validation :serialize_item_template
validate :item_template_must_be_valid
end
module InstanceMethods
def item_template
@item_template ||= Marshal.load(read_attribute(:serialized_item_template).to_s) rescue nil
end
protected
def serialize_item_template
if self.new_record? || self.raw_item_template_changed?
@item_parsing_errors = []
begin
self._parse_and_serialize_item_template
rescue ::Liquid::SyntaxError => error
@item_parsing_errors << I18n.t(:liquid_syntax, :error => error.to_s, :scope => [:errors, :messages])
end
end
end
def _parse_and_serialize_item_template
item_template = ::Liquid::Template.parse(self.raw_item_template, {})
self.serialized_item_template = BSON::Binary.new(Marshal.dump(item_template))
end
def item_template_must_be_valid
@item_parsing_errors.try(:each) { |msg| self.errors.add :item_template, msg }
end
# def item_template
# self.read_attribute(:default_item_template) || self.default_item_template
# end
#
# def default_item_template
# '{{ content.highlighted_field_value }}'
# end
end
end
end
end

View File

@ -36,9 +36,9 @@ module Extensions
begin
self._parse_and_serialize_template
rescue ::Liquid::SyntaxError => error
@parsing_errors << I18n.t(:liquid_syntax, :fullpath => self.fullpath, :error => error.to_s,:scope => [:errors, :messages])
@parsing_errors << I18n.t(:liquid_syntax, :fullpath => self.fullpath, :error => error.to_s, :scope => [:errors, :messages, :page])
rescue ::Locomotive::Liquid::PageNotFound => error
@parsing_errors << I18n.t(:liquid_extend, :fullpath => self.fullpath,:scope => [:errors, :messages])
@parsing_errors << I18n.t(:liquid_extend, :fullpath => self.fullpath, :scope => [:errors, :messages, :page])
end
end
end

View File

@ -13,6 +13,10 @@
= f.foldable_inputs :name => :presentation, :class => 'switchable' do
= f.input :highlighted_field_name, :as => :select, :collection => options_for_highlighted_field(f.object, 'contents'), :include_blank => false
= f.input :group_by_field_name, :as => :select, :collection => options_for_group_by_field(f.object, 'contents')
= f.custom_input :raw_item_template, :css => 'small-code' do
%code{ :class => 'html' }
= f.text_area :raw_item_template, :class => 'small'
= f.errors_on :item_template
= f.foldable_inputs :name => :options, :class => 'switchable' do
= f.input :order_by, :as => :select, :collection => options_for_order_by(f.object, 'contents'), :include_blank => false

View File

@ -6,7 +6,7 @@
%li.content{ :id => "content-#{content._id}" }
%em
%strong
= link_to content.send(@content_type.highlighted_field_name), edit_admin_content_path(@content_type.slug, content)
= link_to content_label_for(content), edit_admin_content_path(@content_type.slug, content)
.more
%span
!= t('admin.contents.index.updated_at')

View File

@ -49,6 +49,7 @@ javascripts:
- public/javascripts/admin/plugins/tiny_mce/tinymce.js
- public/javascripts/admin/contents.js
content_types:
- public/javascripts/admin/plugins/codemirror/codemirror.min.js
- public/javascripts/admin/content_types.js
site:
- public/javascripts/admin/site.js

View File

@ -4,5 +4,6 @@
"ruby_version": "1.9.2",
"sql": false,
"mongodb": true,
"start_page": "admin/pages"
"start_page": "admin/pages",
"project_name": "locomotive"
}

View File

@ -35,6 +35,7 @@ Locomotive::Application.configure do
# 'BUSHIDO_APP' => 'san_francisco',
# 'BUSHIDO_HOST' => 'bushi.do',
# 'LOCOMOTIVE_SITE_NAME' => 'Locomotive TEST',
# 'BUSHIDO_CLAIMED' => 'true'
# 'BUSHIDO_CLAIMED' => 'true',
# 'BUSHIDO_METRICS_TOKEN' => 'foobar'
# }
end

View File

@ -32,9 +32,12 @@ de:
protected_page: "Du kannst keine Index oder 404 Seiten löschen"
extname_changed: "Die neue Datei hat nicht die originale Dateiendung"
array_too_short: "ist zu kurz (minimale Element-Zahl ist %{count})"
liquid_syntax: "Liquid Syntax-Fehler, bitte überprüfe die Syntax ('%{error}')"
invalid_theme_file: "darf nicht leer sein oder ist keine zip-Datei"
page:
liquid_syntax: "Liquid Syntax-Fehler, bitte überprüfe die Syntax ('%{error}'/'%{fullpath}')"
liquid_extend: "Die Seite '%{fullpath}' verwendet eine Vorlage, die gar nicht existiert"
invalid_theme_file: "darf nicht leer sein oder ist keine zip-Datei"
attributes:
defaults:

View File

@ -11,9 +11,11 @@ en:
protected_page: "You can not remove index or 404 pages"
extname_changed: "New file does not have the original extension"
array_too_short: "is too small (minimum element number is %{count})"
liquid_syntax: "Liquid Syntax error ('%{error}')"
invalid_theme_file: "can't be blank or isn't a zip file"
page:
liquid_syntax: "Liquid Syntax error ('%{error}' on '%{fullpath}')"
liquid_extend: "The page '%{fullpath}' extends a template which does not exist"
invalid_theme_file: "can't be blank or isn't a zip file"
attributes:
defaults:

View File

@ -32,9 +32,11 @@ fr:
protected_page: "Vous ne pouvez pas supprimer les pages index et 404"
extname_changed: "Nouveau fichier n'a pas l'extension original"
array_too_short: "est trop petit (le nombre minimum d'éléments est %{count})"
liquid_syntax: "Erreur de syntaxe ('%{error}')"
invalid_theme_file: "doit être rempli ou n'est pas un fichier zip"
page:
liquid_syntax: "Erreur de syntaxe dans les sections de page, veuillez vérifier la syntaxe ('%{error}'/'%{fullpath}')"
liquid_extend: "La page '%{fullpath}' étend le contenu d'une page qui n'existe pas"
invalid_theme_file: "doit être rempli ou n'est pas un fichier zip"
attributes:
defaults:

View File

@ -38,9 +38,11 @@ it:
protected_page: "Non è possibile eliminare le pagine index e 404"
extname_changed: "Il nuovo file non ha l'estesione originale"
array_too_short: "troppo corto (il numero minimo di elementi è %{count})"
liquid_syntax: "Errore nella sintassi Liquid ('%{error}')"
invalid_theme_file: "non può essere vuoto o non è un file zip"
page:
liquid_syntax: "Errore nella sintassi Liquid ('%{error}' in '%{fullpath}')"
liquid_extend: "La pagina '%{fullpath}' estende un template che non esiste"
invalid_theme_file: "non può essere vuoto o non è un file zip"
attributes:
defaults:

View File

@ -30,9 +30,11 @@ pt-BR:
protected_page: "Você não pode remover a página inicial e a do erro 404"
extname_changed: "Novo arquivos não tem a mesma extensão que o original"
array_too_short: "é muito pequeno (mínimo de elementos é %{count})"
liquid_syntax: "Erro de sintaxe do Liquid, por favor verifique a sintaxe ('%{error}')"
invalid_theme_file: "não pode ser vazio ou não é um arquivo zip"
page:
liquid_syntax: "Erro de sintaxe do Liquid, por favor verifique a sintaxe"
liquid_extend: "A página extende um template que não existe."
invalid_theme_file: "não pode ser vazio ou não é um arquivo zip"
date:

View File

@ -38,6 +38,7 @@ en:
reset: Reset site
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
api_accounts: Notified Accounts
account:
edit:
@ -78,6 +79,7 @@ en:
samples: "If enabled, the import process will also copy contents and assets"
reset: "If enabled, all the data of your site will be destroyed before importing the new site"
content_type:
raw_item_template: "You can customize the text displayed for each item in the list. Simply use Liquid. Ex: {{ content.name }})"
api_enabled: "It is used to let people from outside to create new instances (example: messages in a contact form)"
api_accounts: "A notification email will be sent to each of the accounts listed above when a new instance is created"

View File

@ -40,6 +40,7 @@ fr:
samples: Copier contenu
reset: Remettre à zéro
content_type:
raw_item_template: Template d'affichage
api_accounts: Comptes à notifier
account:
edit:
@ -81,5 +82,6 @@ fr:
reset: "Si activé, toutes les données de votre site seront détruites avant l'import du nouveau site"
content_type:
slug: Nom utilisé dans les templates liquid afin d'accéder aux enregistrements de ce modèle
raw_item_template: "Personnaliser le texte affiché pour chaque élément de la liste. Utilisez simplement du code Liquid. Ex: {{ content.name }}"
api_enabled: "Utilisé pour autoriser la création de nouvelles instances de l'extérieur (ex.: les messages dans un formulaire de contact)"
api_accounts: "Un email de notification sera envoyé à chaque compte listé ci-dessus lors de la création d'une nouvelle instance"

View File

@ -13,6 +13,7 @@ module Locomotive
def initialize(app, opts = {})
@app = app
@bushido_app_name = ENV['BUSHIDO_APP']
@bushido_metrics_token = ENV['BUSHIDO_METRICS_TOKEN']
@bushido_claimed = ::Locomotive.bushido_app_claimed?
end
@ -27,9 +28,10 @@ module Locomotive
<script type="text/javascript">
var _bushido_app = '#{@bushido_app_name}';
var _bushido_claimed = #{@bushido_claimed.to_s};
var _bushido_metrics_token = '#{@bushido_metrics_token}';
(function() {
var bushido = document.createElement('script'); bushido.type = 'text/javascript'; bushido.async = true;
bushido.src = '#{BUSHIDO_JS_URL}';
bushido.src = '#{BUSHIDO_JS_URL}?#{::Bushido::VERSION.gsub('.', '')}';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bushido, s);
})();
</script>

View File

@ -2,7 +2,11 @@ module Locomotive
module Liquid
module Drops
class Content < Base
delegate :meta_keywords, :meta_description, :to => "@source"
delegate :meta_keywords, :meta_description, :to => '@source'
def _id
@source._id.to_s
end
def before_method(meth)
return '' if @source.nil?

View File

@ -62,7 +62,8 @@ module Locomotive
'asset_collections' => Locomotive::Liquid::Drops::AssetCollections.new,
'contents' => Locomotive::Liquid::Drops::Contents.new,
'current_page' => self.params[:page],
'params' => self.params
'params' => self.params,
'url' => request.url
}.merge(flash.stringify_keys) # data from api
if @page.templatized? # add instance from content type

View File

@ -20,9 +20,9 @@ Gem::Specification.new do |s|
s.add_dependency "rails", ">= 3.0.7"
s.add_dependency "warden"
s.add_dependency "devise", "1.1.3"
s.add_dependency "mongoid", "2.0.1"
s.add_dependency "mongoid", "2.0.2"
s.add_dependency "bson_ext", "~> 1.3.0"
s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.5"
s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.7"
s.add_dependency "will_paginate"
s.add_dependency "haml", "3.0.25"
@ -37,7 +37,7 @@ Gem::Specification.new do |s|
s.add_dependency "rmagick", "2.12.2"
s.add_dependency "locomotive_carrierwave", "0.5.0.1.beta3"
s.add_dependency "custom_fields", "1.0.0.beta.13"
s.add_dependency "custom_fields", "1.0.0.beta.15"
s.add_dependency "fog", "0.3.7"
s.add_dependency "mimetype-fu"
s.add_dependency "actionmailer-with-request"

View File

@ -22,7 +22,7 @@ var addCodeMirrorEditor = function(type, el, parser) {
parser = (parser || 'Liquid') + 'Parser';
var editor = CodeMirror.fromTextArea(el.attr('id'), {
height: "400px",
height: el.hasClass('small') ? '60px' : '400px',
stylesheet: [
"/stylesheets/admin/plugins/codemirror/csscolors.css",
"/stylesheets/admin/plugins/codemirror/xmlcolors.css",

View File

@ -144,6 +144,18 @@ form.formtastic fieldset ol li.code p.inline-errors {
background-image: none;
}
form.formtastic fieldset ol li.small-code code { margin: 0px; display: inline-block; width: 75%; }
form.formtastic fieldset ol li.small-code p.inline-errors {
position: relative;
display: block !important;
float: none;
margin-left: 20%;
width: 45%;
margin: 0.5em 0px 0px 20%;
left: 0px;
}
form.formtastic fieldset ol .more { text-align: right; width: auto; margin: 10px 20px 0 0; line-height: 0.6em; }
form.formtastic fieldset ol .more a { text-decoration: none; color: #787A89; font-size: 0.7em; }
form.formtastic fieldset ol .more a:hover { text-decoration: underline; }