espresso 0.1.12 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -2
- data/README.rdoc +18 -4
- data/Rakefile +33 -7
- data/VERSION +1 -1
- data/espresso.gemspec +59 -28
- data/lib/espresso.rb +36 -19
- data/lib/espresso/collection.rb +44 -0
- data/lib/espresso/collection/searchlogic.rb +17 -0
- data/lib/espresso/collection/will_paginate.rb +19 -0
- data/lib/espresso/concern.rb +37 -0
- data/lib/espresso/controller.rb +17 -0
- data/lib/espresso/controller/inherited_resources.rb +110 -0
- data/lib/espresso/deprecated.rb +19 -0
- data/lib/espresso/deprecated/resources.rb +11 -0
- data/lib/espresso/extensions/action_controller.rb +6 -0
- data/lib/espresso/extensions/action_view.rb +6 -0
- data/lib/espresso/extensions/active_record.rb +6 -0
- data/lib/espresso/extensions/all.rb +6 -0
- data/lib/espresso/{haml.rb → extensions/haml.rb} +4 -2
- data/lib/espresso/extensions/has_scope.rb +13 -0
- data/lib/espresso/extensions/inherited_resources.rb +15 -0
- data/lib/espresso/extensions/searchlogic.rb +14 -0
- data/lib/espresso/extensions/will_paginate.rb +14 -0
- data/lib/espresso/model.rb +22 -66
- data/lib/espresso/model/inherited_resources.rb +20 -0
- data/lib/espresso/view.rb +261 -0
- data/lib/espresso/{action_view → view}/form_builder.rb +3 -1
- data/lib/espresso/view/has_scope.rb +23 -0
- data/lib/espresso/view/inherited_resources.rb +72 -0
- data/lib/espresso/view/searchlogic.rb +33 -0
- data/lib/espresso/view/will_paginate.rb +35 -0
- data/test/espresso_collection_test.rb +6 -0
- data/test/espresso_controller_test.rb +1 -0
- data/test/espresso_extensions_haml_test.rb +19 -0
- data/test/espresso_model_test.rb +26 -0
- data/test/espresso_test.rb +1 -3
- data/test/espresso_view_has_scope_test.rb +11 -0
- data/test/espresso_view_test.rb +46 -0
- data/test/espresso_view_will_paginate_test.rb +9 -0
- data/test/example_model.rb +23 -0
- data/test/test_helper.rb +42 -1
- metadata +73 -33
- data/lib/espresso/action_controller.rb +0 -7
- data/lib/espresso/action_view.rb +0 -21
- data/lib/espresso/action_view/navigation.rb +0 -100
- data/lib/espresso/action_view/resources.rb +0 -59
- data/lib/espresso/action_view/scopes.rb +0 -38
- data/lib/espresso/action_view/stats.rb +0 -54
- data/lib/espresso/locales/en.yml +0 -6
- data/lib/espresso/locales/ru.yml +0 -11
- data/lib/espresso/resources.rb +0 -79
- data/lib/espresso/resources_helpers.rb +0 -24
data/lib/espresso/action_view.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Espresso
|
2
|
-
module ActionView
|
3
|
-
autoload :Resources, 'espresso/action_view/resources'
|
4
|
-
autoload :Scopes, 'espresso/action_view/scopes'
|
5
|
-
autoload :Navigation, 'espresso/action_view/navigation'
|
6
|
-
autoload :FormBuilder, 'espresso/action_view/form_builder'
|
7
|
-
autoload :Stats, 'espresso/action_view/stats'
|
8
|
-
|
9
|
-
include Resources
|
10
|
-
include Scopes
|
11
|
-
include Navigation
|
12
|
-
include Stats
|
13
|
-
|
14
|
-
# Make body’s modifiers, based on controller_name and action_name
|
15
|
-
def body_modifiers
|
16
|
-
{:class => "m-#{controller_name} m-#{controller_name}_#{action_name}"}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
Formtastic::SemanticFormHelper.builder = Espresso::ActionView::FormBuilder
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'will_paginate/view_helpers'
|
2
|
-
|
3
|
-
module Espresso
|
4
|
-
module ActionView
|
5
|
-
module Navigation
|
6
|
-
VIEW_PLACEHOLDERS = {
|
7
|
-
'create' => 'new',
|
8
|
-
'update' => 'edit'
|
9
|
-
}
|
10
|
-
|
11
|
-
# Finds apropriate view name
|
12
|
-
def view_name
|
13
|
-
unless @view_name
|
14
|
-
action_name = controller.action_name
|
15
|
-
@view_name = VIEW_PLACEHOLDERS[action_name] || action_name
|
16
|
-
end
|
17
|
-
@view_name
|
18
|
-
end
|
19
|
-
|
20
|
-
# Make default page title, based on controller and action
|
21
|
-
def default_page_title
|
22
|
-
text = case view_name
|
23
|
-
when 'index'
|
24
|
-
controller_name.camelize
|
25
|
-
when 'new'
|
26
|
-
"#{t('espresso.navigation.new', :default => 'New')} #{controller_name.classify.constantize.human_name}"
|
27
|
-
when 'edit'
|
28
|
-
"#{t('espresso.navigation.edit', :default => 'Editing')} #{controller_name.classify.constantize.human_name}"
|
29
|
-
else
|
30
|
-
t("navigation.#{controller_name}.#{view_name}")
|
31
|
-
end
|
32
|
-
%(<span class="translation_missing">#{text}</span>)
|
33
|
-
end
|
34
|
-
|
35
|
-
def page_title(title = nil, strip = false)
|
36
|
-
@page_title = if title
|
37
|
-
title
|
38
|
-
elsif @page_title
|
39
|
-
@page_title
|
40
|
-
else
|
41
|
-
default = if Rails.env.production?
|
42
|
-
default_page_title
|
43
|
-
else
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
rsrc = if resource?
|
48
|
-
if resource.new_record?
|
49
|
-
resource_class.human_name
|
50
|
-
else
|
51
|
-
link_to(resource, resource_path)
|
52
|
-
end
|
53
|
-
else
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
|
57
|
-
t("navigation.#{controller_name}.#{view_name}",
|
58
|
-
:default => default,
|
59
|
-
:resource => rsrc
|
60
|
-
)
|
61
|
-
end
|
62
|
-
if strip
|
63
|
-
strip_tags(@page_title)
|
64
|
-
else
|
65
|
-
@page_title
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def head_title(default = false, separator = ' | ')
|
70
|
-
default ||= t('application.meta.title')
|
71
|
-
strip_tags([page_title, default].compact.join(separator))
|
72
|
-
end
|
73
|
-
|
74
|
-
def navigation_list(menu)
|
75
|
-
returning '' do |result|
|
76
|
-
menu.each do |item|
|
77
|
-
path = "/#{item}"
|
78
|
-
uri = request.request_uri
|
79
|
-
title = t("navigation.#{item}.index", :default => item.to_s.camelize)
|
80
|
-
result << content_tag(:li, :class => uri.starts_with?(path) ? 'selected' : nil) do
|
81
|
-
link_to_unless_current(title, path) {
|
82
|
-
content_tag(:strong, title)
|
83
|
-
}
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
include WillPaginate::ViewHelpers
|
90
|
-
def will_paginate_with_i18n(collection, options = {})
|
91
|
-
will_paginate_without_i18n(collection,
|
92
|
-
options.merge({
|
93
|
-
:class => 'b-pagination',
|
94
|
-
:previous_label => t('espresso.navigation.previous', :default => '← Previous'),
|
95
|
-
:next_label => t('espresso.navigation.next', :default => 'Next →')}))
|
96
|
-
end
|
97
|
-
alias_method_chain :will_paginate, :i18n
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module Espresso
|
2
|
-
module ActionView
|
3
|
-
module Resources
|
4
|
-
def link_to_new(klass=nil, path=nil)
|
5
|
-
klass ||= resource_class
|
6
|
-
klass_underscored = klass.name.underscore
|
7
|
-
path ||= if klass == resource_class
|
8
|
-
new_resource_path
|
9
|
-
else
|
10
|
-
[:new, klass_underscored]
|
11
|
-
end
|
12
|
-
link_to(t("helpers.action.#{klass_underscored}.new",
|
13
|
-
:default => [:'helpers.action.new', 'Добавить']),
|
14
|
-
path,
|
15
|
-
:class => 'b-action b-action_new')
|
16
|
-
rescue
|
17
|
-
end
|
18
|
-
|
19
|
-
def link_to_show(object=nil)
|
20
|
-
object ||= resource
|
21
|
-
link_to(t("helpers.action.#{object.class.name.underscore}.show",
|
22
|
-
:default => [:'helpers.action.show', object.to_s]),
|
23
|
-
object,
|
24
|
-
:class => 'b-action b-action_show')
|
25
|
-
rescue
|
26
|
-
end
|
27
|
-
|
28
|
-
def link_to_edit(object=nil, path=nil)
|
29
|
-
object ||= resource
|
30
|
-
path ||= object == resource ? edit_resource_path : [:edit, object]
|
31
|
-
link_to(t("helpers.action.#{object.class.name.underscore}.edit",
|
32
|
-
:default => [:'helpers.action.edit', 'Редактировать']),
|
33
|
-
path,
|
34
|
-
:class => 'b-action b-action_edit')
|
35
|
-
rescue
|
36
|
-
end
|
37
|
-
|
38
|
-
def link_to_destroy(object=nil, path=nil)
|
39
|
-
object ||= resource
|
40
|
-
path ||= object == resource ? resource_path : object
|
41
|
-
link_to(t("helpers.action.#{object.class.name.underscore}.edit",
|
42
|
-
:default => [:'helpers.action.destroy', 'Удалить']),
|
43
|
-
path,
|
44
|
-
:class => 'b-action b-action_destroy',
|
45
|
-
:method => :delete,
|
46
|
-
:confirm => 'Вы уверены?')
|
47
|
-
end
|
48
|
-
|
49
|
-
def link_to_index
|
50
|
-
link_to(t("helpers.action.#{controller_name.singularize}.index",
|
51
|
-
:default => [:'helpers.action.index', '← К списку']),
|
52
|
-
collection_path,
|
53
|
-
:class => 'b-action b-action_index'
|
54
|
-
)
|
55
|
-
rescue
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Espresso
|
2
|
-
module ActionView
|
3
|
-
module Scopes
|
4
|
-
def simple_search
|
5
|
-
returning '' do |form|
|
6
|
-
form << form_tag(url_for(:action => :index), :method => :get)
|
7
|
-
form << content_tag(:table, :class => 'b-search') do
|
8
|
-
content_tag(:tr) do
|
9
|
-
returning '' do |result|
|
10
|
-
result << content_tag(:td,
|
11
|
-
content_tag(:div, text_field_tag(:q, params[:q], :type => 'search'), :class => 'b-input'),
|
12
|
-
:class => 'input')
|
13
|
-
result << content_tag(:td,
|
14
|
-
submit_tag(t('krasivotokak.espresso.find', :default => 'Find!'), :class => 'submit'),
|
15
|
-
:class => 'button')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
form << yield if block_given?
|
20
|
-
form << '</form>'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def scope_filter(scopes)
|
25
|
-
items = scopes.inject([]) do |list, scope|
|
26
|
-
list << link_to_unless_current(t(".#{scope}"), collection_path(scope => true))
|
27
|
-
list
|
28
|
-
end
|
29
|
-
|
30
|
-
content_tag(:div, :class => 'b-scope-filter') do
|
31
|
-
content_tag(:ul, :class => 'b-hlist b-hlist_vline') do
|
32
|
-
"<li>#{items.join('<li></li>')}</li>"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Espresso
|
2
|
-
module ActionView
|
3
|
-
module Stats
|
4
|
-
# Set online statistics trackers
|
5
|
-
# @options
|
6
|
-
def online_stats(options = {})
|
7
|
-
static_includes = []
|
8
|
-
dynamic_includes = ''
|
9
|
-
noscript_includes = []
|
10
|
-
initializers = []
|
11
|
-
|
12
|
-
if piwik = options.delete(:piwik)
|
13
|
-
static_includes << "//#{piwik[:site]}/piwik.js"
|
14
|
-
initializers << "var piwikTracker=Piwik.getTracker('//#{piwik[:site]}/piwik.php',#{piwik[:id]});piwikTracker.trackPageView();piwikTracker.enableLinkTracking();"
|
15
|
-
noscript_includes << "//#{piwik[:site]}/piwik.php?idsite=#{piwik[:id]}"
|
16
|
-
end
|
17
|
-
|
18
|
-
if metrika = options.delete(:metrika)
|
19
|
-
static_includes << '//mc.yandex.ru/resource/watch.js'
|
20
|
-
initializers << "var yaCounter#{metrika}=new Ya.Metrika(#{metrika});"
|
21
|
-
noscript_includes << "//mc.yandex.ru/watch/#{metrika}"
|
22
|
-
end
|
23
|
-
|
24
|
-
if analytics = options.delete(:analytics)
|
25
|
-
dynamic_includes << 'var gaJsHost=("https:"==document.location.protocol)?"https://ssl.":"http://www.";'
|
26
|
-
dynamic_includes << 'document.write(unescape("%3Cscript src=\'"+gaJsHost+"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3Ei"));'
|
27
|
-
initializers << "var pageTracker=_gat._getTracker('#{analytics}');pageTracker._trackPageview();"
|
28
|
-
end
|
29
|
-
|
30
|
-
returning('') do |result|
|
31
|
-
unless dynamic_includes.empty?
|
32
|
-
result << javascript_tag(dynamic_includes)
|
33
|
-
end
|
34
|
-
result << javascript_include_tag(static_includes) unless static_includes.empty?
|
35
|
-
unless initializers.empty?
|
36
|
-
initializers = initializers.collect do |initializer|
|
37
|
-
"try {#{initializer}} catch(e) {}"
|
38
|
-
end.join("\n")
|
39
|
-
result << javascript_tag(initializers)
|
40
|
-
end
|
41
|
-
unless noscript_includes.empty?
|
42
|
-
includes = noscript_includes.collect do |noscript|
|
43
|
-
%(<img src="#{noscript}" style="border:0" alt="" />)
|
44
|
-
end.join("\n")
|
45
|
-
result << content_tag(:noscript,
|
46
|
-
content_tag(:div,
|
47
|
-
includes,
|
48
|
-
:style => 'position: absolute'))
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/espresso/locales/en.yml
DELETED
data/lib/espresso/locales/ru.yml
DELETED
data/lib/espresso/resources.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'inherited_resources'
|
2
|
-
require 'has_scope'
|
3
|
-
|
4
|
-
module Espresso
|
5
|
-
module Resources
|
6
|
-
def self.resources(controller = nil)
|
7
|
-
controller ||= self
|
8
|
-
controller.inherit_resources
|
9
|
-
controller.extend ClassMethods
|
10
|
-
controller.send(:include, InstanceMethods)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.included(controller)
|
14
|
-
resources(controller)
|
15
|
-
end
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
# Adds ability to build feeds for resource’s collections.
|
19
|
-
# By default adds Atom feed
|
20
|
-
# @example Add Atom feed for #index
|
21
|
-
# has_feed :atom
|
22
|
-
# @example Add Atom and RSS feed for #index
|
23
|
-
# has_feed :atom, :rss
|
24
|
-
# @example Add Atom, Rss, and ITunes feed for #index, #list and #archive
|
25
|
-
# has_feed :atom, :rss, :itunes_feed, :only => [:index, :list, :archive]
|
26
|
-
def has_feed(*args)
|
27
|
-
options = args.extract_options!
|
28
|
-
if options.empty?
|
29
|
-
options[:only] = :index
|
30
|
-
end
|
31
|
-
|
32
|
-
class_inheritable_accessor(:feed_formats) unless respond_to?(:feed_formats)
|
33
|
-
self.feed_formats = args.empty? ? [:atom] : args
|
34
|
-
self.feed_formats = self.feed_formats.map(&:to_sym)
|
35
|
-
|
36
|
-
self.feed_formats.each do |format|
|
37
|
-
respond_to format, options
|
38
|
-
end
|
39
|
-
|
40
|
-
include FeedScope
|
41
|
-
has_scope :for_feed, options.merge(:default => true,
|
42
|
-
:type => :boolean,
|
43
|
-
:if => :feed_scope_applicable?)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module FeedScope
|
48
|
-
def feed_scope_applicable?
|
49
|
-
params[:format] && self.class.feed_formats.include?(params[:format].to_sym)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module InstanceMethods
|
54
|
-
protected
|
55
|
-
|
56
|
-
# Find collection of objects with pagination.
|
57
|
-
# Also made Searchlogic object @search
|
58
|
-
#
|
59
|
-
# @return [WillPaginate::Collection] collection of objects
|
60
|
-
def collection
|
61
|
-
unless (result = get_collection_ivar).present?
|
62
|
-
@search, result = end_of_association_chain.for_index.
|
63
|
-
search_results(params[:page],
|
64
|
-
params[:query],
|
65
|
-
params[:q])
|
66
|
-
set_collection_ivar(result)
|
67
|
-
end
|
68
|
-
result
|
69
|
-
end
|
70
|
-
|
71
|
-
# Build interpolation options for flash messages
|
72
|
-
def interpolation_options
|
73
|
-
if resource?
|
74
|
-
{ :resource_title => resource.to_s }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Espresso
|
2
|
-
module ResourcesHelpers
|
3
|
-
def self.included(base)
|
4
|
-
super
|
5
|
-
base.send(:helper_method, :resource?, :collection?)
|
6
|
-
end
|
7
|
-
|
8
|
-
# Does the action or view have a resource
|
9
|
-
# @return [Boolean] having a resource
|
10
|
-
def resource?
|
11
|
-
resource
|
12
|
-
rescue
|
13
|
-
false
|
14
|
-
end
|
15
|
-
|
16
|
-
# Does the action or view have a collection of objects
|
17
|
-
# @return [Boolean] having a collection
|
18
|
-
def collection?
|
19
|
-
collection
|
20
|
-
rescue
|
21
|
-
false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|