rails_view_component 0.0.1 → 0.0.2
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/lib/generators/rails_view_component/rails_view_component_generator.rb +32 -19
- data/{haxe_compile.hxml → lib/generators/rails_view_component/templates/haxe_compile.hxml} +0 -0
- data/lib/generators/rails_view_component/templates/view_component/haxe/ViewComponent.hx +26 -0
- data/lib/generators/rails_view_component/templates/view_component/view_component_builder.rb +31 -0
- data/lib/generators/rails_view_component/templates/view_component/view_component_helper.rb +14 -0
- data/lib/generators/rails_view_component/templates/view_component/view_component_model.rb +30 -0
- data/lib/rails_view_component/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 809d813dc621a89b1e749b28f5715666f03c421d
|
4
|
+
data.tar.gz: 1e4a24a3c781c60ddfdbb2982208fa7560967ec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e99531e3bcba4e2794965ebb201c089b1aa391c602d4900915e283f797725be7a8b58d16b4e04269378cc513d6113c1a212a5204b0147f16b01d9f279501307e
|
7
|
+
data.tar.gz: 28a7a07dd203128bf9e48340d3399a7ad916f43e2b1ee5c6a562be4374ed48698bf0b2d280bf2dce036c78ae7c4f5c0d396e25ce2ef8447d649fa8771e12d427
|
@@ -4,27 +4,40 @@ class RailsViewComponentGenerator < Rails::Generators::NamedBase
|
|
4
4
|
desc "This generator creates RailsViewComponent files."
|
5
5
|
|
6
6
|
def create_rails_view_component_file
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
gname, cmd = name.split(":")
|
8
|
+
if cmd == "install"
|
9
|
+
%w( view_component/view_component_builder.rb
|
10
|
+
view_component/view_component_helper.rb
|
11
|
+
view_component/view_component_model.rb
|
12
|
+
view_component/haxe/ViewComponent.hx
|
13
|
+
).each{|file|
|
14
|
+
copy_file file, "lib/#{file}"
|
15
|
+
}
|
16
|
+
copy_file "haxe_compile.hxml", "hax_compile.hxml"
|
17
|
+
|
18
|
+
else
|
19
|
+
copy_and_compile = ->(from, to){
|
20
|
+
root = File.expand_path("../", __FILE__)
|
21
|
+
erb = ERB.new(open("#{root}/erb/#{from}").read)
|
22
|
+
@class_name = class_name
|
23
|
+
@file_name = file_name
|
24
|
+
@args = args
|
25
|
+
create_file "app/rails_view_components/#{file_name}/#{to}",
|
26
|
+
erb.result(binding)
|
27
|
+
}
|
15
28
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
copy_and_compile.call("controller.rb.erb", "#{file_name}_controller.rb")
|
30
|
+
copy_and_compile.call("model.rb.erb", "#{file_name}_model.rb")
|
31
|
+
copy_and_compile.call("routes.rb.erb", "routes.rb")
|
32
|
+
copy_and_compile.call("views/rails_view_component.html.erb.erb",
|
33
|
+
"views/#{file_name}_view_component.html.erb")
|
34
|
+
copy_and_compile.call("haxe/RailsViewComponent.hx.erb",
|
35
|
+
"haxe/#{class_name}ViewComponent.hx")
|
23
36
|
|
24
|
-
|
37
|
+
route "#{class_name}::Routes.routings"
|
25
38
|
|
26
|
-
|
27
|
-
|
39
|
+
inject_into_file "haxe_compile.hxml",
|
40
|
+
after: "## RailsViewComponent JavaScripts\n" do <<RUBY
|
28
41
|
--next
|
29
42
|
# #{@class_name}
|
30
43
|
-lib JQueryExtern
|
@@ -34,7 +47,7 @@ class RailsViewComponentGenerator < Rails::Generators::NamedBase
|
|
34
47
|
-js public/javascripts/#{@file_name}_view_component.js
|
35
48
|
|
36
49
|
RUBY
|
50
|
+
end
|
37
51
|
end
|
38
|
-
|
39
52
|
end
|
40
53
|
end
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import jQuery.*;
|
2
|
+
|
3
|
+
class ViewComponent{
|
4
|
+
public var callbacks = new Map<String, Dynamic->Dynamic->Dynamic->Void>();
|
5
|
+
public function addCallback(method:String, fun:Dynamic->Dynamic->Dynamic->Void){
|
6
|
+
this.callbacks.set(method, fun);
|
7
|
+
}
|
8
|
+
private var componentName : String;
|
9
|
+
public function new(name:String){
|
10
|
+
this.componentName = name;
|
11
|
+
}
|
12
|
+
public function sendRequest(method:String, params){
|
13
|
+
JQueryStatic.post(
|
14
|
+
"/view_component/"+ this.componentName +"/"+ method,
|
15
|
+
params,
|
16
|
+
function(data, status, xhr){
|
17
|
+
var func = this.callbacks.get(method);
|
18
|
+
if(func != null){ func(data, status, xhr); }
|
19
|
+
}).fail(function(e){
|
20
|
+
trace("ERROR:"+e);
|
21
|
+
});
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ViewComponent::ViewComponentBuilder
|
2
|
+
def initialize
|
3
|
+
@count = 0
|
4
|
+
@components = []
|
5
|
+
end
|
6
|
+
def destribute name, erb_params={}, ajax_params = {}
|
7
|
+
@count += 1
|
8
|
+
klass = Module.const_get("#{name.to_s.camelize}::#{name.to_s.camelize}Model")
|
9
|
+
obj = klass.new @count
|
10
|
+
@components.push obj
|
11
|
+
obj.html(erb_params, ajax_params).html_safe
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_javascripts
|
15
|
+
@components.inject([]){|acc,c|acc + c.javascripts}.uniq
|
16
|
+
end
|
17
|
+
def all_stylesheets
|
18
|
+
@components.inject([]){|acc,c|acc + c.stylesheets}.uniq
|
19
|
+
end
|
20
|
+
|
21
|
+
def refer_to_javascripts
|
22
|
+
all_javascripts.map{|js|
|
23
|
+
"<script type='text/javascript' src='#{js}'></script>" }.join
|
24
|
+
end
|
25
|
+
def refer_to_stylesheets
|
26
|
+
all_stylesheets.map{|css|
|
27
|
+
"<link rel='stylesheet' type='text/css' href='#{css}'>" }.join
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module ViewComponent::ViewComponentHelper
|
3
|
+
|
4
|
+
def view_components &block
|
5
|
+
builder = ViewComponent::ViewComponentBuilder.new
|
6
|
+
block.call builder
|
7
|
+
footer = builder.refer_to_javascripts
|
8
|
+
footer += builder.refer_to_stylesheets
|
9
|
+
raw footer
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ViewComponent::ViewComponentModel
|
2
|
+
attr_reader :component_name, :html_identifier, :html_classes
|
3
|
+
def initialize id
|
4
|
+
@component_name = self.class.name.match(/^(?<name>[^:]+)::/)[:name].underscore
|
5
|
+
@html_identifier = "#{@component_name}_#{id}"
|
6
|
+
@html_classes = ["view_component", "#{@component_name}_view_component"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def responsibility
|
10
|
+
1
|
11
|
+
end
|
12
|
+
|
13
|
+
def javascripts
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
def stylesheets
|
17
|
+
[]
|
18
|
+
end
|
19
|
+
|
20
|
+
def html erb_params={}, ajax_params={}
|
21
|
+
action_view = ActionView::Base.new "#{Rails.root}/app/view_components/#{@component_name}/views"
|
22
|
+
erb_params.each{|k,v| action_view.assign(k=>v) }
|
23
|
+
data = ajax_params.map{|k,v| "data-#{k}='#{v}'" }.join(' ')
|
24
|
+
return <<HTML
|
25
|
+
<div id="#{@html_identifier}" class="#{@html_classes.join(' ')}" #{data}>
|
26
|
+
#{action_view.render(template: self.erb_script)}
|
27
|
+
</div>
|
28
|
+
HTML
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi Kojima
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- MIT-LICENSE
|
35
35
|
- README.rdoc
|
36
36
|
- Rakefile
|
37
|
-
- haxe_compile.hxml
|
38
37
|
- lib/generators/rails_view_component/USAGE
|
39
38
|
- lib/generators/rails_view_component/erb/controller.rb.erb
|
40
39
|
- lib/generators/rails_view_component/erb/haxe/RailsViewComponent.hx.erb
|
@@ -42,6 +41,11 @@ files:
|
|
42
41
|
- lib/generators/rails_view_component/erb/routes.rb.erb
|
43
42
|
- lib/generators/rails_view_component/erb/views/rails_view_component.html.erb.erb
|
44
43
|
- lib/generators/rails_view_component/rails_view_component_generator.rb
|
44
|
+
- lib/generators/rails_view_component/templates/haxe_compile.hxml
|
45
|
+
- lib/generators/rails_view_component/templates/view_component/haxe/ViewComponent.hx
|
46
|
+
- lib/generators/rails_view_component/templates/view_component/view_component_builder.rb
|
47
|
+
- lib/generators/rails_view_component/templates/view_component/view_component_helper.rb
|
48
|
+
- lib/generators/rails_view_component/templates/view_component/view_component_model.rb
|
45
49
|
- lib/rails_view_component.rb
|
46
50
|
- lib/rails_view_component/engine.rb
|
47
51
|
- lib/rails_view_component/haxe/RailsViewComponent.hx
|