action_widget 0.6.0.pre → 0.6.0
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.
- checksums.yaml +4 -4
- data/action_widget.gemspec +4 -1
- data/lib/action_widget.rb +26 -17
- data/lib/action_widget/configuration.rb +34 -0
- data/lib/action_widget/extensions/rails/generators.rb +61 -32
- data/lib/action_widget/version.rb +3 -0
- data/lib/action_widget/view_helper.rb +6 -9
- data/spec/action_widget_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- data/support/templates/widget.rb.erb +3 -5
- data/support/templates/widget_spec.rb.erb +3 -5
- data/support/templates/widget_test.rb.erb +4 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b55679eb4877455d51a7e8f16038608e91a191e9
|
4
|
+
data.tar.gz: 5078838b75852803999e6f1357a06d4328b3ee55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c2add84e52d6f3259c6da7186f28c0668c834a3628325d569f9010979f8508258a9dabb55215cefc4b21e864d467ccba6d0eac853465c45b1c28c40ee226286
|
7
|
+
data.tar.gz: 8bb1b072a106dea18e5c69691f8efac3b348d80b898abe93dc442457807acf6a8b7b5ff5a3a31be093e625a34e6829960b04e1f5b02f566ec8f734334fa0a7b5
|
data/action_widget.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require_relative 'lib/action_widget/version.rb'
|
3
|
+
|
2
4
|
Gem::Specification.new do |gem|
|
3
5
|
gem.authors = ["Konstantin Tennhard"]
|
4
6
|
gem.email = ["me@t6d.de"]
|
@@ -10,10 +12,11 @@ Gem::Specification.new do |gem|
|
|
10
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
11
13
|
gem.name = "action_widget"
|
12
14
|
gem.require_paths = ["lib"]
|
13
|
-
gem.version =
|
15
|
+
gem.version = ActionWidget::VERSION
|
14
16
|
|
15
17
|
gem.add_dependency 'smart_properties', '~> 1.10'
|
16
18
|
|
19
|
+
gem.add_development_dependency 'pry'
|
17
20
|
gem.add_development_dependency 'rake', '~> 10.0'
|
18
21
|
gem.add_development_dependency 'rspec', '~> 3.3'
|
19
22
|
gem.add_development_dependency 'actionview', '~> 4.0'
|
data/lib/action_widget.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
1
|
require 'smart_properties'
|
2
2
|
|
3
3
|
module ActionWidget
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
attr_reader :pattern
|
10
|
-
|
11
|
-
def initialize(*)
|
12
|
-
super
|
4
|
+
class << self
|
5
|
+
def [](helper_name)
|
6
|
+
registry[helper_name]
|
7
|
+
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
"(.*)",
|
17
|
-
(suffix.underscore if suffix.presence)
|
18
|
-
].compact.join("_"))
|
9
|
+
def []=(helper_name, klass)
|
10
|
+
registry[helper_name] = klass
|
19
11
|
end
|
20
|
-
end
|
21
12
|
|
22
|
-
class << self
|
23
13
|
def configuration
|
24
14
|
@configuration ||= Configuration.new(suffix: "Widget")
|
25
15
|
end
|
@@ -32,14 +22,33 @@ module ActionWidget
|
|
32
22
|
!!configuration.pattern.match(name)
|
33
23
|
end
|
34
24
|
|
35
|
-
|
25
|
+
protected
|
26
|
+
|
27
|
+
def registry
|
28
|
+
@registry ||= Hash.new do |registry, helper_name|
|
29
|
+
if klass = find_action_widget(helper_name)
|
30
|
+
registry[helper_name] = klass
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def find_action_widget(helper_name)
|
40
|
+
return nil unless helper?(helper_name)
|
36
41
|
basename = configuration.pattern.match(helper_name)[1]
|
37
42
|
classname = [configuration.prefix, basename.camelcase, configuration.suffix].join("")
|
38
43
|
classname.constantize
|
44
|
+
rescue NameError, LoadError
|
45
|
+
nil
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
|
43
50
|
require 'action_widget/base'
|
51
|
+
require 'action_widget/configuration'
|
44
52
|
require 'action_widget/view_helper'
|
45
53
|
require 'action_widget/extensions'
|
54
|
+
require 'action_widget/version'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActionWidget
|
2
|
+
class Configuration
|
3
|
+
include SmartProperties
|
4
|
+
property :prefix
|
5
|
+
property :suffix
|
6
|
+
property :superclass, required: true, default: -> { ActionWidget::Base }
|
7
|
+
property :directory, required: true, converts: :to_s, accepts: ->(string) { !string.empty? }, default: -> { [underscored_prefix, underscored_suffix].compact.join("_") }
|
8
|
+
property :minitest_superclass
|
9
|
+
|
10
|
+
attr_reader :pattern
|
11
|
+
|
12
|
+
def initialize(*)
|
13
|
+
super
|
14
|
+
|
15
|
+
@pattern = Regexp.new("^%s$" % [
|
16
|
+
underscored_prefix,
|
17
|
+
"(.*)",
|
18
|
+
underscored_suffix
|
19
|
+
].compact.join("_"))
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def underscored_prefix
|
25
|
+
return if prefix.nil?
|
26
|
+
prefix.underscore
|
27
|
+
end
|
28
|
+
|
29
|
+
def underscored_suffix
|
30
|
+
return if suffix.nil?
|
31
|
+
suffix.underscore
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,57 +2,86 @@ module ActionWidget
|
|
2
2
|
module Extensions
|
3
3
|
module Rails
|
4
4
|
module Generators
|
5
|
-
|
6
5
|
class Base < ::Rails::Generators::Base
|
7
|
-
|
8
6
|
def self.namespace(name=nil)
|
9
|
-
|
7
|
+
name || "action_widget"
|
10
8
|
end
|
11
|
-
|
12
9
|
end
|
13
|
-
|
14
|
-
class
|
10
|
+
|
11
|
+
class ActionWidget < Base
|
15
12
|
source_root File.expand_path('../../../../../support/templates', __FILE__)
|
16
|
-
argument :
|
17
|
-
class_option :
|
13
|
+
argument :name, :type => :string
|
14
|
+
class_option :test, type: :boolean, default: true
|
18
15
|
|
19
16
|
def generate_widget_implementation_file
|
20
|
-
template('widget.rb.erb',
|
17
|
+
template('widget.rb.erb', implementation_path)
|
21
18
|
end
|
22
19
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
20
|
+
def generate_widget_test_file
|
21
|
+
return unless options.test?
|
22
|
+
|
23
|
+
if defined?(::RSpec)
|
24
|
+
template('widget_spec.rb.erb', spec_path)
|
25
|
+
else
|
26
|
+
template('widget_test.rb.erb', test_path)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def configuration
|
33
|
+
::ActionWidget.configuration
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def test_path
|
37
|
+
File.join('test', configuration.directory, test_filename)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
name = name.titleize
|
43
|
-
name = name.gsub(" ", '')
|
44
|
-
name = name.gsub("/", '::')
|
45
|
-
|
46
|
-
name
|
47
|
-
end
|
40
|
+
def test_filename
|
41
|
+
"#{helper_name}_test.rb"
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
def spec_path
|
45
|
+
File.join('spec', configuration.directory, spec_filename)
|
46
|
+
end
|
47
|
+
|
48
|
+
def spec_filename
|
49
|
+
"#{helper_name}_spec.rb"
|
50
|
+
end
|
51
|
+
|
52
|
+
def implementation_path
|
53
|
+
File.join('app', configuration.directory, implementation_filename)
|
54
|
+
end
|
55
|
+
|
56
|
+
def implementation_filename
|
57
|
+
"#{helper_name}.rb"
|
58
|
+
end
|
59
|
+
|
60
|
+
def class_name
|
61
|
+
[configuration.prefix, basename.classify, configuration.suffix].join('')
|
62
|
+
end
|
63
|
+
|
64
|
+
def superclass_name
|
65
|
+
configuration.superclass.to_s
|
66
|
+
end
|
52
67
|
|
68
|
+
def minitest_superclass_name
|
69
|
+
(configuration.minitest_superclass || "ActionView::TestCase").to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
def helper_name
|
73
|
+
class_name.underscore
|
74
|
+
end
|
75
|
+
|
76
|
+
def basename
|
77
|
+
if match = name.underscore.match(configuration.pattern)
|
78
|
+
match[1]
|
79
|
+
else
|
80
|
+
name
|
81
|
+
end
|
82
|
+
end
|
53
83
|
end
|
54
|
-
|
55
84
|
end
|
56
85
|
end
|
57
86
|
end
|
58
|
-
end
|
87
|
+
end
|
@@ -1,24 +1,21 @@
|
|
1
1
|
module ActionWidget
|
2
2
|
module ViewHelper
|
3
|
-
|
4
3
|
def method_missing(name, *args, &block)
|
5
|
-
|
6
|
-
|
7
|
-
klass = begin
|
8
|
-
ActionWidget.class_for(name)
|
9
|
-
rescue NameError, LoadError
|
10
|
-
return super
|
11
|
-
end
|
4
|
+
widget = ActionWidget[name]
|
5
|
+
return super if widget.nil?
|
12
6
|
|
13
7
|
ActionWidget::ViewHelper.module_eval <<-RUBY
|
14
8
|
def #{name}(*args, &block) # def example_widget(*args, &block)
|
15
9
|
attrs = args.last.kind_of?(Hash) ? args.pop : {}
|
16
|
-
#{
|
10
|
+
#{widget}.new(self, attrs).render(*args, &block) # ExampleWidget.new(self, attrs).render(*args, &block)
|
17
11
|
end # end
|
18
12
|
RUBY
|
19
13
|
|
20
14
|
send(name, *args, &block)
|
21
15
|
end
|
22
16
|
|
17
|
+
def respond_to_missing?(name, include_private = false)
|
18
|
+
!!ActionWidget[name] || super
|
19
|
+
end
|
23
20
|
end
|
24
21
|
end
|
data/spec/action_widget_spec.rb
CHANGED
@@ -17,6 +17,13 @@ class ViewContext < ActionView::Base
|
|
17
17
|
include ActionWidget::ViewHelper
|
18
18
|
end
|
19
19
|
|
20
|
+
RSpec.describe ViewContext do
|
21
|
+
subject(:view_context) { described_class.new }
|
22
|
+
it 'should implement #respond_to_missing?' do
|
23
|
+
expect(view_context.send(:respond_to_missing?, :dummy_widget)).to eq(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
20
27
|
RSpec.describe DummyWidget do
|
21
28
|
let(:view) { ViewContext.new }
|
22
29
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "<%=
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
describe "<%= class_name %>", type: :helper do
|
4
|
+
subject(<%= ":%s" % helper_name %>) { helper.<%= helper_name %> }
|
5
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_widget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.0
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Tennhard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_properties
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,16 +96,19 @@ files:
|
|
82
96
|
- action_widget.gemspec
|
83
97
|
- lib/action_widget.rb
|
84
98
|
- lib/action_widget/base.rb
|
99
|
+
- lib/action_widget/configuration.rb
|
85
100
|
- lib/action_widget/extensions.rb
|
86
101
|
- lib/action_widget/extensions/middleman.rb
|
87
102
|
- lib/action_widget/extensions/rails.rb
|
88
103
|
- lib/action_widget/extensions/rails/generators.rb
|
89
104
|
- lib/action_widget/extensions/rails/railtie.rb
|
105
|
+
- lib/action_widget/version.rb
|
90
106
|
- lib/action_widget/view_helper.rb
|
91
107
|
- spec/action_widget_spec.rb
|
92
108
|
- spec/spec_helper.rb
|
93
109
|
- support/templates/widget.rb.erb
|
94
110
|
- support/templates/widget_spec.rb.erb
|
111
|
+
- support/templates/widget_test.rb.erb
|
95
112
|
homepage: http://github.com/t6d/action_widget
|
96
113
|
licenses: []
|
97
114
|
metadata: {}
|
@@ -106,9 +123,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
123
|
version: '0'
|
107
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
125
|
requirements:
|
109
|
-
- - "
|
126
|
+
- - ">="
|
110
127
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
128
|
+
version: '0'
|
112
129
|
requirements: []
|
113
130
|
rubyforge_project:
|
114
131
|
rubygems_version: 2.4.5
|