jing 0.1.3 → 0.1.5
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 +4 -4
- data/README.md +8 -2
- data/build_and_install.sh +3 -0
- data/lib/jing.rb +23 -12
- data/lib/jing/version.rb +1 -1
- data/publish.sh +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40b0c3e50b02a0213e97bd9b1a7fd5f4e8b8efce03faad1e4943906bc300c186
|
4
|
+
data.tar.gz: 2ad0975e17e68f10b3187f38dab7321f98c23adac21e7e9b477149325c0c8f2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dc11fe05f38be3035d01941b3aea6ea8f0a4dfe978711dbfad8421ddecb0bfd0e54a3be57ba5ea5b38461d9670eb32f0983674113e13111ff8a4677aa53bfb0
|
7
|
+
data.tar.gz: 3ce97d022d737b8b781ee95a916dd5d72b2d0390410fe5e43c165b44567f466e5ff320de2e9a4d717b2a7719c66d13230c9fec8bfb70291b63888949ed7a188b
|
data/README.md
CHANGED
@@ -61,9 +61,15 @@ Folders starting with `_` have special meaning, they generally won't get copied
|
|
61
61
|
|
62
62
|
## Development
|
63
63
|
|
64
|
-
|
64
|
+
Extending is fairly easy.
|
65
65
|
|
66
|
-
|
66
|
+
`@converters` variable in the initialize method holds a bunch of converters. Just add one in the spirit of the others. You can also do this on the fly when initiating the Jing Class by passing the `converter_addons` option.
|
67
|
+
|
68
|
+
Class methods that end in a bang `!` automatically are registered as cli commands. If you wish to add a command just add a bang-method and you should be done.
|
69
|
+
|
70
|
+
Feel free to open issues for questions / ideas etc that you don't know how to work on or have no time working on as well as actual bugs and quirky etc. I'm sure there are some.
|
71
|
+
|
72
|
+
Please fork and make a pull request if you want to contribute.
|
67
73
|
|
68
74
|
## Contributing
|
69
75
|
|
data/lib/jing.rb
CHANGED
@@ -9,19 +9,22 @@ module Jing
|
|
9
9
|
def initialize(opts={})
|
10
10
|
@src = File.expand_path(opts[:src] || Dir.pwd)
|
11
11
|
@dst = File.expand_path(opts[:dst] || File.join(@src, '_dst'))
|
12
|
+
@layouts = opts[:layouts] || '_layouts'
|
13
|
+
@partials = opts[:partials] || '_partials'
|
14
|
+
@loaded_gems = {}
|
12
15
|
@converters = (opts[:converter_addons] || []) + [
|
13
16
|
{extensions: %w[erb], handler: Proc.new { |body, meta, ctx|
|
14
17
|
ERB.new(body).result(OpenStruct.new(meta: meta).instance_eval { ctx })
|
15
18
|
}},
|
16
19
|
{extensions: %w[html htm], handler: Proc.new { |body, meta, ctx|
|
17
|
-
if meta[:layout] && layout = Dir[File.join(@src,
|
20
|
+
if meta[:layout] && layout = Dir[File.join(@src, @layouts, "#{meta[:layout]}.*")].first
|
18
21
|
content = load_content(layout, meta)
|
19
22
|
ERB.new(content[:body]).result(OpenStruct.new(meta: meta, body: body).instance_eval { ctx })
|
20
23
|
else
|
21
24
|
ERB.new(body).result(OpenStruct.new(meta: meta).instance_eval { ctx })
|
22
25
|
end
|
23
26
|
}},
|
24
|
-
{extensions: %w[scss sass], handler: ->(body, meta, ctx){
|
27
|
+
{extensions: %w[scss sass css], handler: ->(body, meta, ctx){
|
25
28
|
load_gem 'sassc'
|
26
29
|
SassC::Engine.new(body, style: (meta[:style] || :compressed)).render
|
27
30
|
}},
|
@@ -31,7 +34,7 @@ module Jing
|
|
31
34
|
}},
|
32
35
|
{extensions: %w[js], handler: ->(body, meta, ctx){
|
33
36
|
load_gem 'uglifier'
|
34
|
-
Uglifier.compile(body, harmony: true, output: {ascii_only: true})
|
37
|
+
Uglifier.compile(body, harmony: true, compress: false, mangle: false, output: {ascii_only: true})
|
35
38
|
}},
|
36
39
|
{extensions: %w[md markdown], handler: ->(body, meta, ctx){
|
37
40
|
load_gem 'kramdown'
|
@@ -45,11 +48,17 @@ module Jing
|
|
45
48
|
end
|
46
49
|
|
47
50
|
def load_gem(name, opts={})
|
48
|
-
gemfile { source(opts.delete(:source)||'https://rubygems.org'); gem(name, opts) }
|
51
|
+
@loaded_gems[name] ||= gemfile { source(opts.delete(:source)||'https://rubygems.org'); gem(name, opts) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def active_exts(file)
|
55
|
+
File.basename(file).split('.').reverse.take_while{|e| @converter_extensions.include?(e)}
|
49
56
|
end
|
50
57
|
|
51
58
|
def dstname(file, path=File.dirname(file))
|
52
|
-
|
59
|
+
exts = active_exts(file).reverse
|
60
|
+
size = exts.size > 1 ? exts[1..-1].join('.').size+2 : 1
|
61
|
+
File.join(path, File.basename(file)[0..-size])
|
53
62
|
end
|
54
63
|
|
55
64
|
def load_content(file, meta={})
|
@@ -62,18 +71,19 @@ module Jing
|
|
62
71
|
|
63
72
|
def render(file, meta={})
|
64
73
|
if !File.file?(file)
|
65
|
-
file = Dir[File.join(@src,
|
74
|
+
file = Dir[File.join(@src, @partials, "#{file}.*")].first
|
66
75
|
else
|
67
76
|
meta.merge!(file: file)
|
68
77
|
end
|
69
78
|
t = Time.now
|
70
79
|
content = load_content(file, meta)
|
71
80
|
body = content[:body]
|
72
|
-
|
81
|
+
exts = active_exts(file)
|
82
|
+
exts.each do |ext|
|
73
83
|
converter = @converters.find { |c| c[:extensions].include?(ext) }
|
74
84
|
body = converter ? converter[:handler].call(body, content[:meta], binding) : body
|
75
85
|
end
|
76
|
-
puts "#{'%.4fs' % (Time.now-t)}\t#{file[@src.size+1..-1]}
|
86
|
+
puts "#{'%.4fs' % (Time.now-t)}\t#{file[@src.size+1..-1]} >#{exts.join('>')}> #{dstname(file, @dst)[@dst.size+1..-1]} (#{(body.size/1024.0).round(2)}kb)"
|
77
87
|
body
|
78
88
|
rescue => e
|
79
89
|
puts "Error\t#{file[@src.size+1..-1]}\n\t#{e.message}\n#{e.backtrace.map{|x| "\t#{x}"}.join("\n")}"
|
@@ -96,12 +106,13 @@ module Jing
|
|
96
106
|
end
|
97
107
|
|
98
108
|
def watch!(opts={})
|
99
|
-
@
|
109
|
+
@converters.delete_if{|e| e[:extensions]==['js']}
|
110
|
+
@converters<<{extensions: %w[js], handler: ->(body, meta, ctx){body}}
|
100
111
|
build!(opts)
|
101
112
|
load_gem('filewatcher')
|
102
113
|
Filewatcher.new([@src, '**', '*']).watch do |filename, event|
|
103
114
|
unless File.expand_path(filename) == @dst
|
104
|
-
puts "
|
115
|
+
puts "\nWATCHED: #{filename}\t#{event}\t#{Time.now}"
|
105
116
|
build!(opts)
|
106
117
|
end
|
107
118
|
end
|
@@ -113,8 +124,8 @@ module Jing
|
|
113
124
|
|
114
125
|
def create!(opts={})
|
115
126
|
abort("usage: #{File.basename($0)} create -name <pathname>") unless opts[:name]
|
116
|
-
|
117
|
-
File.write(File.join(opts[:name], '.meta.yml'), "---\ngenerator: jing\nname: #{File.basename(opts[:name])}\n---\n")
|
127
|
+
[@layouts, @partials].each { |e| FileUtils.mkdir_p(File.join(opts[:name], e)) }
|
128
|
+
File.write(File.join(opts[:name], '.meta.yml'), "---\ngenerator: jing #{VERSION}\nname: #{File.basename(opts[:name])}\n---\n")
|
118
129
|
end
|
119
130
|
|
120
131
|
def version!(opts={})
|
data/lib/jing/version.rb
CHANGED
data/publish.sh
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pachacamac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- bin/console
|
58
58
|
- bin/jing
|
59
59
|
- bin/setup
|
60
|
+
- build_and_install.sh
|
60
61
|
- examples/README.md
|
61
62
|
- examples/simplepage/.meta.yml
|
62
63
|
- examples/simplepage/_layouts/main.html.erb
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- jing.gemspec
|
68
69
|
- lib/jing.rb
|
69
70
|
- lib/jing/version.rb
|
71
|
+
- publish.sh
|
70
72
|
homepage: https://github.com/pachacamac/jing
|
71
73
|
licenses:
|
72
74
|
- MIT
|