pug-rails 1.11.0.1 → 2.0.0

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: 63088a476cff59fa064af8d4ca1604dc599229f0
4
- data.tar.gz: beaff63ef17bf550e20b7c4e059e817beb674b6c
3
+ metadata.gz: c04d4c84bdfca755cf44cc37c81eb46a36f6102d
4
+ data.tar.gz: 3b3618108557ec5e16cc4c1d271b7ecb3d9d9599
5
5
  SHA512:
6
- metadata.gz: d98ab8f6b374ce43225876e23ea00c4b3750e6f4f429f5176daba5ec19e701b96c56b9a3da0ca3110c471c026fdf25955f172aede015648c92cf474adf485ee8
7
- data.tar.gz: 07c4177ac4daf1caa6706b07f0f531aa9a8ded036e88e4b1e4fd1bbff9b53e6f15db6fe38a6aa3a5364819b6e2ea73f75ba0979d19b89b19f9f75309b3a03913
6
+ metadata.gz: dbeea34052c2ed42dd37c3be5a3084ae06f3c9bdcce80d711b844bb7451673d68e5b8467617b60f749195ce4b180d0a6aa703fdd07e43c9571f4400780bdd273
7
+ data.tar.gz: b06a30e6b8d851a46332f75a483697465ed68456348690b20f77b583f89ffcce0cf5fa1f815751229dea4ebc7275bcbc02c6c31dd4ff569be50d030e23e48eb5
data/README.md CHANGED
@@ -1,35 +1,65 @@
1
- # Ruby on Rails integration with Pug (ex. Jade)
1
+ ## Pug/Jade template engine integration with Rails asset pipeline
2
2
 
3
- ## How it works
4
- This gem compiles Jade templates with [command line tool](http://jade-lang.com/command-line).
3
+ ## About
4
+ This gem uses [pug-ruby](https://github.com/yivo/pug-ruby) to compile Pug/Jade templates. Please refer to that gem if you want to use Pug/Jade compiler directly.
5
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)
6
+ ## Installing gem
7
+ Add to your Gemfile:
8
+ ```ruby
9
+ gem 'pug-rails', '~> 2.0'
10
+ ```
10
11
 
11
- Jade template can be alternatively compiled using [command line](http://jade-lang.com/command-line). This method is impemented in this fork.
12
+ ## Installing Jade
13
+ Install Jade globally via npm:
14
+ ```bash
15
+ npm install -g jade
16
+ ```
12
17
 
13
- ## Installing
18
+ Require Jade runtime.js:
19
+ ```js
20
+ //= require jade/runtime
21
+ ```
22
+
23
+ Use `.jst.jade` as extension of your Jade files.
24
+
25
+ ## Installing Pug
14
26
  Install Pug globally via npm:
15
27
  ```bash
16
28
  npm install -g pug-cli
17
29
  ```
18
30
 
19
- Add to your Gemfile:
20
- ```ruby
21
- gem 'pug-rails', '~> 1.0'
22
- ```
23
-
24
31
  Require Pug runtime.js:
25
32
  ```js
26
33
  //= require pug/runtime
27
34
  ```
35
+ NOTE: You don't need to do this if you are inlining Pug runtime functions in template. Please read about `inlineRuntimeFunctions` option at official website — [pugjs.org](http://pugjs.org).
28
36
 
29
- ## Running Tests
30
- ```bash
31
- bundle exec rake test
37
+ Use `.jst.pug` as extension of your Pug files.
38
+
39
+ ## Configuring Pug and Jade
40
+ Access Pug and Jade configurations directly:
41
+ ```ruby
42
+ Jade.config.compile_debug = false
43
+ Pug.config.compile_debug = false
44
+ ```
45
+
46
+ Access Pug and Jade configurations through `Rails.application.config`:
47
+ ```ruby
48
+ Rails.application.config.jade.compile_debug = false
49
+ Rails.application.config.pug.compile_debug = false
50
+ ```
51
+
52
+ ## Configuring asset lookup paths
53
+ It doesn't matter where to put Pug/Jade files but don't forget to update asset lookup paths.
54
+ Personally I prefer to put templates in `app/assets/templates`:
55
+ ```ruby
56
+ # Add app/assets/templates to asset lookup paths
57
+ # Add this to your initializers or application.rb
58
+ Rails.application.config.assets.paths << Rails.root.join('app/assets/templates')
32
59
  ```
33
60
 
61
+ ## Running Tests
62
+ Refer to [pug-ruby](https://github.com/yivo/pug-ruby)
63
+
34
64
  ## Versioning
35
- Gem version always reflects the version of Pug it contains.
65
+ Prior to version 2.0 version of the gem was the same as the version of the Jade runtime that it contains.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Jade
3
+ class Railtie < Rails::Engine
4
+ config.jade = Jade.config
5
+ config.jade.pretty = Rails.env.development?
6
+ config.jade.compile_debug = Rails.env.development?
7
+
8
+ config.before_initialize do |app|
9
+ register_template = -> (env) { (env || app.assets).register_engine('.jade', Jade::Template) }
10
+ if app.config.assets.respond_to?(:configure)
11
+ app.config.assets.configure { |env| register_template.call(env) }
12
+ else
13
+ register_template.call(nil)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'tilt'
3
+ module Jade
4
+ class Template < Tilt::Template
5
+ def prepare
6
+ end
7
+
8
+ def evaluate(context, locals, &block)
9
+ Jade.compile(data, filename: file, client: true)
10
+ end
11
+ end
12
+ end
data/lib/pug-rails.rb CHANGED
@@ -1,40 +1,21 @@
1
1
  # frozen_string_literal: true
2
- require 'open3'
3
- require 'tilt'
4
- require 'json'
5
2
 
6
- module Pug
3
+ module Jade
7
4
  class << self
8
- def compile(source, options = {})
9
- source = source.read if source.respond_to?(:read)
10
-
11
- # Command line arguments take precedence over json options in Jade binary
12
- # @link https://github.com/jadejs/jade/blob/master/bin/jade.js
13
- # @link https://github.com/pugjs/pug-cli/blob/master/index.js
14
- cmd = [ options.fetch(:executable) ]
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
-
26
- def find_executable
27
- %w( pug jade ).find do |name|
28
- `which #{name}`
29
- $?.success?
30
- end
31
- end
5
+ attr_accessor :runtime_version
32
6
  end
7
+ end
33
8
 
34
- class CompileError < ::StandardError
9
+ module Pug
10
+ class << self
11
+ attr_accessor :runtime_version
35
12
  end
36
13
  end
37
14
 
38
- require 'pug/template'
39
- require 'pug/railtie' if defined?(Rails)
15
+ Jade.runtime_version = '1.11.0'
16
+ Pug.runtime_version = '2.0.2'
40
17
 
18
+ require 'pug-rails/template'
19
+ require 'pug-rails/railtie'
20
+ require 'jade-rails/template'
21
+ require 'jade-rails/railtie'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Pug
3
+ class Railtie < Rails::Engine
4
+ config.pug = Pug.config
5
+ config.pug.pretty = Rails.env.development?
6
+ config.pug.compile_debug = Rails.env.development?
7
+
8
+ config.before_initialize do |app|
9
+ register_template = -> (env) { (env || app.assets).register_engine('.pug', Pug::Template) }
10
+ if app.config.assets.respond_to?(:configure)
11
+ app.config.assets.configure { |env| register_template.call(env) }
12
+ else
13
+ register_template.call(nil)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
+ require 'tilt'
2
3
  module Pug
3
4
  class Template < Tilt::Template
4
5
  def prepare
5
6
  end
6
7
 
7
8
  def evaluate(context, locals, &block)
8
- jade_config = Rails.application.config.pug.merge(filename: file)
9
- Pug.compile(data, jade_config)
9
+ Pug.compile(data, filename: file, client: true)
10
10
  end
11
11
  end
12
12
  end
data/pug-rails.gemspec CHANGED
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
- require File.expand_path('../lib/pug/version', __FILE__)
3
-
4
2
  Gem::Specification.new do |s|
5
3
  s.name = 'pug-rails'
6
- s.version = Pug::VERSION
4
+ s.version = '2.0.0'
7
5
  s.author = 'Yaroslav Konoplov'
8
- s.email = 'yaroslav@inbox.com'
9
- s.summary = 'Jade adapter for the Rails asset pipeline.'
10
- s.description = 'Jade adapter for the Rails asset pipeline.'
6
+ s.email = 'eahome00@gmail.com'
7
+ s.summary = 'Pug/Jade template engine integration with Rails asset pipeline.'
8
+ s.description = 'Pug/Jade template engine integration with Rails asset pipeline.'
11
9
  s.homepage = 'https://github.com/yivo/pug-rails'
12
10
  s.license = 'MIT'
13
11
 
@@ -16,7 +14,6 @@ Gem::Specification.new do |s|
16
14
  s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
17
15
  s.require_paths = ['lib']
18
16
 
19
- s.add_dependency 'tilt', '~> 2.0.0'
20
- s.add_development_dependency 'bundler', '~> 1.7'
21
- s.add_development_dependency 'rake', '~> 10.0'
17
+ s.add_dependency 'pug-ruby', '~> 1.0'
18
+ s.add_dependency 'tilt', '~> 2.0'
22
19
  end
@@ -249,4 +249,4 @@ exports.DebugItem = function DebugItem(lineno, filename) {
249
249
  },{"fs":2}],2:[function(require,module,exports){
250
250
 
251
251
  },{}]},{},[1])(1)
252
- });
252
+ });
@@ -1,22 +1,19 @@
1
- (The MIT License)
1
+ Copyright (c) 2014 Forbes Lindesay
2
2
 
3
- Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
4
9
 
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:
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
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.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -1,6 +1,8 @@
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){
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.pug = 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
2
  'use strict';
3
3
 
4
+ var pug_has_own_property = Object.prototype.hasOwnProperty;
5
+
4
6
  /**
5
7
  * Merge two attribute objects giving precedence
6
8
  * to values in object `b`. Classes are special-cased
@@ -13,27 +15,25 @@
13
15
  * @api private
14
16
  */
15
17
 
16
- exports.merge = function merge(a, b) {
18
+ exports.merge = pug_merge;
19
+ function pug_merge(a, b) {
17
20
  if (arguments.length === 1) {
18
21
  var attrs = a[0];
19
22
  for (var i = 1; i < a.length; i++) {
20
- attrs = merge(attrs, a[i]);
23
+ attrs = pug_merge(attrs, a[i]);
21
24
  }
22
25
  return attrs;
23
26
  }
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
27
 
35
28
  for (var key in b) {
36
- if (key != 'class') {
29
+ if (key === 'class') {
30
+ var valA = a[key] || [];
31
+ a[key] = (Array.isArray(valA) ? valA : [valA]).concat(b[key] || []);
32
+ } else if (key === 'style') {
33
+ var valA = pug_style(a[key]);
34
+ var valB = pug_style(b[key]);
35
+ a[key] = valA + (valA && valB && ';') + valB;
36
+ } else {
37
37
  a[key] = b[key];
38
38
  }
39
39
  }
@@ -42,64 +42,81 @@ exports.merge = function merge(a, b) {
42
42
  };
43
43
 
44
44
  /**
45
- * Filter null `val`s.
45
+ * Process array, object, or string as a string of classes delimited by a space.
46
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.
47
+ * If `val` is an array, all members of it and its subarrays are counted as
48
+ * classes. If `escaping` is an array, then whether or not the item in `val` is
49
+ * escaped depends on the corresponding item in `escaping`. If `escaping` is
50
+ * not an array, no escaping is done.
58
51
  *
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.
52
+ * If `val` is an object, all the keys whose value is truthy are counted as
53
+ * classes. No escaping is done.
54
+ *
55
+ * If `val` is a string, it is counted as a class. No escaping is done.
71
56
  *
72
- * @param {Array} classes
73
- * @param {Array.<Boolean>} escaped
57
+ * @param {(Array.<string>|Object.<string, boolean>|string)} val
58
+ * @param {?Array.<string>} escaping
74
59
  * @return {String}
75
60
  */
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]));
61
+ exports.classes = pug_classes;
62
+ function pug_classes_array(val, escaping) {
63
+ var classString = '', className, padding = '', escapeEnabled = Array.isArray(escaping);
64
+ for (var i = 0; i < val.length; i++) {
65
+ className = pug_classes(val[i]);
66
+ if (!className) continue;
67
+ escapeEnabled && escaping[i] && (className = pug_escape(className));
68
+ classString = classString + padding + className;
69
+ padding = ' ';
70
+ }
71
+ return classString;
72
+ }
73
+ function pug_classes_object(val) {
74
+ var classString = '', padding = '';
75
+ for (var key in val) {
76
+ if (key && val[key] && pug_has_own_property.call(val, key)) {
77
+ classString = classString + padding + key;
78
+ padding = ' ';
83
79
  }
84
80
  }
85
- var text = joinClasses(buf);
86
- if (text.length) {
87
- return ' class="' + text + '"';
81
+ return classString;
82
+ }
83
+ function pug_classes(val, escaping) {
84
+ if (Array.isArray(val)) {
85
+ return pug_classes_array(val, escaping);
86
+ } else if (val && typeof val === 'object') {
87
+ return pug_classes_object(val);
88
88
  } else {
89
- return '';
89
+ return val || '';
90
90
  }
91
- };
91
+ }
92
92
 
93
+ /**
94
+ * Convert object or string to a string of CSS styles delimited by a semicolon.
95
+ *
96
+ * @param {(Object.<string, string>|string)} val
97
+ * @return {String}
98
+ */
93
99
 
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(';');
100
+ exports.style = pug_style;
101
+ function pug_style(val) {
102
+ if (!val) return '';
103
+ if (typeof val === 'object') {
104
+ var out = '', delim = '';
105
+ for (var style in val) {
106
+ /* istanbul ignore else */
107
+ if (pug_has_own_property.call(val, style)) {
108
+ out = out + delim + style + ':' + val[style];
109
+ delim = ';';
110
+ }
111
+ }
112
+ return out;
99
113
  } else {
114
+ val = '' + val;
115
+ if (val[val.length - 1] === ';') return val.slice(0, -1);
100
116
  return val;
101
117
  }
102
118
  };
119
+
103
120
  /**
104
121
  * Render the given attribute.
105
122
  *
@@ -109,67 +126,55 @@ exports.style = function (val) {
109
126
  * @param {Boolean} terse
110
127
  * @return {String}
111
128
  */
112
- exports.attr = function attr(key, val, escaped, terse) {
113
- if (key === 'style') {
114
- val = exports.style(val);
129
+ exports.attr = pug_attr;
130
+ function pug_attr(key, val, escaped, terse) {
131
+ if (val === false || val == null || !val && (key === 'class' || key === 'style')) {
132
+ return '';
115
133
  }
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');
134
+ if (val === true) {
135
+ return ' ' + (terse ? key : key + '="' + key + '"');
136
+ }
137
+ if (typeof val.toJSON === 'function') {
138
+ val = val.toJSON();
139
+ }
140
+ if (typeof val !== 'string') {
141
+ val = JSON.stringify(val);
142
+ if (!escaped && val.indexOf('"') !== -1) {
143
+ return ' ' + key + '=\'' + val.replace(/'/g, '&#39;') + '\'';
140
144
  }
141
- return ' ' + key + '="' + val + '"';
142
145
  }
146
+ if (escaped) val = pug_escape(val);
147
+ return ' ' + key + '="' + val + '"';
143
148
  };
144
149
 
145
150
  /**
146
151
  * Render the given attributes object.
147
152
  *
148
153
  * @param {Object} obj
149
- * @param {Object} escaped
154
+ * @param {Object} terse whether to use HTML5 terse boolean attributes
150
155
  * @return {String}
151
156
  */
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));
157
+ exports.attrs = pug_attrs;
158
+ function pug_attrs(obj, terse){
159
+ var attrs = '';
160
+
161
+ for (var key in obj) {
162
+ if (pug_has_own_property.call(obj, key)) {
163
+ var val = obj[key];
164
+
165
+ if ('class' === key) {
166
+ val = pug_classes(val);
167
+ attrs = pug_attr(key, val, false, terse) + attrs;
168
+ continue;
168
169
  }
170
+ if ('style' === key) {
171
+ val = pug_style(val);
172
+ }
173
+ attrs += pug_attr(key, val, false, terse);
169
174
  }
170
175
  }
171
176
 
172
- return buf.join('');
177
+ return attrs;
173
178
  };
174
179
 
175
180
  /**
@@ -180,36 +185,44 @@ exports.attrs = function attrs(obj, terse){
180
185
  * @api private
181
186
  */
182
187
 
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
- }
188
+ var pug_match_html = /["&<>]/;
189
+ exports.escape = pug_escape;
190
+ function pug_escape(_html){
191
+ var html = '' + _html;
192
+ var regexResult = pug_match_html.exec(html);
193
+ if (!regexResult) return _html;
194
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;
195
+ var result = '';
196
+ var i, lastIndex, escape;
197
+ for (i = regexResult.index, lastIndex = 0; i < html.length; i++) {
198
+ switch (html.charCodeAt(i)) {
199
+ case 34: escape = '&quot;'; break;
200
+ case 38: escape = '&amp;'; break;
201
+ case 60: escape = '&lt;'; break;
202
+ case 62: escape = '&gt;'; break;
203
+ default: continue;
204
+ }
205
+ if (lastIndex !== i) result += html.substring(lastIndex, i);
206
+ lastIndex = i + 1;
207
+ result += escape;
208
+ }
209
+ if (lastIndex !== i) return result + html.substring(lastIndex, i);
199
210
  else return result;
200
211
  };
201
212
 
202
213
  /**
203
214
  * Re-throw the given `err` in context to the
204
- * the jade in `filename` at the given `lineno`.
215
+ * the pug in `filename` at the given `lineno`.
205
216
  *
206
217
  * @param {Error} err
207
218
  * @param {String} filename
208
219
  * @param {String} lineno
220
+ * @param {String} str original source
209
221
  * @api private
210
222
  */
211
223
 
212
- exports.rethrow = function rethrow(err, filename, lineno, str){
224
+ exports.rethrow = pug_rethrow;
225
+ function pug_rethrow(err, filename, lineno, str){
213
226
  if (!(err instanceof Error)) throw err;
214
227
  if ((typeof window != 'undefined' || !filename) && !str) {
215
228
  err.message += ' on line ' + lineno;
@@ -218,7 +231,7 @@ exports.rethrow = function rethrow(err, filename, lineno, str){
218
231
  try {
219
232
  str = str || require('fs').readFileSync(filename, 'utf8')
220
233
  } catch (ex) {
221
- rethrow(err, null, lineno)
234
+ pug_rethrow(err, null, lineno)
222
235
  }
223
236
  var context = 3
224
237
  , lines = str.split('\n')
@@ -236,17 +249,11 @@ exports.rethrow = function rethrow(err, filename, lineno, str){
236
249
 
237
250
  // Alter exception message
238
251
  err.path = filename;
239
- err.message = (filename || 'Jade') + ':' + lineno
252
+ err.message = (filename || 'Pug') + ':' + lineno
240
253
  + '\n' + context + '\n\n' + err.message;
241
254
  throw err;
242
255
  };
243
-
244
- exports.DebugItem = function DebugItem(lineno, filename) {
245
- this.lineno = lineno;
246
- this.filename = filename;
247
- }
248
-
249
256
  },{"fs":2}],2:[function(require,module,exports){
250
257
 
251
258
  },{}]},{},[1])(1)
252
- });
259
+ });
metadata CHANGED
@@ -1,79 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pug-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Konoplov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-01 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: tilt
14
+ name: pug-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: '1.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
- version: 2.0.0
26
+ version: '1.0'
27
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
28
+ name: tilt
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
33
+ version: '2.0'
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '10.0'
55
- description: Jade adapter for the Rails asset pipeline.
56
- email: yaroslav@inbox.com
40
+ version: '2.0'
41
+ description: Pug/Jade template engine integration with Rails asset pipeline.
42
+ email: eahome00@gmail.com
57
43
  executables: []
58
44
  extensions: []
59
45
  extra_rdoc_files: []
60
46
  files:
61
47
  - ".gitignore"
62
- - Gemfile
63
48
  - README.md
64
- - Rakefile
49
+ - lib/jade-rails/railtie.rb
50
+ - lib/jade-rails/template.rb
65
51
  - lib/pug-rails.rb
66
- - lib/pug/railtie.rb
67
- - lib/pug/template.rb
68
- - lib/pug/version.rb
52
+ - lib/pug-rails/railtie.rb
53
+ - lib/pug-rails/template.rb
69
54
  - pug-rails.gemspec
70
- - test/assets/javascripts/pug/extends/index.jade
71
- - test/assets/javascripts/pug/extends/layout.jade
72
- - test/assets/javascripts/pug/includes/includes/foot.jade
73
- - test/assets/javascripts/pug/includes/includes/head.jade
74
- - test/assets/javascripts/pug/includes/index.jade
75
- - test/assets/javascripts/pug/sample_template.jade
76
- - test/test-pug-rails.rb
77
55
  - vendor/assets/javascripts/jade/LICENCE
78
56
  - vendor/assets/javascripts/jade/runtime.js
79
57
  - vendor/assets/javascripts/pug/LICENCE
@@ -101,12 +79,5 @@ rubyforge_project:
101
79
  rubygems_version: 2.5.1
102
80
  signing_key:
103
81
  specification_version: 4
104
- summary: Jade adapter for the Rails asset pipeline.
105
- test_files:
106
- - test/assets/javascripts/pug/extends/index.jade
107
- - test/assets/javascripts/pug/extends/layout.jade
108
- - test/assets/javascripts/pug/includes/includes/foot.jade
109
- - test/assets/javascripts/pug/includes/includes/head.jade
110
- - test/assets/javascripts/pug/includes/index.jade
111
- - test/assets/javascripts/pug/sample_template.jade
112
- - test/test-pug-rails.rb
82
+ summary: Pug/Jade template engine integration with Rails asset pipeline.
83
+ test_files: []
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
- gem 'test-unit'
data/Rakefile DELETED
@@ -1,9 +0,0 @@
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/railtie.rb DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
- module Pug
3
- class Railtie < Rails::Engine
4
- config.pug = ActiveSupport::OrderedOptions.new
5
- config.pug.executable = Pug.find_executable
6
- config.pug.pretty = Rails.env.development?
7
- config.pug.self = false
8
- config.pug.compile_debug = Rails.env.development?
9
- config.pug.globals = []
10
- config.jade = config.pug
11
-
12
- config.before_initialize do |app|
13
- register_jade = -> (env = nil) {
14
- (env || app.assets).register_engine '.jade', ::Pug::Template
15
- (env || app.assets).register_engine '.pug', ::Pug::Template
16
- }
17
-
18
- if app.config.assets.respond_to?(:configure)
19
- app.config.assets.configure { |env| register_jade.call(env) }
20
- else
21
- register_jade.call
22
- end
23
- end
24
- end
25
- end
data/lib/pug/version.rb DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
- module Pug
3
- VERSION = '1.11.0.1'
4
- end
@@ -1,8 +0,0 @@
1
- //- index.jade
2
- extends ./layout.jade
3
-
4
- block title
5
- title Article Title
6
-
7
- block content
8
- h1 My Article
@@ -1,8 +0,0 @@
1
- //- layout.jade
2
- doctype html
3
- html
4
- head
5
- block title
6
- title Default title
7
- body
8
- block content
@@ -1,3 +0,0 @@
1
- //- includes/foot.jade
2
- #footer
3
- p Copyright (c) foobar
@@ -1,5 +0,0 @@
1
- //- includes/head.jade
2
- head
3
- title My Site
4
- script(src='/javascripts/jquery.js')
5
- script(src='/javascripts/app.js')
@@ -1,8 +0,0 @@
1
- //- index.jade
2
- doctype html
3
- html
4
- include ./includes/head.jade
5
- body
6
- h1 My Site
7
- p Welcome to my super lame site.
8
- include ./includes/foot.jade
@@ -1,16 +0,0 @@
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.
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'pug-rails'
3
- require 'test/unit'
4
-
5
- class PugTest < Test::Unit::TestCase
6
- DOCTYPE_PATTERN = /^\s*<!DOCTYPE html>/
7
- PUG_TEMPLATE_FUNCTION_PATTERN = /^function\s+template\s*\(locals\)\s*\{.*\}$/m
8
-
9
- def test_compile
10
- template = File.read(File.expand_path('../assets/javascripts/pug/sample_template.jade', __FILE__))
11
- result = Pug.compile(template)
12
- assert_match(PUG_TEMPLATE_FUNCTION_PATTERN, result)
13
- assert_no_match(DOCTYPE_PATTERN, result)
14
- end
15
-
16
- def test_compile_with_io
17
- io = StringIO.new('lorem ipsum dolor')
18
- assert_equal Pug.compile('lorem ipsum dolor'), Pug.compile(io)
19
- end
20
-
21
- def test_compilation_error
22
- assert_raise Pug::CompileError do
23
- Pug.compile <<-JADE
24
- else
25
- .foo
26
- JADE
27
- end
28
- end
29
-
30
- def test_includes
31
- file = File.expand_path('../assets/javascripts/pug/includes/index.jade', __FILE__)
32
- template = File.read(file)
33
- result = Pug.compile(template, filename: file)
34
- assert_match(PUG_TEMPLATE_FUNCTION_PATTERN, result)
35
- assert_no_match(DOCTYPE_PATTERN, result)
36
- end
37
-
38
- def test_extends
39
- file = File.expand_path('../assets/javascripts/pug/extends/layout.jade', __FILE__)
40
- template = File.read(file)
41
- result = Pug.compile(template, filename: file)
42
- assert_match(PUG_TEMPLATE_FUNCTION_PATTERN, result)
43
- assert_no_match(DOCTYPE_PATTERN, result)
44
- end
45
- end