jade-rails 1.11.0.0 → 1.11.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea5675355be3294f2c41a542b0903f7dce8a2892
4
- data.tar.gz: 06585d018f271cbeb6b721c29053232699898ff5
3
+ metadata.gz: 5daf720219cde3a9acc61c884bdb8c36c945b7d1
4
+ data.tar.gz: 0a846c24ab2f425032e18dd23715db7f168400c6
5
5
  SHA512:
6
- metadata.gz: 33a213e6b54f6b6e70f914c4e40c0849cc05e937ad6e980e5b52ec27b213666d147de6212e942da5a62b316933cdf9ee77653ecb76a82f9c9f3297c4f9b61e56
7
- data.tar.gz: 26a32286e9e082a316de221e17d918fc1134cc3ca013983ca86f6f0a8f9346591c096dc7691dca8d1d3692a074c50173a0e90f72cb695e06ef332a8a1119d5ed
6
+ metadata.gz: fbff9f116362d01341ed86b535417cee43a2490ae59cb0b2bc186df48c8d91e5353cc7c721366418e21ec5f60b8bb1425a61759527b133a2fd483154196a8419
7
+ data.tar.gz: b13772c010acbae87dc7ef609be6ad3e1a15734739b55b01064809d78d2e3f875dcf8ee2d72f40e7980fd8cd4febf80c96749c96fbefeefd0b1a317ac70d3d7b
data/README.md CHANGED
@@ -11,7 +11,7 @@ to render Jade templates anywhere on the front end of your Rails app.
11
11
  Add to your Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'jade-rails', '~> 1.11.0.0'
14
+ gem 'jade-rails', '~> 1.11.0.1'
15
15
  ```
16
16
 
17
17
  In your `application.js`, require the Jade runtime before any files that include
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # This line will be overwritten by the integration-testing script as needed.
5
+ # gem 'rails', 'X.Y.Z'
@@ -0,0 +1,4 @@
1
+ h1 Jade: A Template Engine
2
+ p.lead.
3
+ Jade is a terse and simple templating language with a strong focus on
4
+ performance and powerful features.
@@ -0,0 +1,7 @@
1
+ <div id="test-container">
2
+ </div>
3
+
4
+ <%= javascript_tag do -%>
5
+ var testElement = document.getElementById("test-container");
6
+ testElement.innerHTML = JST['amazing_template']();
7
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ root 'test#index'
3
+ end
@@ -0,0 +1,4 @@
1
+ class TestController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,153 @@
1
+ #!/bin/bash
2
+ #
3
+ # This script runs "integration tests" for the jade-rails gem.
4
+ # For each Rails version we'd like to confirm compatibility with, the script will:
5
+ # 1. Instantiate a new Rails app.
6
+ # 2. Add the jade-rails gem to the app.
7
+ # 3. Set up a basic controller and view.
8
+ # 4. Add a simple Jade template, and set up the view to render it.
9
+ # 5. Assert that the Jade template is correctly compiled. Specifically:
10
+ # 5.1. In development, assert that the Jade template correctly compiles to a JS file.
11
+ # 5.2. In production, assert that:
12
+ # - the application.js file compiles
13
+ # - the application.js file contains the Jade template JS
14
+ #
15
+ # ASSUMPTIONS:
16
+ # - This script is running on OS X. (The sed syntax is specific to OS X.)
17
+ # - The bundler gem is globally available.
18
+ # - rbenv is being used to manage Ruby versions.
19
+ #---------------------------------------------------------------------------------------------------
20
+ set -e
21
+ set -o pipefail
22
+
23
+ # This is a utility function to fail-fast if an assertion fails.
24
+ # It takes 1 argument which is the text of the error itself.
25
+ raise () {
26
+ echo
27
+ echo "ERROR"
28
+ echo $1
29
+ echo
30
+ exit 1
31
+ }
32
+
33
+ # To simplify all the other references to files and paths, force this script to only run from inside
34
+ # the integration-tests directory itself.
35
+ current_directory=$(pwd)
36
+ if [[ $current_directory != *"integration-tests" ]]; then
37
+ raise "This script must be run from inside the integration-tests directory."
38
+ fi
39
+
40
+ # Test against the currently-supported Rails versions.
41
+ # See: http://guides.rubyonrails.org/maintenance_policy.html
42
+ rails_versions=(4.1.15 4.2.6)
43
+ # rails_versions=(4.1.15)
44
+ dev_server_port=30000
45
+ for rails_version in ${rails_versions[@]}; do
46
+ echo
47
+ echo "Beginning integration test for Rails v${rails_version}..."
48
+ echo
49
+
50
+ # Set up the version of Rails we're testing against.
51
+ sed -i '' "5 s/.*/gem 'rails', '${rails_version}'/" ./Gemfile
52
+ bundle install
53
+ rbenv rehash
54
+ installed_rails_version=$(bundle exec rails -v)
55
+ if [[ $installed_rails_version != "Rails ${rails_version}" ]]; then
56
+ raise "Failed to correctly install Rails version ${rails_version}."
57
+ fi
58
+
59
+ # Instantiate a new Rails app using that version.
60
+ app_name="test-${rails_version}"
61
+ bundle exec rails new ${app_name}
62
+
63
+ # Inside this Rails app, set up the jade-rails gem.
64
+ # (1) Add it to the Gemfile.
65
+ sed -i '' "$ a\\
66
+ gem 'jade-rails', :path => '../../'
67
+ " ./${app_name}/Gemfile
68
+ # (2) Run `bundle install` for the Rails app.
69
+ cd ${app_name}
70
+ bundle install
71
+ # (3) Add the jade-runtime to the application.js.
72
+ sed -i '' "/require_tree/ i\\
73
+ //= require jade/runtime
74
+ " ./app/assets/javascripts/application.js
75
+
76
+ # Now set up a simple Jade template, along with the controller, view, and route to render it.
77
+ # These files look exactly the same regardless of Rails version or app name.
78
+ cp ../fixtures/amazing_template.jst.jade ./app/assets/javascripts/
79
+ cp ../fixtures/test_controller.rb ./app/controllers/
80
+ mkdir ./app/views/test
81
+ cp ../fixtures/index.html.erb ./app/views/test/
82
+ cp ../fixtures/routes.rb ./config/routes.rb
83
+
84
+ # Now that we have a barebones Rails app set up with the gem and a Jade
85
+ # template, we test to ensure the template compiles and renders properly, in
86
+ # both dev and production. We also want to test the ability to set the
87
+ # config.jade flags in the app code. So, specifically, the test plan is:
88
+ #
89
+ # 1. Test production assets.
90
+ # - Compile assets for production.
91
+ # - Confirm that the compiled application.js contains a Jade template ready to use.
92
+ # - Confirm that the compiled application.js does not have Jade code
93
+ # compiled with compileDebug (because this should be disabled by the
94
+ # default configuration for this gem). See lib/jade/rails/engine.rb.
95
+ # 2. Test development assets.
96
+ # - Start a Rails dev server and request the application.js compiled on the fly for dev.
97
+ # - Confirm that the application.js served in development has the Jade template ready to use.
98
+ # - Confirm that the template was compiled with compileDebug turned on.
99
+ # 3. Test app-level configuration.
100
+ # - Set config.jade.compile_debug to true in config/environments/production.rb.
101
+ # - Recompile assets for production.
102
+ # - Confirm that the compiled application.js has debugging code inside the Jade template.
103
+ #
104
+ # (Note that, by default, our test code also requires all commands to execute
105
+ # successfully, because of the settings at the top of this script.)
106
+
107
+ # These are the strings we'll check for to indicate whether or not
108
+ # compileDebug was used when compiling the Jade template.
109
+ compile_debug_off_string="this.JST.amazing_template=function(){var e=[];return e.push('<h1>Jade: A Template Engine</h1>"
110
+ compile_debug_on_string="unshift(new jade.DebugItem("
111
+
112
+ # 1. Test production assets.
113
+ RAILS_ENV=production bundle exec rake assets:precompile
114
+ production_compiled_js=$(cat public/assets/application-*.js)
115
+ if [[ $production_compiled_js != *"$compile_debug_off_string"* ]]; then
116
+ raise "Precompiled application.js did not have expected production-ready Jade template code."
117
+ fi
118
+ if [[ $production_compiled_js == *"$compile_debug_on_string"* ]]; then
119
+ raise "Precompiled application.js contained debugging code inside Jade template."
120
+ fi
121
+
122
+ # 2. Test development assets.
123
+ # Start up a server, request the compiled asset for the Jade template, and check its contents.
124
+ # bundle exec rails s -p ${dev_server_port} > /dev/null 2>&1 &
125
+ bundle exec rails s -p ${dev_server_port} &
126
+ sleep 5 # Give the dev server time to boot.
127
+ dev_compiled_js=$(curl localhost:${dev_server_port}/assets/application.js)
128
+ if [[ $dev_compiled_js != *"$compile_debug_on_string"* ]]; then
129
+ raise "Development application.js did not contain debugging code inside Jade template."
130
+ fi
131
+ # Clean up the backgrounded dev server.
132
+ kill %%
133
+
134
+ # 3. Test app-level configuration.
135
+ sed -i '' "/Rails.application.configure do/ a\\
136
+ config.jade.compile_debug = true
137
+ " ./config/environments/production.rb
138
+ rm -r tmp/
139
+ rm -r public/assets
140
+ RAILS_ENV=production bundle exec rake assets:precompile
141
+ production_compiled_js=$(cat public/assets/application-*.js)
142
+ if [[ $production_compiled_js != *"$compile_debug_on_string"* ]]; then
143
+ raise "Precompiled application.js with compileDebug true did not contain debugging code inside Jade template."
144
+ fi
145
+
146
+ # Clean out the instantiated Rails app.
147
+ cd ..
148
+ rm -r ${app_name}
149
+
150
+ echo
151
+ echo "Successfully completed integration test for Rails v${rails_version}."
152
+ echo
153
+ done
@@ -1,10 +1,10 @@
1
1
  lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'jade/version'
3
+ require 'jade/rails/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'jade-rails'
7
- spec.version = Jade::VERSION
7
+ spec.version = Jade::Rails::VERSION
8
8
  spec.author = 'Paul Raythattha'
9
9
  spec.email = 'paul@appfactories.com'
10
10
  spec.summary = %q{Jade adapter for the Rails asset pipeline.}
@@ -1,25 +1,2 @@
1
1
  # Jade Template Compiler for Ruby
2
-
3
- require 'json'
4
- require 'execjs'
5
-
6
- module Jade
7
- class << self
8
-
9
- def compile(source, options = {})
10
- @@context ||= begin
11
- jade_js = File.read(File.expand_path('../../vendor/assets/javascripts/jade/jade.js', __FILE__))
12
- ExecJS.compile <<-JS
13
- var window = {};
14
- #{jade_js}
15
- var jade = window.jade;
16
- JS
17
- end
18
- source = source.read if source.respond_to?(:read)
19
- @@context.eval("jade.compileClient(#{source.to_json}, #{options.to_json})")
20
- end
21
-
22
- end
23
- end
24
-
25
- require 'jade/railtie' if defined?(Rails)
2
+ require 'jade/rails'
@@ -0,0 +1,10 @@
1
+ module Jade
2
+ module Rails
3
+ end
4
+ end
5
+
6
+ require 'jade/rails/version'
7
+ require 'jade/rails/engine'
8
+ require 'jade/rails/compiler'
9
+ require 'jade/rails/processor'
10
+ require 'jade/rails/template'
@@ -0,0 +1,26 @@
1
+ module Jade
2
+ module Rails
3
+ class Compiler
4
+ def self.compile(source, options = {})
5
+ @@context ||= begin
6
+ jade_js = File.read(File.expand_path('../../../../vendor/assets/javascripts/jade/jade.js', __FILE__))
7
+ ExecJS.compile <<-JS
8
+ var window = {};
9
+ #{jade_js}
10
+ var jade = window.jade;
11
+ JS
12
+ end
13
+
14
+ # Get the compilation options from the application's config.jade.
15
+ # See lib/jade/rails/engine.rb for details.
16
+ options = ::Rails.application.config.jade.merge(options)
17
+ # For one of the options keys, we need to manually camel-case before
18
+ # passing to the Jade compiler.
19
+ options[:compileDebug] = options.delete(:compile_debug) { false }
20
+
21
+ source = source.read if source.respond_to?(:read)
22
+ compiled = @@context.eval("jade.compileClient(#{source.to_json}, #{options.to_json})")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ module Jade
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+
5
+ config.jade = ActiveSupport::OrderedOptions.new
6
+
7
+ # Set default values. See README for details.
8
+ config.jade.pretty = ::Rails.env.development?
9
+ config.jade.self = false
10
+ config.jade.compile_debug = ::Rails.env.development?
11
+ config.jade.globals = []
12
+
13
+ initializer 'jade.assets.register', :group => :all do |app|
14
+ config.assets.configure do |env|
15
+ env.register_mime_type 'text/x-jade-template', :extensions => ['.jade', '.jst.jade']
16
+ if env.respond_to?(:register_transformer)
17
+ # Sprockets 3 introduces the idea of "transformers," which is
18
+ # exactly what we want here. Note that this transformer class
19
+ # should also be compatible with Sprockets 4. For details, see:
20
+ # https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md
21
+ env.register_transformer 'text/x-jade-template', 'application/javascript', Jade::Rails::Processor
22
+ else
23
+ # If it's not possible to register a transformer, we must be in
24
+ # Sprockets 2. In this case, we'll continue with the old way of
25
+ # using a Tilt template. Later, when we decide to drop support for
26
+ # Sprockets 2, it should be a simple matter of just deleting this
27
+ # clause and the lib/jade/rails/template.rb file.
28
+ app.assets.register_engine '.jade', ::Jade::Rails::Template
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module Jade
2
+ module Rails
3
+ class Processor
4
+
5
+ def initialize(filename, &block)
6
+ @filename = filename
7
+ @source = block.call
8
+ end
9
+
10
+ def render(variable, empty_hash)
11
+ self.class.run(@filename, @source)
12
+ end
13
+
14
+ def self.call(input)
15
+ # Compile the Jade template into a JS template function.
16
+ source = input[:data]
17
+ filename = input[:filename]
18
+ compiled = Compiler.compile(source, { :filename => filename })
19
+
20
+ # Then use the JST processor to add the template to the window.JST object.
21
+ input[:data] = compiled
22
+ return ::Sprockets::JstProcessor.call(input)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ require 'tilt'
2
+
3
+ module Jade
4
+ module Rails
5
+ class Template < Tilt::Template
6
+ def self.engine_initialized?
7
+ true
8
+ end
9
+
10
+ def initialize_engine
11
+ end
12
+
13
+ def prepare
14
+ end
15
+
16
+ # Compile template data using Jade compiler.
17
+ #
18
+ # This returns a String containing a JS function, which is intended
19
+ # to be used with the Sprockets JST engine. Name your file so that
20
+ # it is processed by both of these engines, and then the template
21
+ # will be available on the JST global on the front end.
22
+ #
23
+ # For example, `my_template.jst.jade` will be available on the front
24
+ # end as JST['my_template'], which is a function that takes a single
25
+ # argument containing the locals to use in rendering the template:
26
+ #
27
+ # # => function template(locals) { ... }
28
+ #
29
+ def evaluate(context, locals, &block)
30
+ options = { }
31
+ options[:filename] = eval_file
32
+ Compiler.compile(data, options)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Jade
2
+ module Rails
3
+ VERSION = '1.11.0.1'
4
+ end
5
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jade-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0.0
4
+ version: 1.11.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Raythattha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-13 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tilt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  description: Jade adapter for the Rails asset pipeline.
@@ -72,16 +72,25 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
- - .gitignore
75
+ - ".gitignore"
76
76
  - Gemfile
77
77
  - LICENSE
78
78
  - README.md
79
79
  - Rakefile
80
+ - integration-tests/Gemfile
81
+ - integration-tests/fixtures/amazing_template.jst.jade
82
+ - integration-tests/fixtures/index.html.erb
83
+ - integration-tests/fixtures/routes.rb
84
+ - integration-tests/fixtures/test_controller.rb
85
+ - integration-tests/run-tests.sh
80
86
  - jade-rails.gemspec
81
87
  - lib/jade-rails.rb
82
- - lib/jade/railtie.rb
83
- - lib/jade/template.rb
84
- - lib/jade/version.rb
88
+ - lib/jade/rails.rb
89
+ - lib/jade/rails/compiler.rb
90
+ - lib/jade/rails/engine.rb
91
+ - lib/jade/rails/processor.rb
92
+ - lib/jade/rails/template.rb
93
+ - lib/jade/rails/version.rb
85
94
  - test/test_jade-rails.rb
86
95
  - vendor/assets/javascripts/jade/LICENSE
87
96
  - vendor/assets/javascripts/jade/jade.js
@@ -97,17 +106,17 @@ require_paths:
97
106
  - lib
98
107
  required_ruby_version: !ruby/object:Gem::Requirement
99
108
  requirements:
100
- - - '>='
109
+ - - ">="
101
110
  - !ruby/object:Gem::Version
102
111
  version: '0'
103
112
  required_rubygems_version: !ruby/object:Gem::Requirement
104
113
  requirements:
105
- - - '>='
114
+ - - ">="
106
115
  - !ruby/object:Gem::Version
107
116
  version: '0'
108
117
  requirements: []
109
118
  rubyforge_project:
110
- rubygems_version: 2.0.14
119
+ rubygems_version: 2.5.1
111
120
  signing_key:
112
121
  specification_version: 4
113
122
  summary: Jade adapter for the Rails asset pipeline.
@@ -1,25 +0,0 @@
1
- require 'jade/template'
2
-
3
- module Jade
4
- class Railtie < Rails::Engine
5
- module JadeContext
6
- attr_accessor :jade_config
7
- end
8
-
9
- config.jade = ActiveSupport::OrderedOptions.new
10
-
11
- config.jade.pretty = Rails.env.development?
12
- config.jade.self = false
13
- config.jade.compile_debug = Rails.env.development?
14
- config.jade.globals = []
15
-
16
- initializer :setup_jade, after: 'sprockets.environment', group: :all do |app|
17
- if app.assets
18
- app.assets.register_engine '.jade', ::Jade::Template
19
-
20
- app.assets.context_class.extend(JadeContext)
21
- app.assets.context_class.jade_config = app.config.jade
22
- end
23
- end
24
- end
25
- end
@@ -1,49 +0,0 @@
1
- require 'tilt'
2
-
3
- module Jade
4
- class Template < Tilt::Template
5
-
6
- def self.engine_initialized?
7
- defined? ::Jade
8
- end
9
-
10
- def initialize_engine
11
- require_template_library 'jade'
12
- end
13
-
14
- def prepare
15
- end
16
-
17
- # Compile template data using Jade compiler.
18
- #
19
- # This returns a String containing a JS function, which is intended
20
- # to be used with the Sprockets JST engine. Name your file so that
21
- # it is processed by both of these engines, and then the template
22
- # will be available on the JST global on the front end.
23
- #
24
- # For example, `my_template.jst.jade` will be available on the front
25
- # end as JST['my_template'], which is a function that takes a single
26
- # argument containing the locals to use in rendering the template:
27
- #
28
- # # => function template(locals) { ... }
29
- #
30
- def evaluate(context, locals, &block)
31
- options = { }
32
- options[:filename] = eval_file
33
-
34
- # For Rails 4.0.x and 4.1.x, the app-level config is on context.environment.
35
- # For Rails 4.2.x, it's on context.assets instead.
36
- app_level_config = context.environment.context_class.jade_config
37
- if app_level_config.nil?
38
- app_level_config = context.assets.context_class.jade_config
39
- end
40
- jade_config = app_level_config.merge(options)
41
-
42
- # Manually camelize the one option key that needs to be camelized.
43
- jade_config[:compileDebug] = jade_config.delete(:compile_debug) { false }
44
-
45
- Jade.compile(data, jade_config)
46
- end
47
-
48
- end
49
- end
@@ -1,3 +0,0 @@
1
- module Jade
2
- VERSION = '1.11.0.0'
3
- end