sprockets-coffee-jsx 1.0.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 +7 -0
- data/LICENSE +20 -0
- data/README.md +58 -0
- data/Rakefile +38 -0
- data/lib/sprockets/coffee-react/engine.rb +31 -0
- data/lib/sprockets/coffee-react-postprocessor.rb +26 -0
- data/lib/sprockets/coffee-react-script.rb +38 -0
- data/lib/sprockets/coffee-react.rb +37 -0
- data/lib/sprockets-coffee-react.rb +3 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85f545ece4fa7fb9d370d19112b34aaac3b79558
|
4
|
+
data.tar.gz: 7eb159fdaafd42f1d35528a06acd23eed4553aa7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e12f6685ada112ed82ace1446735c2e47f84408c8830724ed375c5e799db52d9f2b66daeec96a34685239568062c912783c37dcd1c8187579b44418614130ad
|
7
|
+
data.tar.gz: 7854ba0dc81c1dcb26bc03452742a20eeaca6768e04b5a8c08a89352213c3e1089ce931d59b09373d8492bc65d1925e5e5c4895c4c480715c5916b6fa9ac7197
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 James Friend <james@jsdf.co>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# sprockets-coffee-jsx
|
2
|
+
|
3
|
+
Preprocessor for Coffeescript with React JSX (CJSX) support.
|
4
|
+
|
5
|
+
This is an updated version of [sprockets-coffee-react](https://github.com/jsdf/sprockets-coffee-react) gem.
|
6
|
+
|
7
|
+
This gem makes it easy to integrate this into the Rails asset pipeline or other Sprockets chains.
|
8
|
+
|
9
|
+
# Usage
|
10
|
+
|
11
|
+
Add this gem to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sprockets-coffee-jsx'
|
15
|
+
```
|
16
|
+
|
17
|
+
You can name your `JSX` asset files as `.js.coffee.cjsx`, `.js.cjsx` or `.js.coffee`.
|
18
|
+
|
19
|
+
# Rack
|
20
|
+
|
21
|
+
If you're not using rails, you'll need to register the Sprockets preprocessor manually. Here is an
|
22
|
+
adapted version of the Rack example provided by Sprockets, which additionally requires and registers
|
23
|
+
the sprockets-coffee-jsx engine:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'sprockets'
|
27
|
+
require 'sprockets/coffee-react'
|
28
|
+
map '/assets' do
|
29
|
+
environment = Sprockets::Environment.new
|
30
|
+
environment.append_path 'app/assets/javascripts'
|
31
|
+
environment.append_path 'app/assets/stylesheets'
|
32
|
+
environment.register_mime_type 'text/cjsx', extensions: ['.cjsx', '.js.cjsx', '.js.coffee.cjsx'], charset: :unicode
|
33
|
+
environment.register_transformer 'text/cjsx', 'application/javascript', Sprockets::CoffeeReactScript
|
34
|
+
environment.register_preprocessor 'application/javascript', Sprockets::CoffeeReact
|
35
|
+
environment.register_postprocessor 'application/javascript', Sprockets::CoffeeReactPostprocessor
|
36
|
+
run environment
|
37
|
+
end
|
38
|
+
|
39
|
+
map '/' do
|
40
|
+
run YourRackApp
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
# Middleman
|
45
|
+
|
46
|
+
Add the following to your config.rb file:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'sprockets/coffee-react'
|
50
|
+
::Sprockets.register_mime_type 'text/cjsx', extensions: ['.cjsx', '.js.cjsx', '.js.coffee.cjsx'], charset: :unicode
|
51
|
+
::Sprockets.register_transformer 'text/cjsx', 'application/javascript', Sprockets::CoffeeReactScript
|
52
|
+
::Sprockets.register_preprocessor 'application/javascript', Sprockets::CoffeeReact
|
53
|
+
::Sprockets.register_postprocessor 'application/javascript', Sprockets::CoffeeReactPostprocessor
|
54
|
+
```
|
55
|
+
|
56
|
+
# License
|
57
|
+
|
58
|
+
Released under the MIT License. See the LICENSE file for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'SprocketsCoffeeReact'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.libs << 'test'
|
33
|
+
t.pattern = 'test/**/*_test.rb'
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => :test
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'sprockets/coffee-react'
|
3
|
+
require 'sprockets/coffee-react-postprocessor'
|
4
|
+
|
5
|
+
if defined?(Rails)
|
6
|
+
module Sprockets
|
7
|
+
class CoffeeReact
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
initializer :setup_coffee_react, :after => "sprockets.environment", :group => :all do |app|
|
10
|
+
if app.assets
|
11
|
+
self.class.install app.assets
|
12
|
+
else
|
13
|
+
app.config.assets.configure { |env| self.class.install env }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.install(environment)
|
18
|
+
if environment.respond_to?(:register_transformer)
|
19
|
+
environment.register_mime_type 'text/cjsx', extensions: ['.cjsx', '.js.cjsx', '.js.coffee.cjsx'], charset: :unicode
|
20
|
+
environment.register_transformer 'text/cjsx', 'application/javascript', Sprockets::CoffeeReactScript
|
21
|
+
else
|
22
|
+
environment.register_engine '.cjsx', Sprockets::CoffeeReactScript
|
23
|
+
environment.register_engine '.js.cjsx', Sprockets::CoffeeReactScript
|
24
|
+
end
|
25
|
+
environment.register_preprocessor 'application/javascript', Sprockets::CoffeeReact
|
26
|
+
environment.register_postprocessor 'application/javascript', Sprockets::CoffeeReactPostprocessor
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'tilt'
|
3
|
+
require 'coffee-react'
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
class CoffeeReactPostprocessor < Tilt::Template
|
7
|
+
|
8
|
+
def prepare
|
9
|
+
end
|
10
|
+
|
11
|
+
def evaluate(scope, locals, &block)
|
12
|
+
self.class.run(scope.pathname.to_s, data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.call(input)
|
16
|
+
filename = input[:source_path] || input[:filename]
|
17
|
+
source = input[:data]
|
18
|
+
run(filename, source)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.run(filename, source)
|
22
|
+
::CoffeeReact.jstransform(source)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'tilt'
|
3
|
+
require 'coffee-react'
|
4
|
+
require 'coffee_script'
|
5
|
+
|
6
|
+
module Sprockets
|
7
|
+
# Preprocessor that runs CJSX source files through coffee-react-transform
|
8
|
+
# then compiles with coffee-script
|
9
|
+
class CoffeeReactScript < Tilt::Template
|
10
|
+
COFFEE_CJSX_EXTENSION = /\.coffee\.cjsx/
|
11
|
+
CJSX_EXTENSION = /\.cjsx[^\/]*?$/
|
12
|
+
CJSX_PRAGMA = /^\s*#[ \t]*@cjsx/i
|
13
|
+
|
14
|
+
def prepare
|
15
|
+
end
|
16
|
+
|
17
|
+
def evaluate(scope, locals, &block)
|
18
|
+
self.class.run(scope.pathname.to_s, data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.call(input)
|
22
|
+
filename = input[:source_path] || input[:filename]
|
23
|
+
source = input[:data]
|
24
|
+
run(filename, source)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.run(filename, source)
|
28
|
+
if filename =~ COFFEE_CJSX_EXTENSION
|
29
|
+
::CoffeeReact.transform(source)
|
30
|
+
elsif filename =~ CJSX_EXTENSION || source =~ CJSX_PRAGMA
|
31
|
+
::CoffeeScript.compile(::CoffeeReact.transform(source))
|
32
|
+
else
|
33
|
+
source
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'tilt'
|
3
|
+
require 'coffee-react'
|
4
|
+
require 'sprockets/coffee-react-postprocessor'
|
5
|
+
|
6
|
+
module Sprockets
|
7
|
+
# Preprocessor that runs CJSX source files through coffee-react-transform
|
8
|
+
class CoffeeReact < Tilt::Template
|
9
|
+
CJSX_EXTENSION = /\.(:?cjsx|coffee)[^\/]*?$/
|
10
|
+
CJSX_PRAGMA = /^\s*#[ \t]*@cjsx/i
|
11
|
+
|
12
|
+
def prepare
|
13
|
+
end
|
14
|
+
|
15
|
+
def evaluate(scope, locals, &block)
|
16
|
+
self.class.run(scope.pathname.to_s, data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.call(input)
|
20
|
+
filename = input[:source_path] || input[:filename]
|
21
|
+
source = input[:data]
|
22
|
+
run(filename, source)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.run(filename, source)
|
26
|
+
if filename =~ CJSX_EXTENSION || source =~ CJSX_PRAGMA
|
27
|
+
::CoffeeReact.transform(source)
|
28
|
+
else
|
29
|
+
source
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.install(environment = ::Sprockets)
|
34
|
+
Sprockets::CoffeeReact::Engine.install(environment)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-coffee-jsx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rael Gugelmin Cunha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coffee-react
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coffee-script
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tilt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sprockets
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |2
|
70
|
+
Preprocessor for Coffeescript with React JSX (CJSX).
|
71
|
+
This gem makes it easy to integrate this into the Rails asset pipeline or other Sprockets chains.
|
72
|
+
If you want to use CJSX without Sprockets, see the coffee-react gem, or the coffee-react npm module.
|
73
|
+
This is an update version of sprockets-coffee-react gem.
|
74
|
+
email: rael.gc@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/sprockets-coffee-react.rb
|
83
|
+
- lib/sprockets/coffee-react-postprocessor.rb
|
84
|
+
- lib/sprockets/coffee-react-script.rb
|
85
|
+
- lib/sprockets/coffee-react.rb
|
86
|
+
- lib/sprockets/coffee-react/engine.rb
|
87
|
+
homepage: https://github.com/raelgc/sprockets-coffee-jsx
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.8
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Coffeescript with React JSX (CJSX) via Sprockets
|
111
|
+
test_files: []
|