active-component 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b98862901db5f269ab90cb2cc2fc8d1736cf36
|
4
|
+
data.tar.gz: ca0037e4db1b85b689b60ac972c59ad94c67a9c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da2ca99d464aeb5e4379634bc6f412b128408164e94a2c75a2f05836b4d2f13fc30cb48c6e2ebd9fc13d7d3ba36594e749398d1d2e8efc3e39eee38050fdb26
|
7
|
+
data.tar.gz: 9551697868ed3d380cee267301f74460334959f4a2125f1a4b7b82e04cdde782795cbe6169181dfc596c51e392e68a442629ed00cd811c10e89f4520a2f5b9de
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#.
|
2
|
+
# This provides a method camelize and constantize
|
3
|
+
#
|
4
|
+
module ActiveComponent
|
5
|
+
module Inflections
|
6
|
+
|
7
|
+
def constantize
|
8
|
+
names = camel_cased_word.split('::')
|
9
|
+
|
10
|
+
# Trigger a builtin NameError exception including the ill-formed constant in the message.
|
11
|
+
Object.const_get(camel_cased_word) if names.empty?
|
12
|
+
|
13
|
+
# Remove the first blank element in case of '::ClassName' notation.
|
14
|
+
names.shift if names.size > 1 && names.first.empty?
|
15
|
+
|
16
|
+
names.inject(Object) do |constant, name|
|
17
|
+
if constant == Object
|
18
|
+
constant.const_get(name)
|
19
|
+
else
|
20
|
+
candidate = constant.const_get(name)
|
21
|
+
next candidate if constant.const_defined?(name, false)
|
22
|
+
next candidate unless Object.const_defined?(name)
|
23
|
+
|
24
|
+
# Go down the ancestors to check it it's owned
|
25
|
+
# directly before we reach Object or the end of ancestors.
|
26
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
27
|
+
break const if ancestor == Object
|
28
|
+
break ancestor if ancestor.const_defined?(name, false)
|
29
|
+
const
|
30
|
+
end
|
31
|
+
|
32
|
+
# owner is in Object, so raise
|
33
|
+
constant.const_get(name, false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def camelize
|
39
|
+
string = term.to_s
|
40
|
+
if uppercase_first_letter
|
41
|
+
string = string.sub(/^[a-z\d]*/) { inflections.acronyms[$&] || $&.capitalize }
|
42
|
+
else
|
43
|
+
string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { $&.downcase }
|
44
|
+
end
|
45
|
+
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
|
46
|
+
string.gsub!('/', '::')
|
47
|
+
string
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
class ActiveComponent::InflectionsTest < Test::Unit::TestCase
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def test_active_component_constantize
|
8
|
+
text = "FooComponent"
|
9
|
+
assert_equal FooComponent, text.constantize
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_active_component_camelize
|
13
|
+
text = 'foo_component'
|
14
|
+
assert_equal 'FooComponent', text.camelize
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_active_component_camelize_constantize
|
18
|
+
text = 'foo_component'
|
19
|
+
assert_equal FooComponent, text.camelize.constantize
|
20
|
+
end
|
21
|
+
end
|
@@ -54,7 +54,7 @@ class ActiveComponent::RenderableTest < ActiveSupport::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
test "it returns a string from the template" do
|
57
|
-
string = @view.send(:
|
57
|
+
string = @view.send(:element, :foo, :bar => "Hello world!")
|
58
58
|
assert_equal "<div>Hello world!</div>", string
|
59
59
|
end
|
60
60
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Chavez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mustache
|
@@ -133,6 +133,7 @@ extra_rdoc_files: []
|
|
133
133
|
files:
|
134
134
|
- lib/active_component/base.rb
|
135
135
|
- lib/active_component/context.rb
|
136
|
+
- lib/active_component/inflections.rb
|
136
137
|
- lib/active_component/railtie.rb
|
137
138
|
- lib/active_component/renderable.rb
|
138
139
|
- lib/active_component/version.rb
|
@@ -145,6 +146,7 @@ files:
|
|
145
146
|
- Rakefile
|
146
147
|
- test/active_component/base_test.rb
|
147
148
|
- test/active_component/context_test.rb
|
149
|
+
- test/active_component/inflections_test.rb
|
148
150
|
- test/active_component/railtie_test.rb
|
149
151
|
- test/active_component/renderable_test.rb
|
150
152
|
- test/active_component_test.rb
|
@@ -182,6 +184,7 @@ summary: A View-Component framework for Rails applications.
|
|
182
184
|
test_files:
|
183
185
|
- test/active_component/base_test.rb
|
184
186
|
- test/active_component/context_test.rb
|
187
|
+
- test/active_component/inflections_test.rb
|
185
188
|
- test/active_component/railtie_test.rb
|
186
189
|
- test/active_component/renderable_test.rb
|
187
190
|
- test/active_component_test.rb
|
@@ -192,4 +195,3 @@ test_files:
|
|
192
195
|
- test/support/foo_controller.rb
|
193
196
|
- test/support/foo_sinatra.rb
|
194
197
|
- test/test_helper.rb
|
195
|
-
has_rdoc:
|