jing 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/jing +6 -0
- data/bin/setup +8 -0
- data/jing.gemspec +28 -0
- data/lib/jing.rb +124 -0
- data/lib/jing/version.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47f325ca7dd14ce87ee5f723c99fc304bc3bf6a8a46db119661d25042bad3c46
|
4
|
+
data.tar.gz: ee9b6a1a936af41ce75f1b1fbb51f1da986f668d5d143fc01437707d0239ba5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d024d28256b4c8ccd70122e153df628566c639ffbc90a3ddf939b112c2ae2f0e061a2221592cd9b120a49fc1372e515f4ada4425bc9f98e70e0016d5449c67ae
|
7
|
+
data.tar.gz: 8dd63e51f46fd3e71ea8744681c0d8beccc9544eda9dd1e079ad2a7e2fa22a1560bfec6cceced9102a9245e690087f80fc6ab10bd0895314d845aedd96108a72
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 pachacamac
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Jing
|
2
|
+
|
3
|
+
A tiny static site generator packing a punch
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jing'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jing
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
call `jing` on the command line or have a look at the code (it's tiny) :)
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
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).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pachacamac/jing.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jing"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/jing
ADDED
data/bin/setup
ADDED
data/jing.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "jing/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jing"
|
7
|
+
spec.version = Jing::VERSION
|
8
|
+
spec.authors = ["pachacamac"]
|
9
|
+
spec.email = ["marcanbe@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A tiny static site generator packing a punch}
|
12
|
+
spec.description = %q{Yes yet another static site generator}
|
13
|
+
spec.homepage = "https://github.com/pachacamac/jing"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.executables = ["jing"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
data/lib/jing.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require "jing/version"
|
2
|
+
|
3
|
+
module Jing
|
4
|
+
class Jing
|
5
|
+
attr_accessor :converters, :converter_extensions
|
6
|
+
|
7
|
+
def initialize(opts={})
|
8
|
+
@src = File.expand_path(opts[:src] || Dir.pwd)
|
9
|
+
@dst = File.expand_path(opts[:dst] || File.join(@src, '_dst'))
|
10
|
+
@converters = (opts[:converter_addons] || []) + [
|
11
|
+
{extensions: %w[erb], handler: Proc.new { |body, meta, ctx|
|
12
|
+
ERB.new(body).result(OpenStruct.new(meta: meta).instance_eval { ctx })
|
13
|
+
}},
|
14
|
+
{extensions: %w[html htm], handler: Proc.new { |body, meta, ctx|
|
15
|
+
if meta[:layout] && layout = Dir[File.join(@src, '_layouts', "#{meta[:layout]}.*")].first
|
16
|
+
content = load_content(layout, meta)
|
17
|
+
ERB.new(content[:body]).result(OpenStruct.new(meta: meta, body: body).instance_eval { ctx })
|
18
|
+
else
|
19
|
+
ERB.new(body).result(OpenStruct.new(meta: meta).instance_eval { ctx })
|
20
|
+
end
|
21
|
+
}},
|
22
|
+
{extensions: %w[scss sass], handler: ->(body, meta, ctx){
|
23
|
+
load_gem 'sassc'
|
24
|
+
SassC::Engine.new(body, style: (meta[:style] || :compressed)).render
|
25
|
+
}},
|
26
|
+
{extensions: %w[ts], handler: ->(body, meta, ctx){
|
27
|
+
load_gem 'typescript-node'
|
28
|
+
TypeScript::Node.compile(body, '--target', (meta[:style] || 'ES5'))
|
29
|
+
}},
|
30
|
+
{extensions: %w[js], handler: ->(body, meta, ctx){
|
31
|
+
load_gem 'uglifier'
|
32
|
+
Uglifier.compile(body, harmony: true)
|
33
|
+
}},
|
34
|
+
{extensions: %w[md markdown], handler: ->(body, meta, ctx){
|
35
|
+
load_gem 'kramdown'
|
36
|
+
Kramdown::Document.new(body).to_html
|
37
|
+
}},
|
38
|
+
]
|
39
|
+
|
40
|
+
@converter_extensions = @converters.map { |e| e[:extensions] }.flatten
|
41
|
+
main_meta_file = File.join(@src, '.meta.yml')
|
42
|
+
@meta = YAML.load(File.read(main_meta_file)).map { |k,v| [k.to_sym,v] }.to_h if File.exist?(main_meta_file)
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_gem(name, opts={})
|
46
|
+
gemfile { source(opts.delete(:source)||'https://rubygems.org'); gem(name, opts) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def dstname(file, path=File.dirname(file))
|
50
|
+
File.join(path, File.basename(file).split('.', 3)[0..1].join('.'))
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_content(file, meta={})
|
54
|
+
body = File.open(file, 'rb').read
|
55
|
+
return {body: body, meta: meta} unless @converter_extensions.include?(File.extname(file)[1..-1])
|
56
|
+
body.match(/^(?:(---\s*\n.*?\n?)^(?:---\s*$\n?))?(.*)$/m)
|
57
|
+
meta.merge!(YAML.load($1).map { |k,v| [k.to_sym,v] }.to_h) if $1
|
58
|
+
{body: $2, meta: meta}
|
59
|
+
end
|
60
|
+
|
61
|
+
def render(file, meta={})
|
62
|
+
if !File.file?(file)
|
63
|
+
file = Dir[File.join(@src, '_partials', "#{file}.*")].first
|
64
|
+
else
|
65
|
+
meta.merge!(file: file)
|
66
|
+
end
|
67
|
+
t = Time.now
|
68
|
+
content = load_content(file, meta)
|
69
|
+
body = content[:body]
|
70
|
+
File.basename(file).split('.')[1..-1].reverse.each do |ext|
|
71
|
+
converter = @converters.find { |c| c[:extensions].include?(ext) }
|
72
|
+
body = converter ? converter[:handler].call(body, content[:meta], binding) : body
|
73
|
+
end
|
74
|
+
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)"
|
75
|
+
body
|
76
|
+
rescue => e
|
77
|
+
puts "Error\t#{file[@src.size+1..-1]}\n\t#{e.message}\n#{e.backtrace.map{|x| "\t#{x}"}.join("\n")}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def build!
|
81
|
+
t = Time.now
|
82
|
+
FileUtils.rm_r(@dst) if File.exist?(@dst)
|
83
|
+
Dir.mkdir(@dst)
|
84
|
+
Dir[File.join(@src, '**', '*')].each do |file|
|
85
|
+
next unless File.file?(file)
|
86
|
+
dir = File.dirname(file)[@src.size+1..-1]
|
87
|
+
next if dir.to_s.start_with?('_')
|
88
|
+
outfile = dstname(file, File.join(*[@dst, dir].compact))
|
89
|
+
out = render(file, @meta.merge(layout: dir))
|
90
|
+
FileUtils.mkdir_p(File.dirname(outfile))
|
91
|
+
File.open(outfile, 'wb').write(out)
|
92
|
+
end
|
93
|
+
puts "#{'%.4fs' % (Time.now-t)} total"
|
94
|
+
end
|
95
|
+
|
96
|
+
def watch!
|
97
|
+
@converter_extensions.delete('js')
|
98
|
+
build!
|
99
|
+
load_gem('filewatcher')
|
100
|
+
Filewatcher.new([@src, '**', '*']).watch do |filename, event|
|
101
|
+
puts "WATCHED #{filename}\t#{event}"
|
102
|
+
build!
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def serve!
|
107
|
+
WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: @dst).start
|
108
|
+
end
|
109
|
+
|
110
|
+
def create!
|
111
|
+
abort("usage: #{File.basename($0)} create <name/path>") unless ARGV[1]
|
112
|
+
%w[_layouts _partials].each { |e| FileUtils.mkdir_p(File.join(ARGV[1], e)) }
|
113
|
+
File.write(File.join(ARGV[1], '.meta.yml'), "---\ngenerator: jing\nname: #{File.basename(ARGV[1])}\n---\n")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.cli!
|
118
|
+
cmd = ARGV[0]
|
119
|
+
commands = Jing.instance_methods(false).grep(/!$/).map{|e| e[0..-2]}
|
120
|
+
abort("usage: #{File.basename($0)} <#{commands.join('|')}>") unless commands.include?(cmd)
|
121
|
+
jing = Jing.new()
|
122
|
+
jing.send(:"#{cmd}!")
|
123
|
+
end
|
124
|
+
end
|
data/lib/jing/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pachacamac
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Yes yet another static site generator
|
42
|
+
email:
|
43
|
+
- marcanbe@gmail.com
|
44
|
+
executables:
|
45
|
+
- jing
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/jing
|
56
|
+
- bin/setup
|
57
|
+
- jing.gemspec
|
58
|
+
- lib/jing.rb
|
59
|
+
- lib/jing/version.rb
|
60
|
+
homepage: https://github.com/pachacamac/jing
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.7.4
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: A tiny static site generator packing a punch
|
84
|
+
test_files: []
|