jing 0.1.3 → 0.1.5

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
  SHA256:
3
- metadata.gz: c0109a16bd2e74f10edbe5aa725d5e8b63ff68e1ba1c5b5668641f351a2f172f
4
- data.tar.gz: f5c8d6cf786cfc9032d3f06c1a8c4361e7a612a3b8927c11b1e45256981ce3dc
3
+ metadata.gz: 40b0c3e50b02a0213e97bd9b1a7fd5f4e8b8efce03faad1e4943906bc300c186
4
+ data.tar.gz: 2ad0975e17e68f10b3187f38dab7321f98c23adac21e7e9b477149325c0c8f2f
5
5
  SHA512:
6
- metadata.gz: d2bb4d26c9d2371c680f347e1ffec482c83a2179a750063a252791ffb70c0440027991f398ca40d6cd65a4b1e0c9e5097a9a67fdb244b99ca1f0bb9f8528c104
7
- data.tar.gz: 23ed2e92a0df6b52bd94c0c48a81ba5364125a4e1e0380e2c47cff09f929f11e0837cc21c6a306f47680c991ecf936657f68f5dc167a30dd31f59d663d010242
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
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+ Extending is fairly easy.
65
65
 
66
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
 
@@ -0,0 +1,3 @@
1
+ #rm *.gem
2
+ gem build jing.gemspec
3
+ rake install
@@ -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, '_layouts', "#{meta[:layout]}.*")].first
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
- File.join(path, File.basename(file).split('.', 3)[0..1].join('.'))
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, '_partials', "#{file}.*")].first
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
- File.basename(file).split('.')[1..-1].reverse.each do |ext|
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]} => #{dstname(file, @dst)[@dst.size+1..-1]} (#{(body.size/1024.0).round(2)}kb)"
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
- @converter_extensions.delete('js')
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 "WATCHED #{filename}\t#{event}"
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
- %w[_layouts _partials].each { |e| FileUtils.mkdir_p(File.join(opts[:name], e)) }
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={})
@@ -1,3 +1,3 @@
1
1
  module Jing
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,4 @@
1
+ gem build jing.gemspec
2
+ gemfile=$(ls *.gem | tail -n 1)
3
+ echo pushing $gemfile
4
+ gem push $gemfile
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.3
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-06 00:00:00.000000000 Z
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