riot_js-rails 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2caab9b9960cca67b7470af50ce43bb3daca763
4
- data.tar.gz: 6fd2a649d36cfee3669b1fedf839647a2d56f105
3
+ metadata.gz: 3336fa961ac6cc151f8e325563c2c8def675d4a4
4
+ data.tar.gz: 84134a612de5ae749d084399be8d23c4fd4084de
5
5
  SHA512:
6
- metadata.gz: b076a2783b991b3e2f29e8973f8bfd9b2ec08395960257482073dd9d8a8324c38d6fa0c4b21b16dbf0d951cc315417c4cb5d21a3af9a740ba3fa58a73e525769
7
- data.tar.gz: 881f5d86d9ca7844b10efb615320203fb7973035b1515c90cbaedf28a9eee7c533d20f91b42fc2dad6ae3c7084f68f63b17f11313dced0b88f241bb5a17e811d
6
+ metadata.gz: f985f48151efe46b088871a08232459e6dd29bb2b1d869ccd7f02fb2c99c88d86d99d3c9377a820d41cc534a94936fa946d7ff67fd62750009509a919e199e9f
7
+ data.tar.gz: d12a75cc7b410a7ece60a27aff51ffb7f3fe6edde10ccd1f9e5bfcfb1fe10ecc457880db3a22ab96a23d46193d5880ac84bc49fb336fcc61fd7eca8335a35010
data/README.md CHANGED
@@ -49,7 +49,7 @@ Alternative approach is to use view helper, e.g.:
49
49
  ```
50
50
  This will generate following HTML:
51
51
  ```html
52
- <example-tag id="riot-example-tag-2822884" class="riot-rails-component"></example-tag>
52
+ <example-tag data-opts="{&quot;header&quot;:&quot;Some header&quot;}" data-mount></example-tag>
53
53
  ```
54
54
  and immediate mount it with given options.
55
55
 
@@ -59,7 +59,7 @@ You can also use HTML element as tag:
59
59
  ```
60
60
  which will generate following code:
61
61
  ```html
62
- <div id="riot-example-tag-5012227" class="riot-rails-component" riot-tag="example-tag"></div>
62
+ <div data-opts="{&quot;header&quot;:&quot;Some header&quot;}" data-mount riot-tag="example-tag"></div>
63
63
  ```
64
64
 
65
65
  To generate tag with content use block:
@@ -74,7 +74,32 @@ If you want to add your own classes to component or any other attributes, pass i
74
74
  <%= riot_component(:div, :example_tag, { :header => 'Some header' }, { class: 'my-class' }) %>
75
75
  ```
76
76
 
77
- # HAML, SASS and CoffeeScript
77
+ If you don't want to use helper you can use plain HTML:
78
+ ```html
79
+ <example-tag data-riot></example-tag>
80
+ ```
81
+
82
+ # Built-in preprocessing
83
+
84
+ You can use one of the Riot built-in preprocessors for javascript.
85
+ Available options are: "coffee", "typescript", "es6" and "none"
86
+
87
+ Example:
88
+ ```
89
+ <my-tag>
90
+ <script type="coffee">
91
+ # your coffeescript logic goes here
92
+ </script>
93
+ </my-tag>
94
+ ```
95
+
96
+ Note that this may require some extra NodeJS modules. Riot-rails uses by default global modules installed by npm (installed with option ```-g```).
97
+ If you want to use local modules add following line to your ```config/application.rb```:
98
+ ```
99
+ config.riot.node_paths << '/path/to/your/node_modules'
100
+ ```
101
+
102
+ # Rails preprocessing: HAML, SASS and CoffeeScript
78
103
 
79
104
  You can define tag using HAML, SASS and CoffeeScript. Example:
80
105
  ```haml
@@ -83,7 +108,7 @@ You can define tag using HAML, SASS and CoffeeScript. Example:
83
108
  = "{header}"
84
109
 
85
110
  :scss
86
- timer-haml {
111
+ example-haml {
87
112
  h1 {
88
113
  background-color: #ffff00;
89
114
  }
@@ -28,10 +28,8 @@ module RiotJs
28
28
  def component_attributes(name, data, attributes)
29
29
  component_name = name.to_s.gsub('_', '-')
30
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))
31
+ riot_data = { opts: data.to_json, riot: true }
32
+ attributes = attributes.merge(data: attributes_data.merge(riot_data))
35
33
  return component_name, attributes
36
34
  end
37
35
 
@@ -12,6 +12,7 @@ module RiotJs
12
12
  encoding: 'UTF-8',
13
13
  runner_path: File.expand_path('../../../../../vendor/assets/javascripts/compiler/node_runner.js', __FILE__),
14
14
  )
15
+ JS_RUNTIME.instance_variable_set :@binary, JS_RUNTIME.send(:locate_binary) if defined?(::Barista)
15
16
 
16
17
  RIOT_COMPILER_PATH = File.expand_path('../../../../../vendor/assets/javascripts/compiler/compiler.js', __FILE__)
17
18
 
@@ -5,6 +5,9 @@ require 'riot_js/rails/helper'
5
5
  module RiotJs
6
6
  module Rails
7
7
  class Railtie < ::Rails::Railtie
8
+ config.riot = ActiveSupport::OrderedOptions.new
9
+ config.riot.node_paths = []
10
+
8
11
  initializer :setup_sprockets do |app|
9
12
  Processor.register_self app
10
13
 
@@ -20,6 +23,26 @@ module RiotJs
20
23
  ::Rails.application.assets.context_class.class_eval(helpers)
21
24
  end
22
25
 
26
+ config.after_initialize do |app|
27
+ node_paths = ENV['NODE_PATH'].to_s.split(':')
28
+ node_paths += app.config.riot.node_paths
29
+ node_global_path = detect_node_global_path
30
+ node_paths << node_global_path if node_global_path
31
+
32
+ ENV['NODE_PATH'] = node_paths.join(':')
33
+ end
34
+
35
+
36
+ def detect_node_global_path
37
+ prefix = `npm config get prefix`.to_s.chomp("\n")
38
+ possible_paths = [ "#{prefix}/lib/node", "#{prefix}/lib/node_modules" ]
39
+
40
+ possible_paths.each do |path|
41
+ return path if File.directory?(path)
42
+ end
43
+ return
44
+ end
45
+
23
46
  end
24
47
  end
25
48
  end
@@ -1,5 +1,5 @@
1
1
  module RiotJs
2
2
  module Rails
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -1,14 +1,20 @@
1
1
  ;(function($) {
2
2
 
3
3
  var riotRails = {
4
- componentClass: 'riot-rails-component',
4
+ componentSelector: '[data-riot]',
5
5
  mounted: [],
6
- mount: function(selector) {
7
- var component = $(selector);
6
+ mount: function(component) {
7
+ var mounted, id, generated;
8
8
  var opts = component.data('opts');
9
+ var id = component.attr('id') || 'riot-' + Math.floor((Math.random() * 10000000));
10
+
11
+ component.attr('id', id);
12
+
9
13
  component.removeAttr('data-opts');
10
- var mounted = riot.mount(selector, opts);
11
- this.mounted.push(mounted[0]);
14
+ component.removeAttr('data-riot');
15
+
16
+ mounted = riot.mount('#' + id, opts);
17
+ this.mounted.concat(mounted);
12
18
  },
13
19
  unmountAll: function () {
14
20
  $.each(this.mounted, function(index, component) {
@@ -18,8 +24,8 @@
18
24
  },
19
25
  mountAll: function() {
20
26
  var self = this;
21
- $('.' + self.componentClass).each(function(){
22
- self.mount('#' + $(this).attr('id'));
27
+ $(self.componentSelector).each(function(){
28
+ self.mount($(this));
23
29
  });
24
30
  }
25
31
  };
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riot_js-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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-27 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails