├── .gitignore
├── Gemfile
├── LICENSE
├── README.md
├── Rakefile
├── integration-tests
├── Gemfile
├── fixtures
│ ├── amazing_template.jst.jade
│ ├── index.html.erb
│ ├── routes.rb
│ └── test_controller.rb
└── run-tests.sh
├── jade-rails.gemspec
├── lib
├── jade-rails.rb
└── jade
│ ├── rails.rb
│ └── rails
│ ├── compiler.rb
│ ├── engine.rb
│ ├── processor.rb
│ ├── template.rb
│ └── version.rb
├── test
└── test_jade-rails.rb
└── vendor
└── assets
└── javascripts
└── jade
├── LICENSE
├── jade.js
├── runtime.js
└── sample_template.jade
/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | *.lock
3 | .bundle
4 | .ruby-version
5 | pkg/
6 | tmp/
7 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # jade-rails.gemspec specifies this gem's dependencies.
4 | gemspec
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Paul Raythattha
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Ruby on Rails Integration with Jade
2 |
3 | This gem provides integration for Ruby on Rails projects with the [Jade
4 | templating language](http://jade-lang.com/).
5 |
6 | Combined with the JST engine built in to Sprockets, you can use this gem
7 | to render Jade templates anywhere on the front end of your Rails app.
8 |
9 | ## Installing
10 |
11 | Add to your Gemfile:
12 |
13 | ```ruby
14 | gem 'jade-rails', '~> 1.11.0.1'
15 | ```
16 |
17 | In your `application.js`, require the Jade runtime before any files that include
18 | Jade templates.
19 |
20 | ```
21 | //= require jade/runtime
22 | ```
23 |
24 | ## Configuring
25 |
26 | Use `config.jade` in your application or environment files to set compilation
27 | options. These will be passed to the Jade compiler for all your templates.
28 |
29 | This gem supports only a subset of the full list of Jade compiler options,
30 | because only some of them make sense for client-side compilation within Rails.
31 |
32 | ### Available Options
33 |
34 | - `pretty`: Add whitespace to the compiled HTML to make it slightly easier to
35 | read. This defaults to `true` in development and `false` otherwise.
36 |
37 | - `self`: Use a `self` namespace to hold locals in compiled templates. This
38 | defaults to `false` in all environments.
39 |
40 | - `compile_debug`: Compile templates with debugging instrumentation. (This is
41 | passed as `compileDebug` to the Jade compiler.) It defaults to `true` in
42 | development and `false` otherwise.
43 |
44 | - `globals`: This is an array of globals (as strings) that will be made
45 | available in the local scope of compiled templates. It defaults to `[]`.
46 |
47 | In addition, the `filename` of the template being compiled is always passed in
48 | to the Jade compiler options. If `compile_debug` is set to `true`, the filename
49 | will be shown as part of the error output.
50 |
51 | See [the official Jade documentation](http://jade-lang.com/api/) for more
52 | details about these options.
53 |
54 | ## Example
55 |
56 | In `config/application.rb`:
57 |
58 | ```ruby
59 | AmazingProject::Application.configure do
60 | config.jade.pretty = true
61 | config.jade.compile_debug = true
62 | config.jade.globals = ['helpers']
63 | end
64 | ```
65 |
66 | In `app/assets/javascripts/templates/amazing_template.jst.jade`:
67 |
68 | ```jade
69 | h1 Jade: A Template Engine
70 | p.lead.
71 | Jade is a terse and simple templating language with a strong focus on
72 | performance and powerful features.
73 | ```
74 |
75 | Then you can render this template anywhere in your JS code:
76 |
77 | ```javascript
78 | JST['templates/amazing_template']()
79 | ```
80 |
81 | ## Notes
82 |
83 | Includes are not supported. Instead, use JST along with Jade's functionality
84 | for unescaped buffered code. For example, to "include" another template named
85 | `includes/header.jst.jade` which renders with no locals, write:
86 |
87 | ```jade
88 | != JST['includes/header']()
89 | ```
90 |
91 | ## Running Tests
92 |
93 | ```bash
94 | bundle exec rake test
95 | ```
96 |
97 | ## Versioning
98 |
99 | The `jade-rails` gem version always reflects the version of Jade it contains,
100 | with an additional number for gem-specific changes.
101 |
102 | Always check [the Jade change log](http://jade-lang.com/history/) when upgrading.
103 |
104 | ## Code Status
105 |
106 | [](http://badge.fury.io/rb/jade-rails)
107 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require "rake/testtask"
2 | require "bundler/gem_tasks"
3 |
4 | Rake::TestTask.new do |t|
5 | t.libs << 'test'
6 | end
7 |
8 | desc 'Run test suite'
9 | task :default => :test
10 |
--------------------------------------------------------------------------------
/integration-tests/Gemfile:
--------------------------------------------------------------------------------
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'
6 |
--------------------------------------------------------------------------------
/integration-tests/fixtures/amazing_template.jst.jade:
--------------------------------------------------------------------------------
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.
5 |
--------------------------------------------------------------------------------
/integration-tests/fixtures/index.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <%= javascript_tag do -%>
5 | var testElement = document.getElementById("test-container");
6 | testElement.innerHTML = JST['amazing_template']();
7 | <% end -%>
8 |
--------------------------------------------------------------------------------
/integration-tests/fixtures/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | root 'test#index'
3 | end
4 |
--------------------------------------------------------------------------------
/integration-tests/fixtures/test_controller.rb:
--------------------------------------------------------------------------------
1 | class TestController < ApplicationController
2 | def index
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/integration-tests/run-tests.sh:
--------------------------------------------------------------------------------
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('Jade: A Template Engine
"
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
154 |
--------------------------------------------------------------------------------
/jade-rails.gemspec:
--------------------------------------------------------------------------------
1 | lib = File.expand_path('../lib', __FILE__)
2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3 | require 'jade/rails/version'
4 |
5 | Gem::Specification.new do |spec|
6 | spec.name = 'jade-rails'
7 | spec.version = Jade::Rails::VERSION
8 | spec.author = 'Paul Raythattha'
9 | spec.email = 'paul@appfactories.com'
10 | spec.summary = %q{Jade adapter for the Rails asset pipeline.}
11 | spec.description = %q{Jade adapter for the Rails asset pipeline.}
12 | spec.homepage = 'https://github.com/mahipal/jade-rails'
13 | spec.license = 'MIT'
14 |
15 | spec.files = `git ls-files -z`.split("\x0")
16 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17 |
18 | spec.add_dependency 'execjs'
19 | spec.add_dependency 'tilt'
20 |
21 | spec.add_development_dependency 'bundler', '~> 1.7'
22 | spec.add_development_dependency 'rake', '~> 10.0'
23 | end
24 |
--------------------------------------------------------------------------------
/lib/jade-rails.rb:
--------------------------------------------------------------------------------
1 | # Jade Template Compiler for Ruby
2 | require 'jade/rails'
3 |
--------------------------------------------------------------------------------
/lib/jade/rails.rb:
--------------------------------------------------------------------------------
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'
11 |
--------------------------------------------------------------------------------
/lib/jade/rails/compiler.rb:
--------------------------------------------------------------------------------
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
27 |
--------------------------------------------------------------------------------
/lib/jade/rails/engine.rb:
--------------------------------------------------------------------------------
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
36 |
--------------------------------------------------------------------------------
/lib/jade/rails/processor.rb:
--------------------------------------------------------------------------------
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
28 |
--------------------------------------------------------------------------------
/lib/jade/rails/template.rb:
--------------------------------------------------------------------------------
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
37 |
--------------------------------------------------------------------------------
/lib/jade/rails/version.rb:
--------------------------------------------------------------------------------
1 | module Jade
2 | module Rails
3 | VERSION = '1.11.0.1'
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/test/test_jade-rails.rb:
--------------------------------------------------------------------------------
1 | require 'jade-rails'
2 | require 'test/unit'
3 |
4 | class JadeTest < Test::Unit::TestCase
5 | JADE_TEMPLATE_FUNCTION_PATTERN = /^function\s+template\s*\(locals\)\s*\{.*\}$/m
6 |
7 | def test_compile
8 | template = File.read(File.expand_path('../../vendor/assets/javascripts/jade/sample_template.jade', __FILE__))
9 | result = Jade.compile(template)
10 | assert_match(JADE_TEMPLATE_FUNCTION_PATTERN, result)
11 | assert_no_match(/^\s*/, result)
12 | end
13 |
14 | def test_compile_with_io
15 | io = StringIO.new('string of jade')
16 | assert_equal Jade.compile('string of jade'), Jade.compile(io)
17 | end
18 |
19 | def test_compilation_error
20 | assert_raise ExecJS::ProgramError do
21 | Jade.compile <<-JADE
22 | else
23 | .foo
24 | JADE
25 | end
26 | end
27 |
28 | end
29 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/jade/LICENSE:
--------------------------------------------------------------------------------
1 | (The MIT License)
2 |
3 | Copyright (c) 2009-2014 TJ Holowaychuk
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 NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/jade/runtime.js:
--------------------------------------------------------------------------------
1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jade = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o} escaped
74 | * @return {String}
75 | */
76 | exports.cls = function cls(classes, escaped) {
77 | var buf = [];
78 | for (var i = 0; i < classes.length; i++) {
79 | if (escaped && escaped[i]) {
80 | buf.push(exports.escape(joinClasses([classes[i]])));
81 | } else {
82 | buf.push(joinClasses(classes[i]));
83 | }
84 | }
85 | var text = joinClasses(buf);
86 | if (text.length) {
87 | return ' class="' + text + '"';
88 | } else {
89 | return '';
90 | }
91 | };
92 |
93 |
94 | exports.style = function (val) {
95 | if (val && typeof val === 'object') {
96 | return Object.keys(val).map(function (style) {
97 | return style + ':' + val[style];
98 | }).join(';');
99 | } else {
100 | return val;
101 | }
102 | };
103 | /**
104 | * Render the given attribute.
105 | *
106 | * @param {String} key
107 | * @param {String} val
108 | * @param {Boolean} escaped
109 | * @param {Boolean} terse
110 | * @return {String}
111 | */
112 | exports.attr = function attr(key, val, escaped, terse) {
113 | if (key === 'style') {
114 | val = exports.style(val);
115 | }
116 | if ('boolean' == typeof val || null == val) {
117 | if (val) {
118 | return ' ' + (terse ? key : key + '="' + key + '"');
119 | } else {
120 | return '';
121 | }
122 | } else if (0 == key.indexOf('data') && 'string' != typeof val) {
123 | if (JSON.stringify(val).indexOf('&') !== -1) {
124 | console.warn('Since Jade 2.0.0, ampersands (`&`) in data attributes ' +
125 | 'will be escaped to `&`');
126 | };
127 | if (val && typeof val.toISOString === 'function') {
128 | console.warn('Jade will eliminate the double quotes around dates in ' +
129 | 'ISO form after 2.0.0');
130 | }
131 | return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, ''') + "'";
132 | } else if (escaped) {
133 | if (val && typeof val.toISOString === 'function') {
134 | console.warn('Jade will stringify dates in ISO form after 2.0.0');
135 | }
136 | return ' ' + key + '="' + exports.escape(val) + '"';
137 | } else {
138 | if (val && typeof val.toISOString === 'function') {
139 | console.warn('Jade will stringify dates in ISO form after 2.0.0');
140 | }
141 | return ' ' + key + '="' + val + '"';
142 | }
143 | };
144 |
145 | /**
146 | * Render the given attributes object.
147 | *
148 | * @param {Object} obj
149 | * @param {Object} escaped
150 | * @return {String}
151 | */
152 | exports.attrs = function attrs(obj, terse){
153 | var buf = [];
154 |
155 | var keys = Object.keys(obj);
156 |
157 | if (keys.length) {
158 | for (var i = 0; i < keys.length; ++i) {
159 | var key = keys[i]
160 | , val = obj[key];
161 |
162 | if ('class' == key) {
163 | if (val = joinClasses(val)) {
164 | buf.push(' ' + key + '="' + val + '"');
165 | }
166 | } else {
167 | buf.push(exports.attr(key, val, false, terse));
168 | }
169 | }
170 | }
171 |
172 | return buf.join('');
173 | };
174 |
175 | /**
176 | * Escape the given string of `html`.
177 | *
178 | * @param {String} html
179 | * @return {String}
180 | * @api private
181 | */
182 |
183 | var jade_encode_html_rules = {
184 | '&': '&',
185 | '<': '<',
186 | '>': '>',
187 | '"': '"'
188 | };
189 | var jade_match_html = /[&<>"]/g;
190 |
191 | function jade_encode_char(c) {
192 | return jade_encode_html_rules[c] || c;
193 | }
194 |
195 | exports.escape = jade_escape;
196 | function jade_escape(html){
197 | var result = String(html).replace(jade_match_html, jade_encode_char);
198 | if (result === '' + html) return html;
199 | else return result;
200 | };
201 |
202 | /**
203 | * Re-throw the given `err` in context to the
204 | * the jade in `filename` at the given `lineno`.
205 | *
206 | * @param {Error} err
207 | * @param {String} filename
208 | * @param {String} lineno
209 | * @api private
210 | */
211 |
212 | exports.rethrow = function rethrow(err, filename, lineno, str){
213 | if (!(err instanceof Error)) throw err;
214 | if ((typeof window != 'undefined' || !filename) && !str) {
215 | err.message += ' on line ' + lineno;
216 | throw err;
217 | }
218 | try {
219 | str = str || require('fs').readFileSync(filename, 'utf8')
220 | } catch (ex) {
221 | rethrow(err, null, lineno)
222 | }
223 | var context = 3
224 | , lines = str.split('\n')
225 | , start = Math.max(lineno - context, 0)
226 | , end = Math.min(lines.length, lineno + context);
227 |
228 | // Error context
229 | var context = lines.slice(start, end).map(function(line, i){
230 | var curr = i + start + 1;
231 | return (curr == lineno ? ' > ' : ' ')
232 | + curr
233 | + '| '
234 | + line;
235 | }).join('\n');
236 |
237 | // Alter exception message
238 | err.path = filename;
239 | err.message = (filename || 'Jade') + ':' + lineno
240 | + '\n' + context + '\n\n' + err.message;
241 | throw err;
242 | };
243 |
244 | exports.DebugItem = function DebugItem(lineno, filename) {
245 | this.lineno = lineno;
246 | this.filename = filename;
247 | }
248 |
249 | },{"fs":2}],2:[function(require,module,exports){
250 |
251 | },{}]},{},[1])(1)
252 | });
--------------------------------------------------------------------------------
/vendor/assets/javascripts/jade/sample_template.jade:
--------------------------------------------------------------------------------
1 | doctype html
2 | html(lang="en")
3 | head
4 | title= pageTitle
5 | script(type='text/javascript').
6 | if (foo) bar(1 + 5)
7 | body
8 | h1 Jade - node template engine
9 | #container.col
10 | if youAreUsingJade
11 | p You are amazing
12 | else
13 | p Get on it!
14 | p.
15 | Jade is a terse and simple templating language with a
16 | strong focus on performance and powerful features.
17 |
--------------------------------------------------------------------------------