preciousss 0.0.4

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 ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ # IntelliJ #############################################################################################################
7
+ .idea
8
+ /*.ids
9
+
10
+ # Linux ################################################################################################################
11
+ *~
12
+
13
+ # NetBeans #############################################################################################################
14
+ nbproject
15
+
16
+ # Windows ##############################################################################################################
17
+ Thumbs.db
18
+ Desktop.ini
19
+
20
+ # Mac ##################################################################################################################
21
+ .DS_Store
22
+
23
+ # Keep it! (and keep this pattern at the end of .gitignore) ############################################################
24
+ !.gitkeep
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in preciousss.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ Preciousss
2
+ ==========
3
+
4
+ View Helpers
5
+ ------------
6
+
7
+ body_class
8
+ body_id
9
+ errors_for
10
+ flash_messages
11
+ is_bot?
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +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 << '<div class="title">' + options[:title] + '</div>' 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
+ end
@@ -0,0 +1,3 @@
1
+ module Preciousss
2
+ VERSION = '0.0.4'
3
+ end
@@ -0,0 +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
24
+ end
data/lib/preciousss.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Preciousss
2
+
3
+ class Railtie < Rails::Railtie
4
+
5
+ initializer 'preciousss.view_helpers' do |app|
6
+ ActiveSupport.on_load :action_view do
7
+ require 'preciousss/view_helpers/action_view'
8
+
9
+ include Preciousss::ViewHelpers::ActionView
10
+ end
11
+
12
+ ActiveSupport.on_load :action_controller do
13
+ require 'preciousss/controllers/helpers'
14
+
15
+ include Preciousss::Controllers::Helpers
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'preciousss/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'preciousss'
7
+ s.version = Preciousss::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['sodercober']
10
+ s.email = ['sodercober@gmail.com']
11
+ s.homepage = 'https://github.com/sodercober/preciousss'
12
+ s.summary = %q{Several helpers for Ruby on Rails 3}
13
+ s.description = %q{Several helpers for Ruby on Rails 3}
14
+
15
+ s.rubyforge_project = 'preciousss'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: preciousss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease: !!null
6
+ platform: ruby
7
+ authors:
8
+ - sodercober
9
+ autorequire: !!null
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-03-02 00:00:00.000000000 +00:00
13
+ default_executable: !!null
14
+ dependencies: []
15
+ description: Several helpers for Ruby on Rails 3
16
+ email:
17
+ - sodercober@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - lib/preciousss.rb
27
+ - lib/preciousss/controllers/helpers.rb
28
+ - lib/preciousss/version.rb
29
+ - lib/preciousss/view_helpers/action_view.rb
30
+ - preciousss.gemspec
31
+ has_rdoc: true
32
+ homepage: https://github.com/sodercober/preciousss
33
+ licenses: []
34
+ post_install_message: !!null
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project: preciousss
52
+ rubygems_version: 1.5.0
53
+ signing_key: !!null
54
+ specification_version: 3
55
+ summary: Several helpers for Ruby on Rails 3
56
+ test_files: []