preciousss 0.0.4 → 0.0.5
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/lib/preciousss/controllers/helpers.rb +60 -60
- data/lib/preciousss/version.rb +1 -1
- data/lib/preciousss/view_helpers/action_view.rb +23 -23
- metadata +44 -24
@@ -1,61 +1,61 @@
|
|
1
|
-
module Preciousss
|
2
|
-
module Controllers
|
3
|
-
module Helpers
|
4
|
-
BOTS_REGEXP = /Googlebot|facebookexternalhit/i.freeze
|
5
|
-
|
6
|
-
def self.included(base) # :nodoc:
|
7
|
-
base.extend ClassMethods
|
8
|
-
base.send :include, InstanceMethods
|
9
|
-
base.class_eval do
|
10
|
-
helper_method :errors_for, :is_bot?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module ClassMethods
|
15
|
-
end
|
16
|
-
|
17
|
-
module InstanceMethods
|
18
|
-
|
19
|
-
def is_bot?
|
20
|
-
@is_bot ||= request.user_agent.to_s =~ BOTS_REGEXP
|
21
|
-
end
|
22
|
-
|
23
|
-
def errors_for(*params)
|
24
|
-
options = params.extract_options!.symbolize_keys
|
25
|
-
options[:on] = [*options[:on]].compact
|
26
|
-
options[:except_on] = [*options[:except_on]].compact
|
27
|
-
objects = [*params].flatten
|
28
|
-
object_errors = []
|
29
|
-
|
30
|
-
objects.each do |object|
|
31
|
-
errors = nil
|
32
|
-
object = instance_variable_get("@#{object}") if object.is_a?(Symbol)
|
33
|
-
object.errors.each do |attr, msg|
|
34
|
-
(errors ||= ActiveModel::Errors.new(object)).add(attr, msg) if (options[:on].blank? || options[:on].include?(attr.to_sym)) && (options[:except_on].blank? || !options[:except_on].include?(attr.to_sym))
|
35
|
-
end
|
36
|
-
object_errors << errors if errors
|
37
|
-
end
|
38
|
-
|
39
|
-
unless object_errors.empty?
|
40
|
-
options[:class] ||= 'errors'
|
41
|
-
options[:id] ||= objects.map{|object| object.class.name.underscore}.join('-') + '-errors'
|
42
|
-
options[:title] = I18n.t('activerecord.errors.template.header', :model => objects.map{|object| object.class.human}.to_sentence, :count => object_errors.size) if options[:title] === true
|
43
|
-
|
44
|
-
I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
|
45
|
-
messages = object_errors.sum{|errors| errors.full_messages.map{|msg| '<li>' + ERB::Util.html_escape(msg) + '</li>'}}.join.html_safe
|
46
|
-
contents = ''
|
47
|
-
contents << '<
|
48
|
-
contents << '<ul class="messages">' + messages + '</ul>'
|
49
|
-
|
50
|
-
"<div id=\"#{options[:id]}\" class=\"#{options[:class]}\">#{contents}</div>".html_safe
|
51
|
-
end
|
52
|
-
else
|
53
|
-
''
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
1
|
+
module Preciousss
|
2
|
+
module Controllers
|
3
|
+
module Helpers
|
4
|
+
BOTS_REGEXP = /Googlebot|facebookexternalhit/i.freeze
|
5
|
+
|
6
|
+
def self.included(base) # :nodoc:
|
7
|
+
base.extend ClassMethods
|
8
|
+
base.send :include, InstanceMethods
|
9
|
+
base.class_eval do
|
10
|
+
helper_method :errors_for, :is_bot?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
|
19
|
+
def is_bot?
|
20
|
+
@is_bot ||= request.user_agent.to_s =~ BOTS_REGEXP
|
21
|
+
end
|
22
|
+
|
23
|
+
def errors_for(*params)
|
24
|
+
options = params.extract_options!.symbolize_keys
|
25
|
+
options[:on] = [*options[:on]].compact
|
26
|
+
options[:except_on] = [*options[:except_on]].compact
|
27
|
+
objects = [*params].flatten
|
28
|
+
object_errors = []
|
29
|
+
|
30
|
+
objects.each do |object|
|
31
|
+
errors = nil
|
32
|
+
object = instance_variable_get("@#{object}") if object.is_a?(Symbol)
|
33
|
+
object.errors.each do |attr, msg|
|
34
|
+
(errors ||= ActiveModel::Errors.new(object)).add(attr, msg) if (options[:on].blank? || options[:on].include?(attr.to_sym)) && (options[:except_on].blank? || !options[:except_on].include?(attr.to_sym))
|
35
|
+
end
|
36
|
+
object_errors << errors if errors
|
37
|
+
end
|
38
|
+
|
39
|
+
unless object_errors.empty?
|
40
|
+
options[:class] ||= 'errors'
|
41
|
+
options[:id] ||= objects.map{|object| object.class.name.underscore}.join('-') + '-errors'
|
42
|
+
options[:title] = I18n.t('activerecord.errors.template.header', :model => objects.map{|object| object.class.human}.to_sentence, :count => object_errors.size) if options[:title] === true
|
43
|
+
|
44
|
+
I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
|
45
|
+
messages = object_errors.sum{|errors| errors.full_messages.map{|msg| '<li>' + ERB::Util.html_escape(msg) + '</li>'}}.join.html_safe
|
46
|
+
contents = ''
|
47
|
+
contents << '<p class="title">' + options[:title] + '</p>' unless options[:title].blank?
|
48
|
+
contents << '<ul class="messages">' + messages + '</ul>'
|
49
|
+
|
50
|
+
"<div id=\"#{options[:id]}\" class=\"#{options[:class]}\">#{contents}</div>".html_safe
|
51
|
+
end
|
52
|
+
else
|
53
|
+
''
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
61
|
end
|
data/lib/preciousss/version.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
module Preciousss
|
2
|
-
module ViewHelpers
|
3
|
-
module ActionView
|
4
|
-
|
5
|
-
def body_class
|
6
|
-
qualified_controller_name = controller.controller_path.gsub('/', '-')
|
7
|
-
"#{qualified_controller_name} #{controller.action_name} #{qualified_controller_name}-#{controller.action_name} #{I18n.locale}"
|
8
|
-
end
|
9
|
-
|
10
|
-
def body_id
|
11
|
-
"#{controller.controller_path.gsub('/', '-')}-body"
|
12
|
-
end
|
13
|
-
|
14
|
-
def flash_messages
|
15
|
-
return if flash.blank?
|
16
|
-
|
17
|
-
content_tag(:div, :class => "flash-messages #{flash.keys.map{|key| "with-#{key}"}.join(' ')}") do
|
18
|
-
flash.map{|key, value| content_tag(:p, value, :class => "flash-#{key}")}.join.html_safe
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module Preciousss
|
2
|
+
module ViewHelpers
|
3
|
+
module ActionView
|
4
|
+
|
5
|
+
def body_class
|
6
|
+
qualified_controller_name = controller.controller_path.gsub('/', '-')
|
7
|
+
"#{qualified_controller_name} #{controller.action_name} #{qualified_controller_name}-#{controller.action_name} #{I18n.locale}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def body_id
|
11
|
+
"#{controller.controller_path.gsub('/', '-')}-body"
|
12
|
+
end
|
13
|
+
|
14
|
+
def flash_messages
|
15
|
+
return if flash.blank?
|
16
|
+
|
17
|
+
content_tag(:div, :class => "flash-messages #{flash.keys.map{|key| "with-#{key}"}.join(' ')}") do
|
18
|
+
flash.map{|key, value| content_tag(:p, content_tag(:span, value), :class => "flash-#{key}")}.join.html_safe
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,24 +1,34 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: preciousss
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- sodercober
|
9
|
-
autorequire:
|
14
|
+
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
date: 2011-03-04 00:00:00 +00:00
|
19
|
+
default_executable:
|
14
20
|
dependencies: []
|
21
|
+
|
15
22
|
description: Several helpers for Ruby on Rails 3
|
16
|
-
email:
|
23
|
+
email:
|
17
24
|
- sodercober@gmail.com
|
18
25
|
executables: []
|
26
|
+
|
19
27
|
extensions: []
|
28
|
+
|
20
29
|
extra_rdoc_files: []
|
21
|
-
|
30
|
+
|
31
|
+
files:
|
22
32
|
- .gitignore
|
23
33
|
- Gemfile
|
24
34
|
- README.md
|
@@ -31,26 +41,36 @@ files:
|
|
31
41
|
has_rdoc: true
|
32
42
|
homepage: https://github.com/sodercober/preciousss
|
33
43
|
licenses: []
|
34
|
-
|
44
|
+
|
45
|
+
post_install_message:
|
35
46
|
rdoc_options: []
|
36
|
-
|
47
|
+
|
48
|
+
require_paths:
|
37
49
|
- lib
|
38
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
51
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
60
|
none: false
|
46
|
-
requirements:
|
47
|
-
- -
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
50
68
|
requirements: []
|
69
|
+
|
51
70
|
rubyforge_project: preciousss
|
52
|
-
rubygems_version: 1.
|
53
|
-
signing_key:
|
71
|
+
rubygems_version: 1.6.1
|
72
|
+
signing_key:
|
54
73
|
specification_version: 3
|
55
74
|
summary: Several helpers for Ruby on Rails 3
|
56
75
|
test_files: []
|
76
|
+
|