e9_rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.md +4 -0
- data/Rakefile +2 -0
- data/e9_rails.gemspec +24 -0
- data/lib/e9_rails/helpers/resource_error_messages.rb +39 -0
- data/lib/e9_rails/helpers/translation.rb +64 -0
- data/lib/e9_rails/version.rb +3 -0
- data/lib/e9_rails.rb +10 -0
- metadata +100 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/e9_rails.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "e9_rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "e9_rails"
|
7
|
+
s.version = E9Rails::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Travis Cox"]
|
10
|
+
s.email = ["travis@e9digital.com"]
|
11
|
+
s.homepage = "http://www.e9digital.com"
|
12
|
+
s.summary = %q{A collection of helpers and extensions used in e9 Rails 3 projects}
|
13
|
+
s.description = %q{}
|
14
|
+
|
15
|
+
s.rubyforge_project = "e9_rails"
|
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
|
+
|
22
|
+
s.add_dependency "rails", "~> 3.0.0"
|
23
|
+
s.add_dependency "inherited_resources"
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module E9Rails::Helpers
|
2
|
+
#
|
3
|
+
# Simple helper to compile errors on a record in mostly-typical Rails
|
4
|
+
# style, with the assumption that the current record is available as
|
5
|
+
# <tt>resource</tt>.
|
6
|
+
#
|
7
|
+
module ResourceErrorMessages
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
send :helper, HelperMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module HelperMethods
|
15
|
+
#
|
16
|
+
# Assumes the definition of <tt>resource</tt>.
|
17
|
+
# Also accepts it as an option passed to the method.
|
18
|
+
#
|
19
|
+
def resource_error_messages!(options = {})
|
20
|
+
object = options[:resource] || resource
|
21
|
+
|
22
|
+
if object.errors.empty? || ( (errors_on = options.delete(:on)) && (errors_on & object.errors.keys).empty? )
|
23
|
+
return ''
|
24
|
+
end
|
25
|
+
|
26
|
+
messages = object.errors.map {|attribute, msg| content_tag(:li, msg) }.join
|
27
|
+
html = <<-HTML
|
28
|
+
<div id="errorExplanation">
|
29
|
+
<ul>#{messages}</ul>
|
30
|
+
</div>
|
31
|
+
HTML
|
32
|
+
|
33
|
+
html.html_safe
|
34
|
+
rescue => e
|
35
|
+
''
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module E9::Helpers
|
2
|
+
module Translation
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
extend InstanceMethods
|
7
|
+
helper_method :e9_t, :e9_translate
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def e9_translate(lookup_key, opts = {})
|
12
|
+
# TODO is there a nicer way to say this?
|
13
|
+
defaults = []
|
14
|
+
|
15
|
+
lookup_key = lookup_key.to_s
|
16
|
+
|
17
|
+
# if a scoped key is passed assume it's fully scoped (after e9)
|
18
|
+
if lookup_key.include?(".")
|
19
|
+
defaults << lookup_key
|
20
|
+
# reset the key for base lookup
|
21
|
+
lookup_key = lookup_key.split('.').last
|
22
|
+
|
23
|
+
# elsif scope is passed, delete it and use the path as the first default
|
24
|
+
elsif scope = opts.delete(:scope)
|
25
|
+
# this lets you pass scope as an empty string
|
26
|
+
scope = nil if scope.blank?
|
27
|
+
defaults << (Array.wrap(scope) << lookup_key).compact.join('.')
|
28
|
+
|
29
|
+
# the difference between default and scope is that default expects a key,
|
30
|
+
# ignoring the lookup key
|
31
|
+
elsif default = opts.delete(:default)
|
32
|
+
defaults << default
|
33
|
+
end
|
34
|
+
|
35
|
+
# append default lookup of controller path, e.g. "e9.admin.foos.lookup_key"
|
36
|
+
defaults << [controller_path.gsub(/\//, '.'), lookup_key].join('.')
|
37
|
+
|
38
|
+
# and after that, base lookup for the key
|
39
|
+
defaults << lookup_key
|
40
|
+
|
41
|
+
# sym them and clean up possible accidental double dots
|
42
|
+
defaults.map! {|default| [:e9, default].join('.').gsub(/\.+/, '.').to_sym }
|
43
|
+
defaults.uniq!
|
44
|
+
|
45
|
+
lookup_key = defaults.shift
|
46
|
+
|
47
|
+
begin
|
48
|
+
model_name = (opts.delete(:resource_class) || resource_class).model_name
|
49
|
+
opts.reverse_merge!(
|
50
|
+
:model => model_name.human,
|
51
|
+
:models => model_name.human.pluralize,
|
52
|
+
:collection => model_name.collection,
|
53
|
+
:element => model_name.element
|
54
|
+
)
|
55
|
+
rescue
|
56
|
+
end
|
57
|
+
|
58
|
+
::I18n.translate(lookup_key, opts.merge(:default => defaults))
|
59
|
+
end
|
60
|
+
|
61
|
+
alias :e9_t :e9_translate
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/e9_rails.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: e9_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Travis Cox
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-10 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: inherited_resources
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: ""
|
49
|
+
email:
|
50
|
+
- travis@e9digital.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- e9_rails.gemspec
|
63
|
+
- lib/e9_rails.rb
|
64
|
+
- lib/e9_rails/helpers/resource_error_messages.rb
|
65
|
+
- lib/e9_rails/helpers/translation.rb
|
66
|
+
- lib/e9_rails/version.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://www.e9digital.com
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project: e9_rails
|
95
|
+
rubygems_version: 1.3.7
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: A collection of helpers and extensions used in e9 Rails 3 projects
|
99
|
+
test_files: []
|
100
|
+
|