guard-markdown 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -35,6 +35,17 @@ The guard statement defines which guard your configuring and sets any optional p
35
35
  * :convert_on_start - if true will run all conversions when you start the guard. Defaults to true
36
36
  * :dry_run - if true won't actually run the conversion process, but it will output the files being watched and the file it would write to. Use it to tweak your watch statements and when you're happy set it to false.
37
37
 
38
+ If you want to pass additional options directly to kramdown add them as an additional options hash to `kram_ops`.
39
+
40
+ For example to generate a table of contents consisting of headers 2 through 6 first make sure that something like the following is in your markdown source file. This serves as a placeholder which will be replaced with the table of contents. See: [Automatic Table of Contents Generation](http://kramdown.rubyforge.org/converter/html.html#toc).
41
+
42
+ * table of contents
43
+ {:toc}
44
+
45
+ Then include the following in the start of your guard markdown block:
46
+
47
+ :kram_ops_ => { :toc_levels => [2, 3, 4, 5, 6]}
48
+
38
49
  The watch statement - ok, it may look a little intimidating. You'll need to know your regular expressions. But this is what it's doing.
39
50
 
40
51
  watch (/source_dir\/(.+\/)*(.+\.)(md|markdown)/i) { |m| "source_dir/#{m[1]}#{m[2]}#{m[3]}|output_dir/#{m[1]}#{m[2]}html|optional_template.html.erb"}
@@ -65,6 +76,5 @@ Oh yeah, I'm using [Kramdown](http://kramdown.rubyforge.org/) for the conversion
65
76
 
66
77
  * Simplify the required watch statement
67
78
  * Seems a little wasteful to have to recreate the input path in the regexp. Must find a way around it.
68
- * Allow the passing of Kramdown options into the guard
69
79
  * Allow the conversion of more doc types using Kramdown
70
80
 
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'rspec', '~> 2.6'
27
27
  s.add_development_dependency 'guard-rspec'
28
28
  s.add_development_dependency 'growl'
29
+ s.add_development_dependency 'rake'
29
30
  end
@@ -1,17 +1,20 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
3
  require 'guard/watcher'
4
- require 'Kramdown'
4
+ require 'kramdown'
5
5
 
6
6
  module Guard
7
7
  class Markdown < Guard
8
8
  # Your code goes here...
9
+ attr_reader :kram_ops
9
10
  def initialize(watchers=[], options={})
10
11
  super
11
12
  @options = {
12
13
  :convert_on_start => true,
13
14
  :dry_run => false
14
15
  }.update(options)
16
+ @kram_ops = { :input => "kramdown", :output => "html" }
17
+ @kram_ops.update(@options[:kram_ops]) if @options[:kram_ops]
15
18
  end
16
19
 
17
20
  def start
@@ -42,10 +45,9 @@ module Guard
42
45
  target_path = output.gsub(reg,"\\1")
43
46
  FileUtils.mkpath target_path unless target_path.empty?
44
47
 
45
- kram_ops = { :input => "kramdown", :output => "html" }
46
- kram_ops.update({ :template => template }) unless template.nil?
48
+ @kram_ops.update({ :template => template }) unless template.nil?
47
49
 
48
- doc = Kramdown::Document.new(source, kram_ops).to_html
50
+ doc = Kramdown::Document.new(source, @kram_ops).to_html
49
51
 
50
52
 
51
53
  File.open(output, "w") do |f|
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module MarkdownVersion
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -28,6 +28,18 @@ describe "Guard-Markdown" do
28
28
  @subject.options[:convert_on_start].should be false
29
29
  @subject.options[:dry_run].should be true
30
30
  end
31
+ it "should also start with default kramdown options" do
32
+ @subject.kram_ops[:input].should match "kramdown"
33
+ @subject.kram_ops[:output].should match "html"
34
+ @subject.kram_ops[:toc_levels].should be nil
35
+ end
36
+ it "should accept additional kramdown options" do
37
+ @subject = Guard::Markdown.new([],{
38
+ :kram_ops => { :toc_levels => [2, 3, 4, 5, 6] } })
39
+ @subject.kram_ops[:input].should match "kramdown"
40
+ @subject.kram_ops[:output].should match "html"
41
+ @subject.kram_ops[:toc_levels].should =~ [2, 3, 4, 5, 6]
42
+ end
31
43
  end
32
44
 
33
45
  describe "start" do
@@ -106,6 +118,28 @@ describe "Guard-Markdown" do
106
118
  end
107
119
  end
108
120
 
121
+ describe "with a template file and additional kramdown options" do
122
+ it "should use the additional kramdown options and the template when converting the source file" do
123
+ file_double = double()
124
+ file_double.should_receive(:read).and_return("#Title")
125
+ File.should_receive(:open).with("input.md","rb").and_return(file_double)
126
+ kram_doc = double()
127
+ kram_doc.should_receive(:to_html)
128
+
129
+ Kramdown::Document.should_receive(:new).with("#Title", :input => "kramdown", :output => "html",
130
+ :toc_levels => [2, 3, 4, 5, 6], :template => "template.html.erb").and_return(kram_doc)
131
+
132
+ file_out = double()
133
+ FileUtils.should_receive(:mkpath)
134
+ File.should_receive(:open).with("output.html", "w").and_return(file_out)
135
+
136
+ Guard::UI.should_receive(:info).with("input.md >> output.html via template.html.erb")
137
+
138
+ @subject = Guard::Markdown.new([],{ :kram_ops => { :toc_levels => [2, 3, 4, 5, 6] } })
139
+ @subject.run_on_change(["input.md|output.html|template.html.erb"])
140
+ end
141
+ end
142
+
109
143
  describe "run_all" do
110
144
  it "should call run_on_change for all matching paths" do
111
145
  #mock Guard.watcher
@@ -133,4 +167,4 @@ def mock_kramdown text
133
167
  kram_doc = double()
134
168
  Kramdown::Document.should_receive(:new).with(text, :input => "kramdown", :output=> "html").and_return(kram_doc)
135
169
  kram_doc
136
- end
170
+ end
metadata CHANGED
@@ -1,93 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-markdown
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
4
5
  prerelease:
5
- version: 0.1.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Darren Wallace
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: guard
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70223889876720 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.2.2
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: kramdown
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70223889876720
25
+ - !ruby/object:Gem::Dependency
26
+ name: kramdown
27
+ requirement: &70223889875280 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
34
32
  version: 0.13.3
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: bundler
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70223889875280
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70223889873940 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: "1.0"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
46
44
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rspec
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70223889873940
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70223889871280 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
51
+ requirements:
54
52
  - - ~>
55
- - !ruby/object:Gem::Version
56
- version: "2.6"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
57
55
  type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: guard-rspec
61
56
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70223889871280
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-rspec
60
+ requirement: &70223889870540 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
68
66
  type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
67
+ prerelease: false
68
+ version_requirements: *70223889870540
69
+ - !ruby/object:Gem::Dependency
71
70
  name: growl
71
+ requirement: &70223889869540 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
72
78
  prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
79
+ version_requirements: *70223889869540
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: &70223889868320 !ruby/object:Gem::Requirement
74
83
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
79
88
  type: :development
80
- version_requirements: *id006
81
- description: Watches a source folder and converts markdown docs to html docs in a target folder
82
- email:
89
+ prerelease: false
90
+ version_requirements: *70223889868320
91
+ description: Watches a source folder and converts markdown docs to html docs in a
92
+ target folder
93
+ email:
83
94
  - wallace@midweekcrisis.com
84
95
  executables: []
85
-
86
96
  extensions: []
87
-
88
97
  extra_rdoc_files: []
89
-
90
- files:
98
+ files:
91
99
  - .gitignore
92
100
  - Gemfile
93
101
  - Guardfile
@@ -103,30 +111,32 @@ files:
103
111
  - spec/spec_helper.rb
104
112
  homepage: https://github.com/darwalenator/guard-markdown
105
113
  licenses: []
106
-
107
114
  post_install_message:
108
115
  rdoc_options: []
109
-
110
- require_paths:
116
+ require_paths:
111
117
  - lib
112
- required_ruby_version: !ruby/object:Gem::Requirement
118
+ required_ruby_version: !ruby/object:Gem::Requirement
113
119
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
125
+ - 0
126
+ hash: 1216822601046321711
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
128
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: "0"
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: 1216822601046321711
124
136
  requirements: []
125
-
126
137
  rubyforge_project: guard-markdown
127
- rubygems_version: 1.8.5
138
+ rubygems_version: 1.8.15
128
139
  signing_key:
129
140
  specification_version: 3
130
141
  summary: Markdown folder > html folder conversion
131
142
  test_files: []
132
-