skim 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/.travis.yml +2 -1
- data/History.md +9 -0
- data/LICENSE +2 -2
- data/README.md +48 -12
- data/bin/skim +6 -0
- data/lib/skim/command.rb +141 -0
- data/lib/skim/engine.rb +0 -1
- data/lib/skim/sprockets.rb +10 -1
- data/lib/skim/template.rb +9 -1
- data/lib/skim/version.rb +1 -1
- data/skim.gemspec +9 -8
- data/test/test_code_blocks.rb +18 -1
- data/test/test_commands.rb +203 -0
- metadata +20 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be0b29f6955ce76137070ba09b3472195a065c2d773aee16e29c0876cb167d46
|
4
|
+
data.tar.gz: 708c7d0a475fdfdebb68aea3736aa8c71ad0defdeaa05cf63fe350095cb84e42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22f31e4516bc4742782dac10a29799105855c3d02e4ef92e8b05cb7c6ec4240e5d09798ecb13d635b7812896eba856b49d70ac3c040f9ab6f51c2b33492104e8
|
7
|
+
data.tar.gz: 13697db4450022d4195a9093827b6d160893c90c688cfd5c30a003604e4b415dece32cf94d7595e9496d9d839bcb96510a13f1c452c809469f963381b5c14217
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/.travis.yml
CHANGED
data/History.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# 0.11.0
|
4
|
+
|
5
|
+
* Add skim command-line interface
|
6
|
+
* Compatibility with Rails 6 and Sprockets 4
|
7
|
+
* Fix "Syntax Error: Unexpected &" bug (#48) -- thanks to @pavelkomiagin!
|
8
|
+
* Update README with CLI documentation and new copyright notice
|
9
|
+
* Update LICENSE for new maintainership
|
10
|
+
* Upgrade Travis infrastructure
|
11
|
+
|
3
12
|
# 0.10.0
|
4
13
|
|
5
14
|
* Compatibility with Rails 4.2, Slim 3, and Sprockets 3
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 John Firebaugh
|
1
|
+
Copyright (c) 2012 John Firebaugh, (c) 2015 AppJudo Inc.
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
Skim [ ![Build status](https://travis-ci.org/
|
1
|
+
Skim [ ![Build status](https://travis-ci.org/appjudo/skim.png) ](https://travis-ci.org/appjudo/skim)
|
2
2
|
====
|
3
3
|
|
4
4
|
Take the fat out of your client-side templates with Skim. Skim is the [Slim](http://slim-lang.com/) templating engine
|
5
5
|
with embedded CoffeeScript. It compiles to JavaScript templates (`.jst`), which can then be served by Rails or any other
|
6
6
|
Sprockets-based asset pipeline.
|
7
7
|
|
8
|
+
# Install
|
9
|
+
|
10
|
+
`gem install skim`, or add `skim` to your `Gemfile`.
|
11
|
+
|
8
12
|
# Usage
|
9
13
|
|
10
|
-
|
14
|
+
Create template files with the extension
|
11
15
|
`.jst.skim`. For example, `test.jst.skim`:
|
12
16
|
|
13
17
|
```jade
|
@@ -20,16 +24,38 @@ In your JavaScript or CoffeeScript, render the result, passing a context object:
|
|
20
24
|
$("body").html(JST["test"]({world: "World"}));
|
21
25
|
```
|
22
26
|
|
23
|
-
|
27
|
+
## Command Line Interface
|
28
|
+
|
29
|
+
The CLI allows Skim to be used in Gulp and Grunt workflows, extending the reach of Skim from the Ruby world into the JS/ES/CoffeeScript communities.
|
30
|
+
|
31
|
+
Features:
|
32
|
+
- Options to output Skim asset and templates separately.
|
33
|
+
- Options to assign template function to `module.exports`, a global function variable, or a global object (keyed by filename, as Sprockets does with its `JST` object).
|
34
|
+
|
35
|
+
Usage: `skim [options]`
|
36
|
+
|
37
|
+
```
|
38
|
+
-s, --stdin Read input from standard input instead of an input file
|
39
|
+
-e, --export Assign to module.exports for CommonJS require
|
40
|
+
-n, --node-global Use Node.js global object for global assignments
|
41
|
+
--jst Assign to global JST object keyed by truncated filename
|
42
|
+
--assign variableName Assign to a global variable
|
43
|
+
--assign-object objectName Assign to a global object keyed by truncated filename
|
44
|
+
--asset-only Output only the Skim preamble asset
|
45
|
+
--omit-asset Omit Skim preamble asset from output
|
46
|
+
--trace Show a full traceback on error
|
47
|
+
-o, --option name=code Set skim option
|
48
|
+
-r, --require library Load library or plugin
|
49
|
+
-h, --help Show this help message
|
50
|
+
-v, --version Print version number
|
51
|
+
```
|
24
52
|
|
25
53
|
# Caveats
|
26
54
|
|
27
55
|
Skim is an early proof-of-concept. Some Slim features are still missing:
|
28
56
|
|
29
|
-
* Skim does not currently support embedded engines. Being a client-side templating languages, it will only be able to
|
30
|
-
|
31
|
-
* Skim does not currently support HTML pretty-printing (Slim's `:pretty` option). This is low priority, as
|
32
|
-
pretty-printing is even less important client-side than server-side.
|
57
|
+
* Skim does not currently support embedded engines. Being a client-side templating languages, it will only be able to support embedded engines with a client-side implementation.
|
58
|
+
* Skim does not currently support HTML pretty-printing (Slim's `:pretty` option). This is low priority, as pretty-printing is even less important client-side than server-side.
|
33
59
|
* Skim does not currently support backslash line continuations.
|
34
60
|
|
35
61
|
# Language reference
|
@@ -53,16 +79,17 @@ string.
|
|
53
79
|
* You will typically want to use the fat arrow `=>` function definition to create callbacks, to preserve the binding of
|
54
80
|
`this` analogously to how `self` behaves in a Ruby block.
|
55
81
|
|
56
|
-
## The
|
82
|
+
## The Context Object
|
57
83
|
|
58
84
|
The context object you pass to the compiled template function becomes the value of this inside your template. You can
|
59
85
|
use CoffeeScript's `@` sigil to easily access properties and call helper methods on the context object.
|
60
86
|
|
61
|
-
## Escaping and
|
87
|
+
## Escaping and Unescaping
|
62
88
|
|
63
89
|
Like Slim, Skim escapes dynamic output by default, and it supports the same `==` and `#{{}}` syntaxes for bypassing
|
64
90
|
escaping. In addition, the special `safe` method on the context object tells Skim that the string can be output without
|
65
91
|
being escaped. You can use this in conjunction with `escape` context method to selectively sanitize parts of the string.
|
92
|
+
|
66
93
|
For example, given the template:
|
67
94
|
|
68
95
|
```jade
|
@@ -86,7 +113,7 @@ to produce:
|
|
86
113
|
<a href='/projects/4'>Crate & Barrel</a>
|
87
114
|
```
|
88
115
|
|
89
|
-
## The Skim
|
116
|
+
## The Skim Asset
|
90
117
|
|
91
118
|
By default, all you need to do to start using Skim is add it to your Gemfile. Skim will embed a small amount of
|
92
119
|
supporting code in each generated template asset. You can remove this duplication by manually including Skim's asset,
|
@@ -104,9 +131,17 @@ And the following in an initializer:
|
|
104
131
|
Skim::Engine.default_options[:use_asset] = true
|
105
132
|
```
|
106
133
|
|
134
|
+
Skim templates also support dependency injection for the Skim asset, instead of using a global Skim variable. Example in Node.js:
|
135
|
+
|
136
|
+
```js
|
137
|
+
var Skim = require('./skim_asset_module.js')
|
138
|
+
var template = require('./template_module.js');
|
139
|
+
console.log(template({Skim: Skim, first_name: 'Dave', last_name: 'Smith'}));
|
140
|
+
```
|
141
|
+
|
107
142
|
# License (MIT)
|
108
143
|
|
109
|
-
Copyright (c) 2012 John Firebaugh
|
144
|
+
Copyright (c) 2012 John Firebaugh, (c) 2015 AppJudo Inc.
|
110
145
|
|
111
146
|
Permission is hereby granted, free of charge, to any person obtaining
|
112
147
|
a copy of this software and associated documentation files (the
|
@@ -129,6 +164,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
129
164
|
|
130
165
|
# Special Thanks
|
131
166
|
|
167
|
+
* John Firebaugh, for creating Skim
|
132
168
|
* Andrew Stone, for Slim
|
133
169
|
* Magnus Holm, for Temple
|
134
|
-
* Daniel Mendler, for maintenance of
|
170
|
+
* Daniel Mendler, for maintenance of Slim and Temple
|
data/bin/skim
ADDED
data/lib/skim/command.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'skim'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Skim
|
5
|
+
class Command
|
6
|
+
def initialize(args)
|
7
|
+
@args = args
|
8
|
+
@options = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Run command
|
12
|
+
def run
|
13
|
+
@opts = OptionParser.new(&method(:set_opts))
|
14
|
+
@opts.parse!(@args)
|
15
|
+
process
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# Configure OptionParser
|
21
|
+
def set_opts(opts)
|
22
|
+
opts.on('-s', '--stdin', 'Read input from standard input instead of an input file') do
|
23
|
+
@input = $stdin
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-e', '--export', 'Assign to module.exports for CommonJS require') do
|
27
|
+
@export = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-n', '--node-global', 'Use Node.js global object for global assignments') do
|
31
|
+
@node_global = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('--jst', 'Assign to global JST object keyed by truncated filename') do
|
35
|
+
@assign_object_name = 'JST'
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('--assign variableName', 'Assign to a global variable') do |str|
|
39
|
+
@assign_variable_name = str
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('--assign-object objectName', 'Assign to a global object keyed by truncated filename') do |str|
|
43
|
+
@assign_object_name = str
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('--asset-only', 'Output only the Skim preamble asset') do
|
47
|
+
@asset_only = true
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on('--omit-asset', 'Omit Skim preamble asset from output') do
|
51
|
+
@options[:use_asset] = true
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on('--trace', 'Show a full traceback on error') do
|
55
|
+
@trace = true
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on('-o', '--option name=code', String, 'Set skim option') do |str|
|
59
|
+
parts = str.split('=', 2)
|
60
|
+
Engine.options[parts.first.gsub(/\A:/, '').to_sym] = eval(parts.last)
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on('-r', '--require library', "Load library or plugin") do |lib|
|
64
|
+
require lib.strip
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on_tail('-h', '--help', 'Show this help message') do
|
68
|
+
puts opts
|
69
|
+
exit
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on_tail('-v', '--version', 'Print version number') do
|
73
|
+
puts "Skim #{VERSION}"
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Process command
|
79
|
+
def process
|
80
|
+
args = @args.dup
|
81
|
+
result = if @asset_only
|
82
|
+
CoffeeScript.compile(Skim::Template.skim_src)
|
83
|
+
else
|
84
|
+
unless @input
|
85
|
+
filename = args.shift
|
86
|
+
if filename
|
87
|
+
@filename = filename
|
88
|
+
@input = File.open(filename, 'r')
|
89
|
+
else
|
90
|
+
@filename = 'STDIN'
|
91
|
+
@input = $stdin
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
locals = @options.delete(:locals) || {}
|
96
|
+
Template.new(@filename, @options) { @input.read }.render(nil, locals)
|
97
|
+
end
|
98
|
+
|
99
|
+
result = prepend_assignment(result)
|
100
|
+
|
101
|
+
rescue Exception => ex
|
102
|
+
raise ex if @trace || SystemExit === ex
|
103
|
+
$stderr.print "#{ex.class}: " if ex.class != RuntimeError
|
104
|
+
$stderr.puts ex.message
|
105
|
+
$stderr.puts ' Use --trace for backtrace.'
|
106
|
+
exit 1
|
107
|
+
else
|
108
|
+
unless @options[:output]
|
109
|
+
filename = args.shift
|
110
|
+
@options[:output] = filename ? File.open(filename, 'w') : $stdout
|
111
|
+
end
|
112
|
+
@options[:output].puts(result)
|
113
|
+
exit 0
|
114
|
+
end
|
115
|
+
|
116
|
+
def prepend_assignment(result)
|
117
|
+
assignment = ''
|
118
|
+
initialization = ''
|
119
|
+
|
120
|
+
global = 'this'
|
121
|
+
if @node_global
|
122
|
+
global = 'global'
|
123
|
+
result.sub!(/(this)(\.Skim =)/) {"#{global}#{$2}"}
|
124
|
+
end
|
125
|
+
|
126
|
+
assignment += "module.exports = " if @export
|
127
|
+
assignment += "#{global}.#{@assign_variable_name} = " if @assign_variable_name
|
128
|
+
if @assign_object_name
|
129
|
+
object_name = "#{global}.#{@assign_object_name}"
|
130
|
+
initialization = "#{object_name} || (#{object_name} = {});\n"
|
131
|
+
assignment += "#{object_name}[#{truncated_filename.inspect}] = "
|
132
|
+
end
|
133
|
+
|
134
|
+
assignment.empty? ? result : (initialization + assignment + result)
|
135
|
+
end
|
136
|
+
|
137
|
+
def truncated_filename
|
138
|
+
@filename.sub(/\.[^#{File::SEPARATOR}]*\Z/, '')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/lib/skim/engine.rb
CHANGED
@@ -22,7 +22,6 @@ module Skim
|
|
22
22
|
use Slim::Splat::Filter
|
23
23
|
use Skim::Controls
|
24
24
|
html :AttributeSorter
|
25
|
-
html :AttributeMerger
|
26
25
|
use Temple::CoffeeScript::AttributeMerger
|
27
26
|
use Skim::CodeAttributes
|
28
27
|
use(:AttributeRemover) { Temple::CoffeeScript::AttributeRemover.new(:remove_empty_attrs => options[:merge_attrs].keys)}
|
data/lib/skim/sprockets.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require "sprockets"
|
2
2
|
|
3
|
-
Sprockets.
|
3
|
+
if Sprockets.respond_to?(:register_transformer)
|
4
|
+
Sprockets.register_mime_type 'text/skim', extensions: ['.skim', '.jst.skim'], charset: :unicode
|
5
|
+
Sprockets.register_transformer 'text/skim', 'application/javascript+function', Skim::Template
|
6
|
+
end
|
7
|
+
|
8
|
+
if Sprockets.respond_to?(:register_engine)
|
9
|
+
args = ['.skim', Skim::Template]
|
10
|
+
args << { mime_type: 'application/javascript', silence_deprecation: true } if Sprockets::VERSION.start_with?('3')
|
11
|
+
Sprockets.register_engine(*args)
|
12
|
+
end
|
4
13
|
|
5
14
|
unless defined?(Rails::Engine)
|
6
15
|
Sprockets.append_path File.expand_path('../../../vendor/assets/javascripts', __FILE__)
|
data/lib/skim/template.rb
CHANGED
@@ -6,6 +6,14 @@ module Skim
|
|
6
6
|
class Template
|
7
7
|
self.default_mime_type = "application/javascript"
|
8
8
|
|
9
|
+
def self.call(input)
|
10
|
+
source = input[:data]
|
11
|
+
context = input[:environment].context_class.new(input)
|
12
|
+
|
13
|
+
result = new { source }.render
|
14
|
+
context.metadata.merge(data: result)
|
15
|
+
end
|
16
|
+
|
9
17
|
def coffee_script_src
|
10
18
|
|
11
19
|
engine = Engine.new(options.merge({
|
@@ -17,7 +25,7 @@ module Skim
|
|
17
25
|
<<-SRC
|
18
26
|
#{self.class.skim_src unless engine.options[:use_asset]}
|
19
27
|
return (context = {}) ->
|
20
|
-
Skim.withContext.call {}, context, ->
|
28
|
+
(context.Skim || Skim).withContext.call {}, context, ->
|
21
29
|
#{src}
|
22
30
|
SRC
|
23
31
|
end
|
data/lib/skim/version.rb
CHANGED
data/skim.gemspec
CHANGED
@@ -2,30 +2,31 @@
|
|
2
2
|
require File.expand_path('../lib/skim/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
5
|
+
gem.authors = ['AppJudo Inc.']
|
6
|
+
gem.email = ['info@appjudo.com']
|
7
7
|
gem.description = %q{Fat-free client-side templates with Slim and CoffeeScript}
|
8
8
|
gem.summary = %q{Take the fat out of your client-side templates with Skim. Skim is the Slim templating engine
|
9
9
|
with embedded CoffeeScript. It compiles to JavaScript templates (.jst), which can then be served by Rails or any other
|
10
10
|
Sprockets-based asset pipeline.}
|
11
|
-
gem.homepage =
|
11
|
+
gem.homepage = ''
|
12
12
|
|
13
13
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
14
|
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
16
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
-
gem.name =
|
17
|
-
gem.require_paths = [
|
17
|
+
gem.name = 'skim'
|
18
|
+
gem.require_paths = ['lib']
|
18
19
|
gem.version = Skim::VERSION
|
20
|
+
gem.license = 'MIT'
|
19
21
|
|
20
22
|
gem.add_dependency "slim", '>= 3.0'
|
21
23
|
gem.add_dependency "coffee-script"
|
22
24
|
gem.add_dependency "coffee-script-source", ">= 1.2.0"
|
23
|
-
gem.add_dependency "sprockets", ">= 2", "<
|
25
|
+
gem.add_dependency "sprockets", ">= 2.0", "< 5.0"
|
24
26
|
|
25
27
|
gem.add_development_dependency "rake"
|
26
28
|
gem.add_development_dependency "pry"
|
27
29
|
gem.add_development_dependency "execjs"
|
28
30
|
gem.add_development_dependency "minitest-reporters"
|
29
|
-
gem.add_development_dependency "
|
30
|
-
gem.add_development_dependency "libv8", "~> 3.16.14.0"
|
31
|
+
gem.add_development_dependency "libv8", "~> 8.4"
|
31
32
|
end
|
data/test/test_code_blocks.rb
CHANGED
@@ -86,4 +86,21 @@ p
|
|
86
86
|
|
87
87
|
assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!', source
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
|
+
def test_attribute_merger
|
91
|
+
source = %q{
|
92
|
+
.hello class='ruby' Hello Ruby!
|
93
|
+
}
|
94
|
+
|
95
|
+
assert_html '<div class="hello ruby">Hello Ruby!</div>', source
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_attribute_merger_with_not_static_class_attr
|
99
|
+
source = %q{
|
100
|
+
- class_name = 'ruby'
|
101
|
+
.hello class=class_name Hello Ruby!
|
102
|
+
}
|
103
|
+
|
104
|
+
assert_html '<div class="hello ruby">Hello Ruby!</div>', source
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'open3'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
class TestSkimCommands < Minitest::Test
|
7
|
+
# nothing complex
|
8
|
+
STATIC_TEMPLATE = "p Hello World!\n"
|
9
|
+
|
10
|
+
# requires a `name` variable to exist at render time
|
11
|
+
DYNAMIC_TEMPLATE = "p Hello \#{name}!\n"
|
12
|
+
|
13
|
+
# a more complex example
|
14
|
+
LONG_TEMPLATE = "h1 Hello\np\n | World!\n small Tiny text"
|
15
|
+
|
16
|
+
# exception raising example
|
17
|
+
INVALID_TEMPLATE = '- if true'
|
18
|
+
|
19
|
+
def test_option_help
|
20
|
+
out, err = exec_skim '--help'
|
21
|
+
assert err.empty?
|
22
|
+
assert_match /Show this help message/, out
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_option_version
|
26
|
+
out, err = exec_skim '--version'
|
27
|
+
assert err.empty?
|
28
|
+
assert_match /\ASkim #{Regexp.escape Skim::VERSION}$/, out
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_export
|
32
|
+
prepare_common_test STATIC_TEMPLATE, '--export' do |out, err|
|
33
|
+
assert err.empty?
|
34
|
+
assert_equal "<p>Hello World!</p>", evaluate_node(out, 'module.exports()')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_assign_variable
|
39
|
+
prepare_common_test STATIC_TEMPLATE, '--assign', 'myFunction' do |out, err|
|
40
|
+
assert err.empty?
|
41
|
+
assert_equal "<p>Hello World!</p>", evaluate(out, 'myFunction()')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_assign_object
|
46
|
+
with_tempfile STATIC_TEMPLATE do |in_file|
|
47
|
+
out, err = exec_skim '--assign-object', 'myObject', in_file
|
48
|
+
assert err.empty?
|
49
|
+
key = in_file.chomp(File.extname(in_file))
|
50
|
+
assert_equal "<p>Hello World!</p>", evaluate(out, "myObject[#{key.inspect}]()")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_jst
|
55
|
+
with_tempfile STATIC_TEMPLATE do |in_file|
|
56
|
+
out, err = exec_skim '--jst', in_file
|
57
|
+
assert err.empty?
|
58
|
+
key = in_file.chomp(File.extname(in_file))
|
59
|
+
assert_equal "<p>Hello World!</p>", evaluate(out, "JST[#{key.inspect}]()")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_node_global
|
64
|
+
prepare_common_test STATIC_TEMPLATE, '--node-global', '--assign', 'myFunction' do |out, err|
|
65
|
+
assert err.empty?
|
66
|
+
assert_match /global\.Skim/, out
|
67
|
+
assert_equal "<p>Hello World!</p>", evaluate_node(out, 'global.myFunction()')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_asset_only
|
72
|
+
out, err = exec_skim '--asset-only'
|
73
|
+
assert err.empty?
|
74
|
+
assert_match %r{withContext\: function}, out
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_omit_asset
|
78
|
+
prepare_common_test STATIC_TEMPLATE, '--omit-asset' do |out, err|
|
79
|
+
assert err.empty?
|
80
|
+
refute_match %r{withContext\: function}, out
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_require
|
85
|
+
with_tempfile 'puts "Not in skim"', 'rb' do |lib|
|
86
|
+
prepare_common_test STATIC_TEMPLATE, '--require', lib, stdin_file: false, file_file: false do |out, err|
|
87
|
+
assert err.empty?
|
88
|
+
assert_match %r{\ANot in skim\n}, out
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_error
|
94
|
+
prepare_common_test INVALID_TEMPLATE, stdin_file: false do |out, err|
|
95
|
+
assert out.empty?
|
96
|
+
assert_match /SyntaxError/, err
|
97
|
+
assert_match /Use --trace for backtrace/, err
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_trace_error
|
102
|
+
prepare_common_test INVALID_TEMPLATE, '--trace', stdin_file: false do |out, err|
|
103
|
+
assert out.empty?
|
104
|
+
assert_match /SyntaxError/, err
|
105
|
+
assert_match /bin\/skim/, err
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
# Executes a test (given as block) four times:
|
112
|
+
#
|
113
|
+
# 1. Read from $stdin, write to $stdout
|
114
|
+
# 2. Read from file, write to $stdout
|
115
|
+
# 3. Read from $stdin, write to file
|
116
|
+
# 4. Read from file, write to file
|
117
|
+
#
|
118
|
+
# Each of the above test executions yields a tuple (out, err).
|
119
|
+
# Any args given are passed to the skim command (before input/output args).
|
120
|
+
def prepare_common_test(content, *args)
|
121
|
+
options = Hash === args.last ? args.pop : {}
|
122
|
+
|
123
|
+
# case 1. $stdin → $stdout
|
124
|
+
unless options[:stdin_stdout] == false
|
125
|
+
out, err = exec_skim *args, '--stdin' do |i|
|
126
|
+
i.write content
|
127
|
+
end
|
128
|
+
yield out, err
|
129
|
+
end
|
130
|
+
|
131
|
+
# case 2. file → $stdout
|
132
|
+
unless options[:file_stdout] == false
|
133
|
+
with_tempfile content do |in_file|
|
134
|
+
out, err = exec_skim *args, in_file
|
135
|
+
yield out, err
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# case 3. $stdin → file
|
140
|
+
unless options[:stdin_file] == false
|
141
|
+
with_tempfile content do |out_file|
|
142
|
+
_, err = exec_skim *args, '--stdin', out_file do |i|
|
143
|
+
i.write content
|
144
|
+
end
|
145
|
+
yield File.read(out_file), err
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# case 4. file → file
|
150
|
+
unless options[:file_file] == false
|
151
|
+
with_tempfile '' do |out_file|
|
152
|
+
with_tempfile content do |in_file|
|
153
|
+
_, err = exec_skim *args, in_file, out_file do |i|
|
154
|
+
i.write content
|
155
|
+
end
|
156
|
+
yield File.read(out_file), err
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def evaluate(src, expression)
|
163
|
+
ExecJS.compile(src).eval(expression)
|
164
|
+
end
|
165
|
+
|
166
|
+
def evaluate_node(src, expression)
|
167
|
+
evaluate("var module = {};\nvar global = this;\n" + src, expression)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Calls bin/skim as a subprocess.
|
171
|
+
#
|
172
|
+
# Yields $stdin to the caller and returns a tupel (out, err) with the
|
173
|
+
# contents of $stdout and $stderr.
|
174
|
+
def exec_skim(*args)
|
175
|
+
out, err = nil, nil
|
176
|
+
|
177
|
+
Open3.popen3 'ruby', 'bin/skim', *args do |stdin, stdout, stderr, wait_thread|
|
178
|
+
yield stdin if block_given?
|
179
|
+
stdin.close
|
180
|
+
out, err = stdout.read, stderr.read
|
181
|
+
end
|
182
|
+
|
183
|
+
return out, err
|
184
|
+
end
|
185
|
+
|
186
|
+
# Creates a temporary file with the given content and yield the path
|
187
|
+
# to this file. The file itself is only available inside the block and
|
188
|
+
# will be deleted afterwards.
|
189
|
+
def with_tempfile(content=nil, extname='skim')
|
190
|
+
f = Tempfile.new ['skim', ".#{extname}"]
|
191
|
+
if content
|
192
|
+
f.write content
|
193
|
+
f.flush # ensure content is actually saved to disk
|
194
|
+
f.rewind
|
195
|
+
end
|
196
|
+
|
197
|
+
yield f.path
|
198
|
+
ensure
|
199
|
+
f.close
|
200
|
+
f.unlink
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- AppJudo Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slim
|
@@ -58,20 +58,20 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2'
|
61
|
+
version: '2.0'
|
62
62
|
- - "<"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '5.0'
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: '2'
|
71
|
+
version: '2.0'
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '5.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,50 +128,40 @@ dependencies:
|
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
|
-
- !ruby/object:Gem::Dependency
|
132
|
-
name: therubyracer
|
133
|
-
requirement: !ruby/object:Gem::Requirement
|
134
|
-
requirements:
|
135
|
-
- - ">="
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '0'
|
138
|
-
type: :development
|
139
|
-
prerelease: false
|
140
|
-
version_requirements: !ruby/object:Gem::Requirement
|
141
|
-
requirements:
|
142
|
-
- - ">="
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '0'
|
145
131
|
- !ruby/object:Gem::Dependency
|
146
132
|
name: libv8
|
147
133
|
requirement: !ruby/object:Gem::Requirement
|
148
134
|
requirements:
|
149
135
|
- - "~>"
|
150
136
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
137
|
+
version: '8.4'
|
152
138
|
type: :development
|
153
139
|
prerelease: false
|
154
140
|
version_requirements: !ruby/object:Gem::Requirement
|
155
141
|
requirements:
|
156
142
|
- - "~>"
|
157
143
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
144
|
+
version: '8.4'
|
159
145
|
description: Fat-free client-side templates with Slim and CoffeeScript
|
160
146
|
email:
|
161
|
-
-
|
162
|
-
executables:
|
147
|
+
- info@appjudo.com
|
148
|
+
executables:
|
149
|
+
- skim
|
163
150
|
extensions: []
|
164
151
|
extra_rdoc_files: []
|
165
152
|
files:
|
166
153
|
- ".gitignore"
|
154
|
+
- ".ruby-version"
|
167
155
|
- ".travis.yml"
|
168
156
|
- Gemfile
|
169
157
|
- History.md
|
170
158
|
- LICENSE
|
171
159
|
- README.md
|
172
160
|
- Rakefile
|
161
|
+
- bin/skim
|
173
162
|
- lib/skim.rb
|
174
163
|
- lib/skim/code_attributes.rb
|
164
|
+
- lib/skim/command.rb
|
175
165
|
- lib/skim/controls.rb
|
176
166
|
- lib/skim/engine.rb
|
177
167
|
- lib/skim/interpolation.rb
|
@@ -198,13 +188,15 @@ files:
|
|
198
188
|
- test/test_code_evaluation.rb
|
199
189
|
- test/test_code_output.rb
|
200
190
|
- test/test_code_structure.rb
|
191
|
+
- test/test_commands.rb
|
201
192
|
- test/test_html_escaping.rb
|
202
193
|
- test/test_html_structure.rb
|
203
194
|
- test/test_skim_template.rb
|
204
195
|
- test/test_text_interpolation.rb
|
205
196
|
- vendor/assets/javascripts/skim.js.coffee
|
206
197
|
homepage: ''
|
207
|
-
licenses:
|
198
|
+
licenses:
|
199
|
+
- MIT
|
208
200
|
metadata: {}
|
209
201
|
post_install_message:
|
210
202
|
rdoc_options: []
|
@@ -221,8 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
213
|
- !ruby/object:Gem::Version
|
222
214
|
version: '0'
|
223
215
|
requirements: []
|
224
|
-
|
225
|
-
rubygems_version: 2.4.5
|
216
|
+
rubygems_version: 3.0.3
|
226
217
|
signing_key:
|
227
218
|
specification_version: 4
|
228
219
|
summary: Take the fat out of your client-side templates with Skim. Skim is the Slim
|
@@ -239,6 +230,7 @@ test_files:
|
|
239
230
|
- test/test_code_evaluation.rb
|
240
231
|
- test/test_code_output.rb
|
241
232
|
- test/test_code_structure.rb
|
233
|
+
- test/test_commands.rb
|
242
234
|
- test/test_html_escaping.rb
|
243
235
|
- test/test_html_structure.rb
|
244
236
|
- test/test_skim_template.rb
|