pug-rails 1.11.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bec6dc4751e1b9c8b0fcdb64b5ac6a94fbfbadbb
4
+ data.tar.gz: 896eeaf9c013c17ec3b3375a9aba5c0b3fea6e3a
5
+ SHA512:
6
+ metadata.gz: ee658ef508ac1de359abf6495e76faf5ec25e373bc1130c28ccf81554e679984067f1760e42e60ef7803e114fb06284ff0fb9e12205aa0440679510bd279334b
7
+ data.tar.gz: ccc6f56d8a85f96845d82fed51b80dc9c4c3b967cdce2c7a5a5110049c548c91faff318a75755b1ad5de54a021374c3e4ddc0165e19f2ac759e779eb58d749fe
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.lock
3
+ .bundle
4
+ .ruby-version
5
+ pkg/
6
+ tmp/
7
+ /.idea/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem 'test-unit'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Ruby on Rails integration with Jade
2
+
3
+ ## How it works
4
+ This gem compiles Jade templates with [command line tool](http://jade-lang.com/command-line).
5
+
6
+ There are support of all basic features including advanced:
7
+ * [Jade includes](http://jade-lang.com/reference/includes)
8
+ * [Jade extends](http://jade-lang.com/reference/extends)
9
+ * [Jade inheritance](http://jade-lang.com/reference/inheritance)
10
+
11
+ Jade template can be alternatively compiled using [command line](http://jade-lang.com/command-line). This method is impemented in this fork.
12
+
13
+ ## Installing
14
+ Install Jade globally via npm:
15
+ ```bash
16
+ npm install -g jade
17
+ ```
18
+
19
+ Add to your Gemfile:
20
+ ```ruby
21
+ gem 'pug-rails', '~> 1.0'
22
+ ```
23
+
24
+ Require Jade runtime.js:
25
+ ```js
26
+ //= require jade/runtime
27
+ ```
28
+
29
+ ## Running Tests
30
+ ```bash
31
+ bundle exec rake test
32
+ ```
33
+
34
+ ## Versioning
35
+ Gem version always reflects the version of Jade it contains.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
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
data/lib/pug-rails.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'open3'
2
+ require 'tilt'
3
+ require 'json'
4
+ require 'pug/template'
5
+ require 'pug/railtie' if defined?(Rails)
6
+
7
+ module Pug
8
+ class << self
9
+ def compile(source, options = {})
10
+ source = source.read if source.respond_to?(:read)
11
+
12
+ # Command line arguments take precedence over json options in Jade binary
13
+ # @link https://github.com/jadejs/jade/blob/master/bin/jade.js
14
+ cmd = %w( jade )
15
+ cmd.push('--client')
16
+ cmd.push('--path', options[:filename]) if options[:filename]
17
+ cmd.push('--pretty') if options[:pretty]
18
+ cmd.push('--no-debug') unless options[:debug]
19
+ cmd.push('--obj', JSON.generate(options))
20
+
21
+ stdout, stderr, exit_status = Open3.capture3(*cmd, stdin_data: source)
22
+ raise CompileError.new(stderr) unless exit_status.success?
23
+ stdout
24
+ end
25
+ end
26
+
27
+ class CompileError < ::StandardError
28
+ end
29
+ end
30
+
@@ -0,0 +1,23 @@
1
+ module Pug
2
+ class Railtie < Rails::Engine
3
+ config.pug = ActiveSupport::OrderedOptions.new
4
+ config.pug.pretty = Rails.env.development?
5
+ config.pug.self = false
6
+ config.pug.compile_debug = Rails.env.development?
7
+ config.pug.globals = []
8
+ config.jade = config.pug
9
+
10
+ config.before_initialize do |app|
11
+ register_jade = -> (env = nil) {
12
+ (env || app.assets).register_engine '.jade', ::Pug::Template
13
+ (env || app.assets).register_engine '.pug', ::Pug::Template
14
+ }
15
+
16
+ if app.config.assets.respond_to?(:configure)
17
+ app.config.assets.configure { |env| register_jade.call(env) }
18
+ else
19
+ register_jade.call
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Pug
2
+ class Template < Tilt::Template
3
+ def prepare
4
+ end
5
+
6
+ def evaluate(context, locals, &block)
7
+ options = { }
8
+ options[:filename] = file
9
+ jade_config = Rails.application.config.pug.merge(options)
10
+ Pug.compile(data, jade_config)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Pug
2
+ VERSION = '1.11.0'
3
+ end
data/pug-rails.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../lib/pug/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'pug-rails'
5
+ s.version = Pug::VERSION
6
+ s.author = 'Yaroslav Konoplov'
7
+ s.email = 'yaroslav@inbox.com'
8
+ s.summary = 'Jade adapter for the Rails asset pipeline.'
9
+ s.description = 'Jade adapter for the Rails asset pipeline.'
10
+ s.homepage = 'https://github.com/yivo/pug-rails'
11
+ s.license = 'MIT'
12
+
13
+ s.executables = `git ls-files -z -- bin/*`.split("\x0").map{ |f| File.basename(f) }
14
+ s.files = `git ls-files -z`.split("\x0")
15
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_dependency 'tilt', '~> 2.0.0'
19
+ s.add_development_dependency 'bundler', '~> 1.7'
20
+ s.add_development_dependency 'rake', '~> 10.0'
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'pug-rails'
2
+ require 'test/unit'
3
+
4
+ class PugTest < Test::Unit::TestCase
5
+ DOCTYPE_PATTERN = /^\s*<!DOCTYPE html>/
6
+ PUG_TEMPLATE_FUNCTION_PATTERN = /^function\s+template\s*\(locals\)\s*\{.*\}$/m
7
+
8
+ def test_compile
9
+ template = File.read(File.expand_path('../assets/javascripts/pug/sample_template.jade', __FILE__))
10
+ result = Pug.compile(template)
11
+ assert_match(PUG_TEMPLATE_FUNCTION_PATTERN, result)
12
+ assert_no_match(DOCTYPE_PATTERN, result)
13
+ end
14
+
15
+ def test_compile_with_io
16
+ io = StringIO.new('lorem ipsum dolor')
17
+ assert_equal Pug.compile('lorem ipsum dolor'), Pug.compile(io)
18
+ end
19
+
20
+ def test_compilation_error
21
+ assert_raise Pug::CompileError do
22
+ Pug.compile <<-JADE
23
+ else
24
+ .foo
25
+ JADE
26
+ end
27
+ end
28
+
29
+ def test_includes
30
+ file = File.expand_path('../assets/javascripts/pug/includes/index.jade', __FILE__)
31
+ template = File.read(file)
32
+ result = Pug.compile(template, filename: file)
33
+ assert_match(PUG_TEMPLATE_FUNCTION_PATTERN, result)
34
+ assert_no_match(DOCTYPE_PATTERN, result)
35
+ end
36
+
37
+ def test_extends
38
+ file = File.expand_path('../assets/javascripts/pug/extends/layout.jade', __FILE__)
39
+ template = File.read(file)
40
+ result = Pug.compile(template, filename: file)
41
+ assert_match(PUG_TEMPLATE_FUNCTION_PATTERN, result)
42
+ assert_no_match(DOCTYPE_PATTERN, result)
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
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.
@@ -0,0 +1,252 @@
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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ 'use strict';
3
+
4
+ /**
5
+ * Merge two attribute objects giving precedence
6
+ * to values in object `b`. Classes are special-cased
7
+ * allowing for arrays and merging/joining appropriately
8
+ * resulting in a string.
9
+ *
10
+ * @param {Object} a
11
+ * @param {Object} b
12
+ * @return {Object} a
13
+ * @api private
14
+ */
15
+
16
+ exports.merge = function merge(a, b) {
17
+ if (arguments.length === 1) {
18
+ var attrs = a[0];
19
+ for (var i = 1; i < a.length; i++) {
20
+ attrs = merge(attrs, a[i]);
21
+ }
22
+ return attrs;
23
+ }
24
+ var ac = a['class'];
25
+ var bc = b['class'];
26
+
27
+ if (ac || bc) {
28
+ ac = ac || [];
29
+ bc = bc || [];
30
+ if (!Array.isArray(ac)) ac = [ac];
31
+ if (!Array.isArray(bc)) bc = [bc];
32
+ a['class'] = ac.concat(bc).filter(nulls);
33
+ }
34
+
35
+ for (var key in b) {
36
+ if (key != 'class') {
37
+ a[key] = b[key];
38
+ }
39
+ }
40
+
41
+ return a;
42
+ };
43
+
44
+ /**
45
+ * Filter null `val`s.
46
+ *
47
+ * @param {*} val
48
+ * @return {Boolean}
49
+ * @api private
50
+ */
51
+
52
+ function nulls(val) {
53
+ return val != null && val !== '';
54
+ }
55
+
56
+ /**
57
+ * join array as classes.
58
+ *
59
+ * @param {*} val
60
+ * @return {String}
61
+ */
62
+ exports.joinClasses = joinClasses;
63
+ function joinClasses(val) {
64
+ return (Array.isArray(val) ? val.map(joinClasses) :
65
+ (val && typeof val === 'object') ? Object.keys(val).filter(function (key) { return val[key]; }) :
66
+ [val]).filter(nulls).join(' ');
67
+ }
68
+
69
+ /**
70
+ * Render the given classes.
71
+ *
72
+ * @param {Array} classes
73
+ * @param {Array.<Boolean>} 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 `&amp;`');
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, '&apos;') + "'";
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
+ '&': '&amp;',
185
+ '<': '&lt;',
186
+ '>': '&gt;',
187
+ '"': '&quot;'
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
+ });
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pug-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.11.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tilt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Jade adapter for the Rails asset pipeline.
56
+ email: yaroslav@inbox.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - Gemfile
63
+ - LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/pug-rails.rb
67
+ - lib/pug/railtie.rb
68
+ - lib/pug/template.rb
69
+ - lib/pug/version.rb
70
+ - pug-rails.gemspec
71
+ - test/test-pug-rails.rb
72
+ - vendor/assets/javascripts/pug/LICENCE
73
+ - vendor/assets/javascripts/pug/runtime.js
74
+ homepage: https://github.com/yivo/pug-rails
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Jade adapter for the Rails asset pipeline.
98
+ test_files:
99
+ - test/test-pug-rails.rb