action_widget 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/action_widget.gemspec +1 -1
- data/lib/action_widget.rb +3 -59
- data/lib/action_widget/base.rb +30 -0
- data/lib/action_widget/extensions.rb +2 -0
- data/lib/action_widget/extensions/middleman.rb +22 -0
- data/lib/action_widget/extensions/rails.rb +2 -0
- data/lib/action_widget/extensions/rails/generators.rb +46 -0
- data/lib/action_widget/extensions/rails/railtie.rb +15 -0
- data/lib/action_widget/view_helper.rb +20 -0
- data/support/templates/widget.rb.erb +7 -0
- data/support/templates/widget_spec.rb.erb +7 -0
- metadata +11 -2
data/action_widget.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
11
11
|
gem.name = "action_widget"
|
12
12
|
gem.require_paths = ["lib"]
|
13
|
-
gem.version = "0.
|
13
|
+
gem.version = "0.2.0"
|
14
14
|
|
15
15
|
gem.add_dependency 'smart_properties', '~> 1.0'
|
16
16
|
end
|
data/lib/action_widget.rb
CHANGED
@@ -1,59 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class Base
|
6
|
-
|
7
|
-
include SmartProperties
|
8
|
-
|
9
|
-
def render_in_context(view_context, &block)
|
10
|
-
@view = view_context
|
11
|
-
render(&block)
|
12
|
-
end
|
13
|
-
|
14
|
-
def render
|
15
|
-
raise NotImplementedError, "#{self.class} must implement #render"
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
attr_reader :view
|
21
|
-
|
22
|
-
undef :capture
|
23
|
-
|
24
|
-
def method_missing(method, *args, &block)
|
25
|
-
view.send(method, *args, &block)
|
26
|
-
rescue NoMethodError
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
module Helper
|
33
|
-
|
34
|
-
def method_missing(name, *args, &block)
|
35
|
-
super unless name =~ /_widget$/
|
36
|
-
|
37
|
-
klass = begin
|
38
|
-
@_action_widget_class_cache ||= {}
|
39
|
-
@_action_widget_class_cache[name] ||= "#{name.to_s.camelcase}".constantize
|
40
|
-
rescue NameError => e
|
41
|
-
super
|
42
|
-
rescue LoadError => e
|
43
|
-
super
|
44
|
-
end
|
45
|
-
|
46
|
-
klass.new(*args).render_in_context(self, &block)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
class Railtie < ::Rails::Railtie
|
52
|
-
|
53
|
-
initializer "action_widget.helper" do
|
54
|
-
ActionView::Base.send(:include, Helper)
|
55
|
-
end
|
56
|
-
|
57
|
-
end if defined?(Rails::Railtie)
|
58
|
-
|
59
|
-
end
|
1
|
+
require 'action_widget/base'
|
2
|
+
require 'action_widget/view_helper'
|
3
|
+
require 'action_widget/extensions'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'smart_properties'
|
2
|
+
|
3
|
+
module ActionWidget
|
4
|
+
class Base
|
5
|
+
|
6
|
+
include SmartProperties
|
7
|
+
|
8
|
+
def render_in_context(view_context, &block)
|
9
|
+
@view = view_context
|
10
|
+
render(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
raise NotImplementedError, "#{self.class} must implement #render"
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
attr_reader :view
|
20
|
+
|
21
|
+
undef :capture if method_defined?(:capture)
|
22
|
+
|
23
|
+
def method_missing(method, *args, &block)
|
24
|
+
view.send(method, *args, &block)
|
25
|
+
rescue NoMethodError
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActionWidget
|
2
|
+
module Extensions
|
3
|
+
module Middleman
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def register!
|
8
|
+
::Middleman::Extensions.register(:action_widget, self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def registered(app)
|
12
|
+
app.send(:include, ::ActionWidget::ViewHelper)
|
13
|
+
end
|
14
|
+
alias included registered
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActionWidget::Extensions::Middleman.register!
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActionWidget
|
2
|
+
module Extensions
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class Create < ::Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../../support/templates', __FILE__)
|
8
|
+
argument :widget_name, :type => :string
|
9
|
+
class_option :rspec, :type => :boolean, :default => true, :description => "Generates rspec file"
|
10
|
+
|
11
|
+
def generate_widget_implementation_file
|
12
|
+
empty_directory 'app/widgets'
|
13
|
+
template('widget.rb.erb', "app/widgets/#{widget_implementation_filename}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_widget_spec_file
|
17
|
+
if defined?(::RSpec) && options.rspec?
|
18
|
+
empty_directory 'spec/widgets'
|
19
|
+
template('widget_spec.rb.erb', "spec/widgets/#{widget_spec_filename}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def widget_spec_filename
|
26
|
+
"#{widget_helper_name}_spec.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def widget_implementation_filename
|
30
|
+
"#{widget_helper_name}.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
def widget_class_name
|
34
|
+
/[Ww]idget$/.match(widget_name) ? widget_name.classify : "#{widget_name.classify}Widget"
|
35
|
+
end
|
36
|
+
|
37
|
+
def widget_helper_name
|
38
|
+
widget_class_name.underscore
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActionWidget
|
2
|
+
module ViewHelper
|
3
|
+
|
4
|
+
def method_missing(name, *args, &block)
|
5
|
+
super unless name =~ /_widget$/
|
6
|
+
|
7
|
+
klass = begin
|
8
|
+
@_action_widget_class_cache = {}
|
9
|
+
@_action_widget_class_cache[name] = "#{name.to_s.camelcase}".constantize
|
10
|
+
rescue NameError => e
|
11
|
+
super
|
12
|
+
rescue LoadError => e
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
klass.new(*args).render_in_context(self, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_widget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: smart_properties
|
@@ -41,6 +41,15 @@ files:
|
|
41
41
|
- Rakefile
|
42
42
|
- action_widget.gemspec
|
43
43
|
- lib/action_widget.rb
|
44
|
+
- lib/action_widget/base.rb
|
45
|
+
- lib/action_widget/extensions.rb
|
46
|
+
- lib/action_widget/extensions/middleman.rb
|
47
|
+
- lib/action_widget/extensions/rails.rb
|
48
|
+
- lib/action_widget/extensions/rails/generators.rb
|
49
|
+
- lib/action_widget/extensions/rails/railtie.rb
|
50
|
+
- lib/action_widget/view_helper.rb
|
51
|
+
- support/templates/widget.rb.erb
|
52
|
+
- support/templates/widget_spec.rb.erb
|
44
53
|
homepage: http://github.com/t6d/action_widget
|
45
54
|
licenses: []
|
46
55
|
post_install_message:
|