react-jsx-sprockets 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 649065ead5c0c32a42ded314213eca5307e38ae3
4
+ data.tar.gz: d0666563eaa8143e472a75525c6896f30b086941
5
+ SHA512:
6
+ metadata.gz: bc08ed00ce5822550e141257232cf02e2d122e6023a6ea6165cc995fe6ee31a3147daf1db41e6496810c383f30230e2784d1cb2dce76aaee596b2ef18866df40
7
+ data.tar.gz: 272ae24fe8e4066534a7079c7de633f674694b0aee922d47f7f4f8492cbe007adeb1069dc96e6284c866ca4720fdb70e7d19e319adf435708805a027fb47ce9a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ tags
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lodash-assets.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jesse Stuart
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ReactJSXSprockets
2
+
3
+ **ReactJSXSprockets** compiles your [React JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) files in your [Sprockets](https://github.com/sstephenson/sprockets) environment.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your `Gemfile`:
8
+
9
+ gem 'react-jsx-sprockets'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ ReactJSXSprockets.configure do |config|
19
+ config.extensions = %w( jsx )
20
+ end
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,35 @@
1
+ require 'execjs'
2
+
3
+ module ReactJSXSprockets
4
+ module JSX
5
+ extend self
6
+
7
+ def compile(source, options = {})
8
+ result = context.call('JSXTransformer.transform', source)
9
+ return result['code']
10
+ end
11
+
12
+ private
13
+
14
+ def context
15
+ @context ||= begin
16
+ # If execjs uses therubyracer, there is no 'global'. Make sure
17
+ # we have it so JSX script can work properly.
18
+ contents = 'var global = global || this;' + source
19
+ ExecJS.compile(contents)
20
+ end
21
+ end
22
+
23
+ def source
24
+ @source ||= File.read(path)
25
+ end
26
+
27
+ def path
28
+ @path ||= File.join(assets_path, 'javascripts', 'jsx.js')
29
+ end
30
+
31
+ def assets_path
32
+ @assets_path ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'assets'))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'tilt'
2
+
3
+ module ReactJSXSprockets
4
+ class Tilt < Tilt::Template
5
+ self.default_mime_type = 'application/javascript'
6
+
7
+ CompileError = Class.new(StandardError)
8
+
9
+ def evaluate(scope, locals, &block)
10
+ begin
11
+ output = JSX.compile(data)
12
+ rescue ExecJS::RuntimeError => e
13
+ raise CompileError.new("ReactJSXSprockets: Failed to compile: #{e.inspect}")
14
+ end
15
+
16
+ output
17
+ end
18
+
19
+ def prepare; end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module ReactJSXSprockets
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'react-jsx-sprockets/version'
2
+
3
+ module ReactJSXSprockets
4
+ extend self
5
+
6
+ require 'react-jsx-sprockets/jsx'
7
+ require 'react-jsx-sprockets/tilt'
8
+
9
+ DEFAULT_EXTENTIONS = %w( jsx ).freeze
10
+
11
+ attr_writer :extensions
12
+
13
+ def configure
14
+ yield(self)
15
+ end
16
+
17
+ def template_extensions
18
+ @template_extensions ||= DEFAULT_EXTENTIONS
19
+ end
20
+
21
+ ##
22
+ # Register extention(s) with Sprockets
23
+ require 'sprockets'
24
+ ReactJSXSprockets.template_extensions.each do |ext|
25
+ Sprockets.register_engine ".#{ext}", Tilt
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'react-jsx-sprockets/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.authors = ["Jesse Stuart"]
8
+ gem.email = ["jesse@jessestuart.ca"]
9
+ gem.description = %q{Use compiled React JSX files with Sprockets}
10
+ gem.summary = %q{Use compiled React JSX files with Sprockets}
11
+ gem.homepage = "https://github.com/jvatic/react-jsx-sprockets"
12
+
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.name = "react-jsx-sprockets"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = ReactJSXSprockets::VERSION
19
+
20
+ gem.add_runtime_dependency "execjs", ">= 1.2.9"
21
+ gem.add_runtime_dependency "tilt", ">= 1.3.3"
22
+ gem.add_runtime_dependency "sprockets", ">= 2.0.3"
23
+ gem.add_runtime_dependency "yajl-ruby"
24
+ end