neuron 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/neuron/navigation.rb +3 -2
- data/lib/neuron/resources.rb +14 -13
- data/lib/neuron/version.rb +1 -1
- metadata +1 -1
data/lib/neuron/navigation.rb
CHANGED
@@ -23,7 +23,8 @@ module Neuron
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def page_title(title = nil, options = {})
|
26
|
-
options =
|
26
|
+
options = default_options.merge(options)
|
27
|
+
options = options.merge(default: navigation_title(title, options))
|
27
28
|
@page_title ||= title || view.t('.title', options)
|
28
29
|
end
|
29
30
|
|
@@ -49,7 +50,7 @@ module Neuron
|
|
49
50
|
# @param [String, nil] title title to set
|
50
51
|
# @param [Hash] options options to {I18n#translate} if building default title
|
51
52
|
def page_title(title = nil, options = {})
|
52
|
-
neuron_title.page_title(title, options)
|
53
|
+
neuron_title.page_title(title, options).html_safe
|
53
54
|
end
|
54
55
|
|
55
56
|
def navigation_title(title = nil, options = {})
|
data/lib/neuron/resources.rb
CHANGED
@@ -43,34 +43,33 @@ module Neuron
|
|
43
43
|
# @param [Hash] html_options html options hash
|
44
44
|
# @option options [Symbol, String] :by the name of the columnt to sort by
|
45
45
|
# @option options [String] :as the text used in link, defaults to human_method_name of :by
|
46
|
-
# @option options [String] :
|
46
|
+
# @option options [String] :url url options when order link does not correspond to current collection_path
|
47
47
|
def order(options = {}, html_options = {})
|
48
|
+
options[:class] ||= resource_class
|
48
49
|
options[:by] = options[:by].to_sym
|
49
|
-
options[:as] ||= human(
|
50
|
+
options[:as] ||= human(options[:class], options[:by])
|
50
51
|
asc_orders = Array(params[:ascending]).map(&:to_sym)
|
51
52
|
desc_orders = Array(params[:descending]).map(&:to_sym)
|
52
53
|
ascending = asc_orders.include?(options[:by])
|
53
54
|
selected = ascending || desc_orders.include?(options[:by])
|
54
55
|
new_scope = ascending ? :descending : :ascending
|
55
|
-
url_options =
|
56
|
+
url_options = {page: params[:page]}
|
57
|
+
url_options[new_scope] = [options[:by]]
|
56
58
|
|
57
59
|
if selected
|
58
60
|
css_classes = html_options[:class] ? html_options[:class].split(/\s+/) : []
|
59
61
|
if ascending # selected
|
60
62
|
options[:as] = "▲ #{options[:as]}"
|
61
63
|
css_classes << 'ascending'
|
62
|
-
url_options[:ascending] = url_options[:ascending] - [options[:by]]
|
63
64
|
else # descending selected
|
64
65
|
options[:as] = "▼ #{options[:as]}"
|
65
66
|
css_classes << 'descending'
|
66
|
-
url_options[:descending] = url_options[:descending] - [options[:by]]
|
67
67
|
end
|
68
68
|
html_options[:class] = css_classes.join(' ')
|
69
69
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
link_to(options[:as].html_safe, collection_path(url_options.deep_merge(options[:params] || {})), html_options)
|
70
|
+
url = options[:url] ? url_for(options[:url].merge(url_options)) : collection_path(url_options)
|
71
|
+
|
72
|
+
link_to(options[:as].html_safe, url, html_options)
|
74
73
|
end
|
75
74
|
|
76
75
|
def collection_title(collection = nil, tag = :h1)
|
@@ -113,7 +112,9 @@ module Neuron
|
|
113
112
|
result << if collection.any?
|
114
113
|
collection_list(collection)
|
115
114
|
else
|
116
|
-
content_tag(:p, t(:no_entries,
|
115
|
+
content_tag(:p, t(:no_entries,
|
116
|
+
scope: [:resources, :collection, :no_entries],
|
117
|
+
default: [controller_i18n_scope.to_sym, :all]))
|
117
118
|
end
|
118
119
|
end
|
119
120
|
end
|
@@ -124,9 +125,9 @@ module Neuron
|
|
124
125
|
resource ||= self.resource
|
125
126
|
action = action_name.to_sym
|
126
127
|
''.html_safe.tap do |result|
|
127
|
-
result << title(
|
128
|
-
|
129
|
-
|
128
|
+
result << title(nil,
|
129
|
+
resource: link_to(resource, canonical_path(resource)),
|
130
|
+
default: resource.to_s)
|
130
131
|
if (action == :show) && can?(:update, resource)
|
131
132
|
result << content_tag(:sup,
|
132
133
|
link_to(t(:edit,
|
data/lib/neuron/version.rb
CHANGED