mithril_rails 0.0.1 → 0.0.4

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.
@@ -0,0 +1,55 @@
1
+ // Unobtrusive scripting adapter for React
2
+ (function(document, window, m) {
3
+ var CLASS_NAME_ATTR = 'data-mithril-class';
4
+ var PROPS_ATTR = 'data-mithril-props';
5
+
6
+ // jQuery is optional. Use it to support legacy browsers.
7
+ var $ = (typeof jQuery !== 'undefined') && jQuery;
8
+
9
+ var findMithrilDOMNodes = function() {
10
+ var SELECTOR = '[' + CLASS_NAME_ATTR + ']';
11
+ if ($) {
12
+ return $(SELECTOR);
13
+ } else {
14
+ return document.querySelectorAll(SELECTOR);
15
+ }
16
+ };
17
+
18
+ var mountComponents = function() {
19
+ var nodes = findMithrilDOMNodes();
20
+ for (var i = 0; i < nodes.length; ++i) {
21
+ var node = nodes[i];
22
+ var className = node.getAttribute(CLASS_NAME_ATTR);
23
+ // Assume className is simple and can be found at top-level (window).
24
+ // Fallback to eval to handle cases
25
+ var constructor = window[className] || eval.call(window, className);
26
+ var propsJson = node.getAttribute(PROPS_ATTR);
27
+ var props = propsJson && JSON.parse(propsJson);
28
+ // insert props in to module
29
+ constructor.properties = props;
30
+ m.module(node, constructor);
31
+ }
32
+ };
33
+
34
+ // Register page load & unload events
35
+ if ($) {
36
+ $(mountComponents);
37
+ } else {
38
+ document.addEventListener('DOMContentLoaded', mountComponents);
39
+ }
40
+
41
+ // Turbolinks specified events
42
+ if (typeof Turbolinks !== 'undefined') {
43
+ var handleEvent;
44
+ if ($) {
45
+ handleEvent = function(eventName, callback) {
46
+ $(document).on(eventName, callback);
47
+ }
48
+ } else {
49
+ handleEvent = function(eventName, callback) {
50
+ document.addEventListener(eventName, callback);
51
+ }
52
+ }
53
+ handleEvent('page:change', mountComponents);
54
+ }
55
+ })(document, window, m);
@@ -0,0 +1,14 @@
1
+ module MithrilHelper
2
+ def mithril_component(name, args = {}, options = {}, &block)
3
+ options = {:tag => options} if options.is_a?(Symbol)
4
+
5
+ html_options = options.reverse_merge(:data => {})
6
+ html_options[:data].tap do |data|
7
+ data[:mithril_class] = name
8
+ data[:mithril_props] = args.to_json unless args.empty?
9
+ end
10
+ html_tag = html_options.delete(:tag) || :div
11
+
12
+ content_tag(html_tag, '', html_options, &block)
13
+ end
14
+ end
@@ -7,4 +7,4 @@ module MithrilRails
7
7
  end
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,2 +1,2 @@
1
1
  require 'mithril_rails/rails/railtie'
2
- require 'mithril_rails/rails/engine'
2
+ require 'mithril_rails/rails/engine'
@@ -1,3 +1,3 @@
1
1
  module MithrilRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mithril_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Humphreys
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-19 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -60,10 +60,11 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - MIT-LICENSE
63
- - README.rdoc
64
63
  - Rakefile
65
64
  - app/assets/javascripts/JSXTransformer.js
66
65
  - app/assets/javascripts/mithril.js
66
+ - app/assets/javascripts/mithril_ujs.js
67
+ - app/helpers/mithril_helper.rb
67
68
  - lib/mithril_rails.rb
68
69
  - lib/mithril_rails/msx.rb
69
70
  - lib/mithril_rails/msx/template.rb
@@ -164,4 +165,3 @@ test_files:
164
165
  - test/dummy/README.rdoc
165
166
  - test/mithril_rails_test.rb
166
167
  - test/test_helper.rb
167
- has_rdoc:
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = MithrilRails
2
-
3
- This project rocks and uses MIT-LICENSE.