wormwood 0.0.6 → 0.0.7
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.
- data/README.md +33 -29
- data/Rakefile +6 -0
- data/bin/wormwood +3 -11
- data/lib/wormwood.rb +22 -1
- data/lib/wormwood/version.rb +1 -1
- data/{test/lib/wormwood/build_test.rb → spec/lib/wormwood/build_spec.rb} +16 -2
- data/{test → spec}/test_helper.rb +15 -11
- metadata +6 -6
data/README.md
CHANGED
@@ -1,53 +1,57 @@
|
|
1
1
|
# Wormwood
|
2
2
|
|
3
|
-
Wormwood is an event-driven
|
3
|
+
Wormwood is an event-driven template rendering utility inspired by [Jekyll](https://github.com/mojombo/jekyll). It's great for rendering markdown, e.g., a README file, as you edit.
|
4
|
+
|
5
|
+
Wormwood will:
|
6
|
+
|
7
|
+
1. watch for changes to a template directory ( _./_ by default)
|
8
|
+
1. render the changed files (via [Tilt](https://github.com/rtomayko/tilt)) into a layout
|
9
|
+
1. write the rendered, laid-out content to an output directory ( _./_ by default).
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
$ gem install wormwood
|
4
15
|
|
5
|
-
Wormwood:
|
6
|
-
1. watches for changes to a template directory ( _./_ by default)
|
7
|
-
2. renders the changed files (via [Tilt](https://github.com/rtomayko/tilt))
|
8
|
-
3. writes the rendered output to an output directory ( _./_ by default).
|
9
16
|
|
10
17
|
## Usage
|
11
18
|
|
12
|
-
1. Create a file [Tilt](https://github.com/rtomayko/tilt) knows how to render, e.g., _foo.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
1. Create a file [Tilt](https://github.com/rtomayko/tilt) knows how to render, e.g., _foo.md_
|
20
|
+
1. Run `wormwood`
|
21
|
+
1. Edit _foo.md_ and observe the creation of _foo.html_
|
22
|
+
|
23
|
+
**Note:** Wormwood will generate a file called _<layout name>.erb_ in your source directory if a file named "layout" doesn't already exist. Feel free to hack it.
|
17
24
|
|
18
25
|
|
19
26
|
## Configuration
|
20
27
|
|
21
|
-
|
28
|
+
Wormwood defines a few configuration options:
|
22
29
|
|
23
|
-
|
30
|
+
`--source` The directory containing the template and layout files. Defaults to "./"
|
24
31
|
|
25
|
-
|
32
|
+
`--destination` The directory to write rendered files to. Defaults to "./"
|
26
33
|
|
27
|
-
`--layout`
|
34
|
+
`--layout` The layout file name (without extension). Defaults to "layout".
|
28
35
|
|
29
|
-
`--variable`
|
36
|
+
`--variable` The name of the variable used to insert rendered content into the layout. Defaults to "content".
|
30
37
|
|
31
38
|
|
32
|
-
##
|
39
|
+
## Developing
|
33
40
|
|
34
|
-
|
41
|
+
1. Develop
|
42
|
+
1. Build gem `rake build`
|
43
|
+
1. Install gem `rake install`
|
44
|
+
1. Run tests `rake test`
|
35
45
|
|
36
|
-
gem 'wormwood'
|
37
46
|
|
38
|
-
|
47
|
+
## Changelog
|
39
48
|
|
40
|
-
|
49
|
+
0.0.7 generates default layout
|
50
|
+
0.0.6 adds layout support
|
41
51
|
|
42
|
-
Or install it yourself as:
|
43
|
-
|
44
|
-
$ gem install wormwood
|
45
52
|
|
53
|
+
## License
|
46
54
|
|
47
|
-
|
55
|
+
Copyright 2013 Erik Eldridge
|
48
56
|
|
49
|
-
|
50
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
-
5. Create new Pull Request
|
57
|
+
Licensed under the MIT License
|
data/Rakefile
CHANGED
data/bin/wormwood
CHANGED
@@ -11,18 +11,14 @@ default_command :watch
|
|
11
11
|
|
12
12
|
global_option '--source [DIR]', 'Watches specified directory path (defaults to "./")'
|
13
13
|
global_option '--destination [DIR]', 'Writes to specified directory path (defaults to "./")'
|
14
|
-
global_option '--layout [NAME]', 'The layout
|
14
|
+
global_option '--layout [NAME]', 'The layout name (defaults to "layout")'
|
15
15
|
global_option '--variable [NAME]', 'The layout variable name (defaults to "content")'
|
16
16
|
|
17
17
|
command :watch do |c|
|
18
18
|
c.syntax = 'wormwood watch [options]'
|
19
19
|
c.description = 'Watches source directory and renders any files that change'
|
20
20
|
c.action do |args, options|
|
21
|
-
options.default
|
22
|
-
:source => './',
|
23
|
-
:destination => './',
|
24
|
-
:layout => 'layout',
|
25
|
-
:variable => 'content'
|
21
|
+
options.default Wormwood::DEFAULTS
|
26
22
|
Wormwood.watch(options)
|
27
23
|
end
|
28
24
|
end
|
@@ -31,11 +27,7 @@ command :build do |c|
|
|
31
27
|
c.syntax = 'wormwood build [options]'
|
32
28
|
c.description = 'Renders all templates in source directory'
|
33
29
|
c.action do |args, options|
|
34
|
-
options.default
|
35
|
-
:source => './',
|
36
|
-
:destination => './',
|
37
|
-
:layout => 'layout',
|
38
|
-
:variable => 'content'
|
30
|
+
options.default Wormwood::DEFAULTS
|
39
31
|
Wormwood.build(Dir[Wormwood::GLOB], options)
|
40
32
|
end
|
41
33
|
end
|
data/lib/wormwood.rb
CHANGED
@@ -5,7 +5,13 @@ require 'fileutils'
|
|
5
5
|
require 'tilt'
|
6
6
|
|
7
7
|
module Wormwood
|
8
|
-
GLOB = '**/*.{
|
8
|
+
GLOB = '**/*.{markdown,mkd,md}'
|
9
|
+
DEFAULTS = {
|
10
|
+
:source => '.',
|
11
|
+
:destination => '.',
|
12
|
+
:layout => 'layout',
|
13
|
+
:variable => 'content'
|
14
|
+
}
|
9
15
|
|
10
16
|
# ref: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/commands/build.rb
|
11
17
|
# ref: https://github.com/TwP/directory_watcher/blob/master/lib/directory_watcher.rb
|
@@ -22,6 +28,10 @@ module Wormwood
|
|
22
28
|
|
23
29
|
def self.build paths, options
|
24
30
|
layout_path = Dir.glob(File.join(options.source, "#{options.layout}*")).first
|
31
|
+
if layout_path.nil?
|
32
|
+
layout_path = File.join(options.source, "#{options.layout}.erb")
|
33
|
+
create_layout layout_path, options
|
34
|
+
end
|
25
35
|
paths.each do |source_path|
|
26
36
|
dest_path = File.join \
|
27
37
|
options.destination,
|
@@ -32,4 +42,15 @@ module Wormwood
|
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
45
|
+
def self.create_layout layout_path, options
|
46
|
+
default_layout = <<-EOS.gsub /^\s+/, ''
|
47
|
+
<!--
|
48
|
+
Default layout generated by wormwood.
|
49
|
+
Check out https://github.com/erikeldridge/wormwood#usage for more info.
|
50
|
+
-->
|
51
|
+
<%= #{options.variable} %>
|
52
|
+
EOS
|
53
|
+
File.write layout_path, default_layout
|
54
|
+
end
|
55
|
+
|
35
56
|
end
|
data/lib/wormwood/version.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
describe Wormwood do
|
3
3
|
before do
|
4
|
-
clear_dest
|
5
|
-
|
4
|
+
clear_dest!
|
5
|
+
create_source_dir!
|
6
|
+
create_template!
|
7
|
+
end
|
8
|
+
|
9
|
+
it "generates default layout" do
|
10
|
+
Wormwood.build \
|
11
|
+
[source_dir("foo.erb")],
|
12
|
+
OpenStruct.new({
|
13
|
+
'source' => source_dir,
|
14
|
+
'destination' => dest_dir,
|
15
|
+
'layout' => 'layout',
|
16
|
+
'variable' => 'content'
|
17
|
+
})
|
18
|
+
assert File.exist?(source_dir('layout.erb'))
|
6
19
|
end
|
7
20
|
|
8
21
|
it "writes to the correct destination" do
|
22
|
+
create_layout!
|
9
23
|
Wormwood.build \
|
10
24
|
[source_dir("foo.erb")],
|
11
25
|
OpenStruct.new({
|
@@ -4,12 +4,21 @@ require 'fileutils'
|
|
4
4
|
require 'ostruct'
|
5
5
|
require_relative '../lib/wormwood.rb'
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def clear_dest!
|
8
|
+
FileUtils.rm_rf(dest_dir)
|
9
|
+
FileUtils.mkdir_p(dest_dir)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_source_dir!
|
13
|
+
FileUtils.mkdir_p(source_dir) unless File.exists? source_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_layout!
|
17
|
+
File.write(source_dir('layout.erb'), "<%= content %>")
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_template!
|
21
|
+
File.write(source_dir('foo.erb'), "asd")
|
13
22
|
end
|
14
23
|
|
15
24
|
# ref: https://github.com/mojombo/jekyll/blob/master/test/helper.rb
|
@@ -20,8 +29,3 @@ end
|
|
20
29
|
def source_dir(*subdirs)
|
21
30
|
File.join(File.dirname(__FILE__), 'tmp/source', *subdirs)
|
22
31
|
end
|
23
|
-
|
24
|
-
def clear_dest
|
25
|
-
FileUtils.rm_rf(dest_dir)
|
26
|
-
FileUtils.mkdir_p(dest_dir)
|
27
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wormwood
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: commander
|
@@ -74,8 +74,8 @@ files:
|
|
74
74
|
- bin/wormwood
|
75
75
|
- lib/wormwood.rb
|
76
76
|
- lib/wormwood/version.rb
|
77
|
-
-
|
78
|
-
-
|
77
|
+
- spec/lib/wormwood/build_spec.rb
|
78
|
+
- spec/test_helper.rb
|
79
79
|
- wormwood.gemspec
|
80
80
|
homepage: http://github.com/erikeldridge/wormwood
|
81
81
|
licenses: []
|
@@ -104,5 +104,5 @@ summary: Wormwood watches for changes to a template directory ("./" by default),
|
|
104
104
|
the changed files (via Tilt), and writes the rendered output to an output directory
|
105
105
|
("./" by default).
|
106
106
|
test_files:
|
107
|
-
-
|
108
|
-
-
|
107
|
+
- spec/lib/wormwood/build_spec.rb
|
108
|
+
- spec/test_helper.rb
|