useful_helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in useful_helpers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ useful_helpers
2
+ ==============
3
+
4
+ Useful helpers methods for Good Rails App
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ en:
2
+ useful_helpers:
3
+ breadcrumbs:
4
+ root: Home page
5
+ dashboard: Dashboard
6
+ admin: Admin
7
+ page: Page
8
+ regional_suffix: in Tomsk
9
+ city_abbr: ""
@@ -0,0 +1,9 @@
1
+ ru:
2
+ useful_helpers:
3
+ breadcrumbs:
4
+ root: Главная
5
+ dashboard: Мой кабинет
6
+ admin: Админка
7
+ page: Страница
8
+ regional_suffix: в Томске
9
+ city_abbr: "г."
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ # require "useful_helpers/helpers"
3
+
4
+ require "useful_helpers/helpers/browser_helper"
5
+ require "useful_helpers/helpers/date_time_helper"
6
+ require "useful_helpers/helpers/formtastic_helper"
7
+ require "useful_helpers/helpers/paginate_helper"
8
+ require "useful_helpers/helpers/seo_helper"
9
+ require "useful_helpers/helpers/url_helper"
10
+
11
+ module UsefulHelpers
12
+ class Engine < ::Rails::Engine
13
+ isolate_namespace UsefulHelpers
14
+ engine_name "useful_helpers"
15
+
16
+ initializer "useful_helpers.includers" do |app|
17
+ ActionView::Base.send :include, UsefulHelpers::Helpers::BrowserHelper
18
+ ActionView::Base.send :include, UsefulHelpers::Helpers::DateTimeHelper
19
+ ActionView::Base.send :include, UsefulHelpers::Helpers::FormtasticHelper
20
+ ActionView::Base.send :include, UsefulHelpers::Helpers::PaginateHelper
21
+ ActionView::Base.send :include, UsefulHelpers::Helpers::SeoHelper
22
+ ActionView::Base.send :include, UsefulHelpers::Helpers::UrlHelper
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ module UsefulHelpers
3
+ module Helpers
4
+ module BrowserHelper
5
+ def normal_browser?
6
+ !(request.env['HTTP_USER_AGENT'] =~ /MSIE (6|5|4|3|2)/)
7
+ end
8
+
9
+ def ie_browser?
10
+ request.env['HTTP_USER_AGENT'] =~ /MSIE/
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+ module UsefulHelpers
3
+ module Helpers
4
+ module DateTimeHelper
5
+ def localize_date(date, format=:long)
6
+ I18n.localize(date, :format => format)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ module UsefulHelpers
3
+ module Helpers
4
+ module FormtasticHelper
5
+ def formtastic_cancel_button(object, redirect_path=nil)
6
+ path =
7
+ if redirect_path
8
+ redirect_path
9
+ else
10
+ if object.new_record?
11
+ collection_path
12
+ else
13
+ resource_path(object)
14
+ end
15
+ end
16
+ content_tag :li,
17
+ link_to(
18
+ t("web-app-theme.cancel"),
19
+ path,
20
+ :class => "cancel"
21
+ ),
22
+ :class => "commit_button"
23
+ end
24
+
25
+ def actions_for(form, label=nil)
26
+ print_label = label ? label : nil
27
+ html = ""
28
+ html += form.actions do
29
+ submit_for(form, print_label) + cancel_for(form)
30
+ end
31
+ raw html
32
+ end
33
+
34
+ def submit_for(form, label=nil)
35
+ print_label = label ? label : "Отправить"
36
+ form.action :submit,
37
+ :as => :button,
38
+ :label => raw("<span class='b-btn__wrap g-dib'>#{print_label}</span>"),
39
+ :button_html => {:class => "b-btn _blue g-dib"}
40
+ end
41
+
42
+ def cancel_for(form, label=nil)
43
+ print_label = label ? label : "Отмена"
44
+ form.action :cancel,
45
+ :as => :link,
46
+ :label => print_label,
47
+ :button_html => {:class => "a_button cancelite"}
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ module UsefulHelpers
3
+ module Helpers
4
+ module PaginateHelper
5
+ def paginate(collection)
6
+ html = will_paginate(collection).gsub('/page-1"', '/"').gsub('_/', '') rescue nil
7
+ if html && request.fullpath.include?("page-")
8
+ html = html.gsub("page-#{params[:page]}/", "")
9
+ end
10
+ raw html
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+ module UsefulHelpers
3
+ module Helpers
4
+ module SeoHelper
5
+ def delimiter
6
+ raw '&#32;&#8594;&#32;'
7
+ end
8
+
9
+ def page_title(page_title)
10
+ content_for(:page_title) { raw("<h1>#{page_title}</h1>") }
11
+ end
12
+
13
+ def canonical(url)
14
+ content_for :head do
15
+ raw "<link rel=\"canonical\" href=\"#{url}\" />"
16
+ end
17
+ end
18
+
19
+ def noindex
20
+ content_for :head do
21
+ noindex_tag
22
+ end
23
+ end
24
+
25
+ def noindex_tag
26
+ raw '<meta name="robots" content="noindex, nofollow" />'
27
+ end
28
+
29
+ def breadcrumbs(prefix, links)
30
+ case prefix
31
+ when "root"
32
+ anchor = I18n.t("useful_helpers.breadcrumbs.root")
33
+ path = "/"
34
+ when "dashboard"
35
+ anchor = I18n.t("useful_helpers.breadcrumbs.dashboard")
36
+ path = "/dashboard"
37
+ when "admin"
38
+ anchor = I18n.t("useful_helpers.breadcrumbs.admin")
39
+ path = "/admin"
40
+ else
41
+ anchor, path = nil, nil
42
+ end
43
+ return "" if path.nil?
44
+ first_link = ["<a title=\"#{anchor}\" href=\"#{path}\">#{anchor}</a>"]
45
+ content_for :breadcrumbs do
46
+ raw "<div class=\"breadcrumbs\">#{(first_link+links).flatten.join(delimiter)}</div>"
47
+ end
48
+ end
49
+
50
+ def build_meta_title
51
+ html = @meta_title
52
+ city_abbr = I18n.t("useful_helpers.city_abbr")
53
+ regional_suffix = I18n.t("useful_helpers.regional_suffix")
54
+ unless ca('welcome', 'index')
55
+ if html.include?(regional_suffix)
56
+ html << " — #{@site_name}"
57
+ elsif @city.present?
58
+ html << " — #{@site_name}, #{city_abbr} #{@city.ru}"
59
+ else
60
+ html << " — #{@full_site_name}"
61
+ end
62
+ end
63
+ html << " | #{I18n.t('useful_helpers.page')} #{@page_counter}" if @page_counter && @page_counter != 1
64
+ html
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ module UsefulHelpers
3
+ module Helpers
4
+ module UrlHelper
5
+ def rc(prefix)
6
+ request.request_uri.to_s.include?(prefix)
7
+ end
8
+
9
+ def cn(controller)
10
+ params[:controller] == controller
11
+ end
12
+
13
+ def an(action)
14
+ action_name == action
15
+ end
16
+
17
+ def ca(controller, action)
18
+ params[:controller] == controller && action_name == action
19
+ end
20
+
21
+ ["index", "show", "new", "edit"].each do |action|
22
+ define_method action do
23
+ action_name == action
24
+ end
25
+ end
26
+
27
+ # def skype_to(login)
28
+ # raw "<a href=\"skype:#{login}?call\">#{login}</a>"
29
+ # end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ require "useful_helpers/helpers/browser_helper"
3
+ require "useful_helpers/helpers/date_time_helper"
4
+ require "useful_helpers/helpers/formtastic_helper"
5
+ require "useful_helpers/helpers/paginate_helper"
6
+ require "useful_helpers/helpers/seo_helper"
7
+ require "useful_helpers/helpers/url_helper"
@@ -0,0 +1,3 @@
1
+ module UsefulHelpers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ # coding: utf-8
2
+ require "useful_helpers/engine"
3
+ require "useful_helpers/version"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'useful_helpers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "useful_helpers"
8
+ spec.version = UsefulHelpers::VERSION
9
+ spec.authors = ["Andrey"]
10
+ spec.email = ["railscode@gmail.com"]
11
+ spec.description = "Useful helpers methods for Good Rails App"
12
+ spec.summary = "Useful helpers methods for Good Rails App"
13
+ spec.homepage = "https://github.com/vav/useful_helpers"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "rails", ">= 3.2.12"
25
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: useful_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.12
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.12
62
+ description: Useful helpers methods for Good Rails App
63
+ email:
64
+ - railscode@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - config/locales/useful_helpers.en.yml
75
+ - config/locales/useful_helpers.ru.yml
76
+ - lib/useful_helpers.rb
77
+ - lib/useful_helpers/engine.rb
78
+ - lib/useful_helpers/helpers.rb
79
+ - lib/useful_helpers/helpers/browser_helper.rb
80
+ - lib/useful_helpers/helpers/date_time_helper.rb
81
+ - lib/useful_helpers/helpers/formtastic_helper.rb
82
+ - lib/useful_helpers/helpers/paginate_helper.rb
83
+ - lib/useful_helpers/helpers/seo_helper.rb
84
+ - lib/useful_helpers/helpers/url_helper.rb
85
+ - lib/useful_helpers/version.rb
86
+ - useful_helpers.gemspec
87
+ homepage: https://github.com/vav/useful_helpers
88
+ licenses:
89
+ - MIT
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.23
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Useful helpers methods for Good Rails App
112
+ test_files: []