Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of git://github.com/alsemyonov/espresso into ra…
…ils3
  • Loading branch information
Alexander Semyonov committed Jun 19, 2010
2 parents c079e66 + dd96cc8 commit fda77f0
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 24 deletions.
4 changes: 3 additions & 1 deletion app/views/espresso/_form.html.haml
@@ -1,4 +1,6 @@
- semantic_form_for(resource, :url => resource.new_record? ? collection_path : resource_path(resource), :html => {:class => 'b-espresso-form'}) do |f|
- semantic_form_for(resource,
:url => resource.new_record? ? collection_path : resource_path(resource),
:html => {:class => 'b-espresso-form', :multipart => true}) do |f|
- if manage_options.field_sets?
- manage_options.field_sets.each do |field_set|
- f.inputs field_set.options do
Expand Down
4 changes: 4 additions & 0 deletions config/locales/ru.yml
Expand Up @@ -6,9 +6,13 @@ ru:
view:
created_and_updated: "{{created}}—{{updated}}"
helpers:
filter: Показать
action:
new: Добавить
show: Просмотреть
edit: Редактировать
destroy: Удалить
confirm_destroy: Вы уверены, что хотите удалить?
time:
formats:
compact: "%d.%m.%Y, %H:%M"
7 changes: 5 additions & 2 deletions lib/espresso/manage/base_options.rb
Expand Up @@ -2,6 +2,8 @@

module Espresso::Manage
class BaseOptions
STUFF_FIELDS = [:id, :updated_at, :type]

attr_accessor :model_class, :main_field,
:filter_vertical, :filter_horizontal,
:radio_fields, :prepopulated_fields
Expand All @@ -17,8 +19,9 @@ def initialize(model_class = nil, options = {})
self.model_class = model_class
self.main_field = model_class.name_field if model_class.respond_to?(:name_field)
fields = model_class.columns.collect do |column|
column.name.to_sym
end - [:id, :updated_at, :type, main_field]
column_name = column.name
column_name.gsub(/_id$/, '').to_sym
end - STUFF_FIELDS - [main_field]
@fields = FieldSet.new(self)
([main_field] + fields).each do |field_name|
@fields << Field.new(self, field_name)
Expand Down
37 changes: 32 additions & 5 deletions lib/espresso/view.rb
Expand Up @@ -120,12 +120,19 @@ def default_page_title
when 'edit'
"#{t('espresso.navigation.edit', :default => 'Edit')} #{(resource? ? resource_class : controller_name.classify.constantize).model_name.human}"
end
%(<span class="translation_missing">#{text}</span>)
else
if resource?
resource.to_s
else
"#{controller_name}#{action_name}"
end
end.html_safe
%(<span class="translation_missing">#{text}</span>).html_safe
end

def page_title(title = nil, strip = false)
@page_title = if title
title
title.to_s
elsif @page_title
@page_title
else
Expand All @@ -141,10 +148,10 @@ def page_title(title = nil, strip = false)
nil
end

t("navigation.#{controller_name}.#{view_name}",
t("navigation.#{controller.controller_path.gsub(/\//, '.')}.#{view_name}",
:default => default,
:resource => rsrc
)
).html_safe
end
if strip
strip_tags(@page_title)
Expand All @@ -164,7 +171,7 @@ def head_title(default = false, separator = ' | ')
def navigation_list(menu, prefix = nil)
''.tap do |result|
menu.each do |item|
path = prefix ? "/#{prefix}/#{item}" : "/#{item}"
path = url_for(:controller => prefix ? "#{prefix}/#{item}" : item, :only_path => true)
uri = request.request_uri
title = t(['navigation', prefix, item, 'index'].compact.join('.'),
:default => item.to_s.camelize)
Expand All @@ -174,6 +181,22 @@ def navigation_list(menu, prefix = nil)
}
end
end
end.html_safe
end

def filter_links(filter)
content_tag(:div, :class => 'b-filter') do
content_tag(:span, "#{t('view.helpers.filter', :default => 'Filter')}: ") <<
content_tag(:ul, :class => 'b-hlist b-hlist_space') do
filter.inject(''.html_safe) do |result, link|
result << content_tag(:li,
link_to_unless_current(t(".#{link}",
:default => link.humanize),
{link => true},
:class => 'ajax'),
:class => link)
end
end
end
end

Expand Down Expand Up @@ -273,5 +296,9 @@ def body_modifiers
end

if defined?(Searchlogic)
require 'espresso/view/searchlogic'
end

if defined?(Formtastic)
require 'espresso/view/form_builder'
end
18 changes: 7 additions & 11 deletions lib/espresso/view/inherited_resources.rb
Expand Up @@ -64,27 +64,23 @@ def link_to_destroy(object=nil, path=nil)
end

def link_to_index
link_to(t("navigation.#{controller_name}.index",
:default => [:'helpers.action.index', '&larr; Back']),
collection_path,
:class => 'b-action b-action_index')
link_to(t("navigation.#{controller.controller_path.gsub(/\//, '.')}.index",
:default => [:'helpers.action.index', '&larr; Back']).html_safe,
collection_path,
:class => 'b-action b-action_index')
rescue
end

def resource_breadcrumbs(options = {})
content_tag(:ol, :class => 'b-hlist b-hlist_arrow') do
breadcrumbs = [].tap do |result|
''.html_safe.tap do |result|
if resource?
result << link_to_index
result << content_tag(:li, link_to_index)
if action_name != 'show'
result << link_to_show
result << content_tag(:li, link_to_show)
end
end
end
concat debug(breadcrumbs)
breadcrumbs.map do |link|
content_tag(:li, link)
end.join
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions lib/espresso/view/inherited_resources/manage.rb
Expand Up @@ -8,11 +8,11 @@ def manage_column_representation(object, field)

if field.name == :created_at
value = if value == object.updated_at
time(value)
time(value, :format => :compact)
else
t('espresso.view.created_and_updated',
:created => time(value),
:updated => time(object.updated_at))
:created => time(value, :format => :compact),
:updated => time(object.updated_at, :format => :compact)).html_safe
end
end

Expand All @@ -22,7 +22,8 @@ def manage_column_representation(object, field)
when Date
date(value)
when ::ActiveRecord::Base
link_to(value, value)
link_to(value, url_for(:controller => value.class.name.tableize,
:action => :edit, :id => value.to_param))
else
if respond_to?(:manage_field_typecast)
manage_field_typecast(value)
Expand Down
49 changes: 49 additions & 0 deletions lib/espresso/view/searchlogic.rb
@@ -1,8 +1,11 @@
require 'espresso/view'
require 'searchlogic'
require 'searchlogic/rails_helpers'

module Espresso::View
module InstanceMethods
include Searchlogic::RailsHelpers

def simple_search
''.tap do |form|
form << form_tag(url_for(:action => :index), :method => :get)
Expand All @@ -29,5 +32,51 @@ def simple_search
end
end

# Creates a link that alternates between acending and descending. It basically
# alternates between calling 2 named scopes: "ascend_by_*" and "descend_by_*"
#
# By default Searchlogic gives you these named scopes for all of your columns, but
# if you wanted to create your own, it will work with those too.
#
# Examples:
#
# order @search, :by => :username
# order @search, :by => :created_at, :as => "Created"
#
# This helper accepts the following options:
#
# * <tt>:by</tt> - the name of the named scope. This helper will prepend this value with "ascend_by_" and "descend_by_"
# * <tt>:as</tt> - the text used in the link, defaults to whatever is passed to :by
# * <tt>:ascend_scope</tt> - what scope to call for ascending the data, defaults to "ascend_by_:by"
# * <tt>:descend_scope</tt> - what scope to call for descending the data, defaults to "descend_by_:by"
# * <tt>:params</tt> - hash with additional params which will be added to generated url
# * <tt>:params_scope</tt> - the name of the params key to scope the order condition by, defaults to :search
def order(search, options = {}, html_options = {})
options[:params_scope] ||= :search
if !options[:as]
id = options[:by].to_s.downcase == "id"
options[:as] = id ? options[:by].to_s.upcase : options[:by].to_s.humanize
end
options[:ascend_scope] ||= "ascend_by_#{options[:by]}"
options[:descend_scope] ||= "descend_by_#{options[:by]}"
ascending = search.order.to_s == options[:ascend_scope]
new_scope = ascending ? options[:descend_scope] : options[:ascend_scope]
selected = [options[:ascend_scope], options[:descend_scope]].include?(search.order.to_s)
if selected
css_classes = html_options[:class] ? html_options[:class].split(" ") : []
if ascending
options[:as] = "↑&nbsp;#{options[:as]}"
css_classes << "ascending"
else
options[:as] = "↓&nbsp;#{options[:as]}"
css_classes << "descending"
end
html_options[:class] = css_classes.join(" ")
end
url_options = {
options[:params_scope] => search.conditions.merge( { :order => new_scope } )
}.deep_merge(options[:params] || {})
link_to options[:as].html_safe, url_for(url_options), html_options
end
end
end
2 changes: 1 addition & 1 deletion lib/espresso/view/will_paginate.rb
Expand Up @@ -21,7 +21,7 @@ def paginated_list(collection_name, options = {})
prefix = options.delete(:prefix)
prefix = prefix ? " b-list_#{prefix}_#{collection_name}" : nil
start = (collection.respond_to?(:offset) ? collection.offset : 0) + 1
''.tap do |result|
''.html_safe.tap do |result|
result << content_tag(:ol,
render(collection),
:class => "b-list b-list_#{collection_name}#{prefix}",
Expand Down

0 comments on commit fda77f0

Please sign in to comment.