riot_js-rails 0.1.0 → 0.2.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/README.md +84 -3
- data/lib/riot_js/rails.rb +1 -0
- data/lib/riot_js/rails/helper.rb +14 -17
- data/lib/riot_js/rails/processors/compiler.rb +1 -2
- data/lib/riot_js/rails/processors/processor.rb +10 -20
- data/lib/riot_js/rails/processors/sprockets_processor_v2.rb +26 -0
- data/lib/riot_js/rails/processors/sprockets_processor_v3.rb +36 -0
- data/lib/riot_js/rails/railtie.rb +3 -3
- data/lib/riot_js/rails/version.rb +1 -1
- data/riot_js-rails.gemspec +2 -1
- data/vendor/assets/javascripts/riot_rails.js +2 -2
- metadata +28 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2caab9b9960cca67b7470af50ce43bb3daca763
|
4
|
+
data.tar.gz: 6fd2a649d36cfee3669b1fedf839647a2d56f105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b076a2783b991b3e2f29e8973f8bfd9b2ec08395960257482073dd9d8a8324c38d6fa0c4b21b16dbf0d951cc315417c4cb5d21a3af9a740ba3fa58a73e525769
|
7
|
+
data.tar.gz: 881f5d86d9ca7844b10efb615320203fb7973035b1515c90cbaedf28a9eee7c533d20f91b42fc2dad6ae3c7084f68f63b17f11313dced0b88f241bb5a17e811d
|
data/README.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
Muut Riot integration with Rails
|
4
4
|
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
1. Nodejs - for tags compiling.
|
8
|
+
2. jQuery - for tags mounting (if you're going to use helpers provided by gem).
|
9
|
+
3. Rails 3 and 4 supported
|
10
|
+
|
11
|
+
|
5
12
|
## Installation
|
6
13
|
|
7
14
|
Add this line to your application's Gemfile:
|
@@ -10,13 +17,87 @@ Add this line to your application's Gemfile:
|
|
10
17
|
gem 'riot_js-rails'
|
11
18
|
```
|
12
19
|
|
13
|
-
|
20
|
+
Execute:
|
14
21
|
|
15
|
-
$ bundle
|
22
|
+
$ bundle install
|
23
|
+
|
24
|
+
Add ```riot``` and ```riot_rails``` to your ```application.js```:
|
25
|
+
```
|
26
|
+
//= require riot
|
27
|
+
//= require riot_rails
|
28
|
+
```
|
16
29
|
|
17
30
|
## Usage
|
18
31
|
|
19
|
-
|
32
|
+
Put all your components somewhere into ```assets/javascript```. All components tags must have ```.tag``` extension (if you use older version of sprockets, try ```.js.tag```) and need to be required in your ```application.js```. This will compile component to Javascript.
|
33
|
+
|
34
|
+
|
35
|
+
## Helpers
|
36
|
+
|
37
|
+
Each component has to be mounted. It can be done by executing ```riot.mount``` in javascript, e.g.:
|
38
|
+
```javascript
|
39
|
+
$(function() {
|
40
|
+
riot.mount('example-tag');
|
41
|
+
});
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
Alternative approach is to use view helper, e.g.:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
<%= riot_component(:example_tag, { :header => 'Some header' }) %>
|
49
|
+
```
|
50
|
+
This will generate following HTML:
|
51
|
+
```html
|
52
|
+
<example-tag id="riot-example-tag-2822884" class="riot-rails-component"></example-tag>
|
53
|
+
```
|
54
|
+
and immediate mount it with given options.
|
55
|
+
|
56
|
+
You can also use HTML element as tag:
|
57
|
+
```ruby
|
58
|
+
<%= riot_component(:div, :example_tag, { :header => 'Some header' }) %>
|
59
|
+
```
|
60
|
+
which will generate following code:
|
61
|
+
```html
|
62
|
+
<div id="riot-example-tag-5012227" class="riot-rails-component" riot-tag="example-tag"></div>
|
63
|
+
```
|
64
|
+
|
65
|
+
To generate tag with content use block:
|
66
|
+
```ruby
|
67
|
+
<%= riot_component(:example_tag, { :header => 'Some header' }) do %>
|
68
|
+
<p>Content</p>
|
69
|
+
<% end %>
|
70
|
+
```
|
71
|
+
|
72
|
+
If you want to add your own classes to component or any other attributes, pass it as last argument:
|
73
|
+
```ruby
|
74
|
+
<%= riot_component(:div, :example_tag, { :header => 'Some header' }, { class: 'my-class' }) %>
|
75
|
+
```
|
76
|
+
|
77
|
+
# HAML, SASS and CoffeeScript
|
78
|
+
|
79
|
+
You can define tag using HAML, SASS and CoffeeScript. Example:
|
80
|
+
```haml
|
81
|
+
%example-haml
|
82
|
+
%h1{ onclick: "{change_header}" }
|
83
|
+
= "{header}"
|
84
|
+
|
85
|
+
:scss
|
86
|
+
timer-haml {
|
87
|
+
h1 {
|
88
|
+
background-color: #ffff00;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
:coffee
|
93
|
+
self = this
|
94
|
+
this.header = opts.header
|
95
|
+
|
96
|
+
this.change_header = ()->
|
97
|
+
self.header = 'New header'
|
98
|
+
```
|
99
|
+
|
100
|
+
Note: file has to have ```.tag.haml``` extension (or ```.js.tag.haml``` for older version of Sprockets)
|
20
101
|
|
21
102
|
## Contributing
|
22
103
|
|
data/lib/riot_js/rails.rb
CHANGED
data/lib/riot_js/rails/helper.rb
CHANGED
@@ -3,38 +3,35 @@ module RiotJs
|
|
3
3
|
module Helper
|
4
4
|
|
5
5
|
def riot_component(*args, &block)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
html_tag_riot_component(*args, &block)
|
11
|
-
else
|
12
|
-
raise ArgumentError, 'wrong number of arguments (required 2 or 3)'
|
6
|
+
if args[1].kind_of?(Hash)
|
7
|
+
custom_tag_riot_component(*args, &block)
|
8
|
+
else
|
9
|
+
html_tag_riot_component(*args, &block)
|
13
10
|
end
|
14
11
|
end
|
15
12
|
|
16
13
|
private
|
17
14
|
|
18
|
-
def custom_tag_riot_component(name, data, &block)
|
19
|
-
component_name, attributes = component_attributes(name, data)
|
15
|
+
def custom_tag_riot_component(name, data, attributes={}, &block)
|
16
|
+
component_name, attributes = component_attributes(name, data, attributes)
|
20
17
|
|
21
18
|
component_tag(component_name, attributes, &block)
|
22
19
|
end
|
23
20
|
|
24
|
-
def html_tag_riot_component(tag, name, data, &block)
|
25
|
-
component_name, attributes = component_attributes(name, data)
|
21
|
+
def html_tag_riot_component(tag, name, data, attributes={}, &block)
|
22
|
+
component_name, attributes = component_attributes(name, data, attributes)
|
26
23
|
attributes['riot-tag'] = component_name
|
27
24
|
|
28
25
|
component_tag(tag, attributes, &block)
|
29
26
|
end
|
30
27
|
|
31
|
-
def component_attributes(name, data)
|
28
|
+
def component_attributes(name, data, attributes)
|
32
29
|
component_name = name.to_s.gsub('_', '-')
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
attributes_data = attributes[:data] || attributes['data'] || {}
|
31
|
+
attributes_class = attributes[:class] || attributes['class']
|
32
|
+
attributes = attributes.merge(id: "riot-#{component_name}-#{Random.rand(10000000)}",
|
33
|
+
class: "#{attributes_class} riot-rails-component".strip,
|
34
|
+
data: attributes_data.merge(opts: data.to_json))
|
38
35
|
return component_name, attributes
|
39
36
|
end
|
40
37
|
|
@@ -1,34 +1,24 @@
|
|
1
1
|
require 'riot_js/rails/processors/compiler'
|
2
2
|
|
3
|
+
if Gem::Version.new(Sprockets::VERSION) < Gem::Version.new('3.0.0')
|
4
|
+
require 'riot_js/rails/processors/sprockets_processor_v2'
|
5
|
+
else
|
6
|
+
require 'riot_js/rails/processors/sprockets_processor_v3'
|
7
|
+
end
|
8
|
+
|
3
9
|
module RiotJs
|
4
10
|
module Rails
|
5
|
-
class Processor
|
6
|
-
def self.instance
|
7
|
-
@instance ||= new
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.call(input)
|
11
|
-
instance.call(input)
|
12
|
-
end
|
11
|
+
class Processor < SprocketsProcessor
|
13
12
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
data = compile_tag
|
18
|
-
|
19
|
-
@context.metadata.merge(data: data)
|
13
|
+
def process
|
14
|
+
compile_tag
|
20
15
|
end
|
21
16
|
|
22
17
|
private
|
23
18
|
|
24
|
-
def prepare(input)
|
25
|
-
@context = input[:environment].context_class.new(input)
|
26
|
-
@data = input[:data]
|
27
|
-
end
|
28
|
-
|
29
19
|
def compile_tag
|
30
20
|
::RiotJs::Rails::Compiler.compile(@data)
|
31
21
|
end
|
32
22
|
end
|
33
23
|
end
|
34
|
-
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RiotJs
|
2
|
+
module Rails
|
3
|
+
class SprocketsProcessor < Tilt::Template
|
4
|
+
|
5
|
+
self.default_mime_type = 'application/javascript'
|
6
|
+
|
7
|
+
def self.register_self(app)
|
8
|
+
app.assets.register_engine '.tag', self
|
9
|
+
end
|
10
|
+
|
11
|
+
def evaluate(context, locals, &block)
|
12
|
+
@context = context
|
13
|
+
process
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare
|
17
|
+
@data = data
|
18
|
+
end
|
19
|
+
|
20
|
+
def process
|
21
|
+
raise 'Not implemented'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RiotJs
|
2
|
+
module Rails
|
3
|
+
class SprocketsProcessor
|
4
|
+
def self.instance
|
5
|
+
@instance ||= new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.call(input)
|
9
|
+
instance.call(input)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(input)
|
13
|
+
prepare(input)
|
14
|
+
data = process
|
15
|
+
|
16
|
+
@context.metadata.merge(data: data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.register_self(app)
|
20
|
+
app.assets.register_engine '.tag', self, mime_type: 'application/javascript'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def process
|
26
|
+
raise 'Not implemented'
|
27
|
+
end
|
28
|
+
|
29
|
+
def prepare(input)
|
30
|
+
@context = input[:environment].context_class.new(input)
|
31
|
+
@data = input[:data]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -6,11 +6,11 @@ module RiotJs
|
|
6
6
|
module Rails
|
7
7
|
class Railtie < ::Rails::Railtie
|
8
8
|
initializer :setup_sprockets do |app|
|
9
|
-
|
9
|
+
Processor.register_self app
|
10
10
|
|
11
11
|
if defined?(::Haml)
|
12
12
|
require 'tilt/haml'
|
13
|
-
app.assets.register_engine '.haml', ::Tilt::HamlTemplate
|
13
|
+
app.assets.register_engine '.haml', ::Tilt::HamlTemplate
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -22,4 +22,4 @@ module RiotJs
|
|
22
22
|
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
data/riot_js-rails.gemspec
CHANGED
@@ -20,11 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
|
23
|
-
spec.add_dependency 'rails', '
|
23
|
+
spec.add_dependency 'rails', '>= 3.0', '< 4.3'
|
24
24
|
spec.add_dependency 'execjs', '~> 2'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
spec.add_development_dependency 'minitest', '~> 5.1'
|
29
29
|
spec.add_development_dependency 'byebug', '~> 5.0'
|
30
|
+
spec.add_development_dependency 'mocha', '~> 1.0'
|
30
31
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
;(function($) {
|
2
2
|
|
3
3
|
var riotRails = {
|
4
|
-
|
4
|
+
componentClass: 'riot-rails-component',
|
5
5
|
mounted: [],
|
6
6
|
mount: function(selector) {
|
7
7
|
var component = $(selector);
|
@@ -18,7 +18,7 @@
|
|
18
18
|
},
|
19
19
|
mountAll: function() {
|
20
20
|
var self = this;
|
21
|
-
$(self.
|
21
|
+
$('.' + self.componentClass).each(function(){
|
22
22
|
self.mount('#' + $(this).attr('id'));
|
23
23
|
});
|
24
24
|
}
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot_js-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Jaroszewski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4'
|
22
|
+
version: '4.3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4'
|
32
|
+
version: '4.3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: execjs
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +100,20 @@ dependencies:
|
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: '5.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: mocha
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.0'
|
97
117
|
description: This gem provides integration of Muut Riot with Rails
|
98
118
|
email:
|
99
119
|
- b.jarosze@gmail.com
|
@@ -110,6 +130,8 @@ files:
|
|
110
130
|
- lib/riot_js/rails/helper.rb
|
111
131
|
- lib/riot_js/rails/processors/compiler.rb
|
112
132
|
- lib/riot_js/rails/processors/processor.rb
|
133
|
+
- lib/riot_js/rails/processors/sprockets_processor_v2.rb
|
134
|
+
- lib/riot_js/rails/processors/sprockets_processor_v3.rb
|
113
135
|
- lib/riot_js/rails/railtie.rb
|
114
136
|
- lib/riot_js/rails/version.rb
|
115
137
|
- riot_js-rails.gemspec
|