-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed simple conversion. Added (hopefully) helpful README
- Loading branch information
Showing
7 changed files
with
185 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard 'rspec', :version => 2 do | ||
watch(%r{^spec/.+_spec\.rb}) | ||
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
|
||
# # Rails example | ||
# watch('spec/spec_helper.rb') { "spec" } | ||
# watch('config/routes.rb') { "spec/routing" } | ||
# watch('app/controllers/application_controller.rb') { "spec/controllers" } | ||
# watch(%r{^spec/.+_spec\.rb}) | ||
# watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } | ||
# watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
# watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
guard 'markdown' do | ||
# must produce a string => "input/path/file.md|target/path/output/file.html" | ||
# The first regexp, watch (regexp) is used to match the files to be watched for changes | ||
# The second regexp is used to determine the input path of the changed file, and the desired output path | ||
# of the converted file, both built by the regexp matched against the detected changed file. | ||
# The goal is to create a string of the form "input/path/file.md|output/path/file.html", | ||
# i.e, both the input file path and the output file path separated by a pipe. | ||
guard 'markdown', :convert_on_start => true, :dry_run => true do | ||
# See README for info on the watch statement below | ||
# Will not convert while :dry_run is true. Once you're happy with your watch statements remove it | ||
watch (/source_dir\/(.+\/)*(.+\.)(md|markdown)/i) { |m| "source_dir/#{m[1]}#{m[2]}#{m[3]}|output_dir/#{m[1]}#{m[2]}html"} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Guard::Markdown # | ||
Markdown guard will watch your markdown documents for changes and convert them to lovely, semantic html. Yay! | ||
|
||
## Install ## | ||
|
||
You're going to need [Guard](https://github.com/guard/guard) too. | ||
|
||
Install with | ||
|
||
$ gem install guard-markdown | ||
|
||
Or add it to your Gemfile | ||
|
||
gem 'guard-markdown' | ||
|
||
## Usage ## | ||
|
||
Go see the [Guard usage doc](https://github.com/guard/guard#readme) for general instructions | ||
|
||
## The Guardfile - where the magic happens | ||
|
||
The Guardfile is where you define your desired input and output paths. | ||
Create it with: | ||
|
||
$ guard init markdown | ||
|
||
Then tweak the watch statements to your hearts content. It'll look a lot like this: | ||
|
||
guard 'markdown', :convert_on_start => true, :dry_run => true do | ||
watch (/source_dir\/(.+\/)*(.+\.)(md|markdown)/i) { |m| "source_dir/#{m[1]}#{m[2]}#{m[3]}|output_dir/#{m[1]}#{m[2]}html"} | ||
end | ||
|
||
The guard statement defines which guard your configuring and sets any optional parameters. | ||
|
||
* :convert_on_start - if true will run all conversions when you start the guard. Defaults to true | ||
* :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. | ||
|
||
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. | ||
|
||
watch (/source_dir\/(.+\/)*(.+\.)(md|markdown)/i) { |m| "source_dir/#{m[1]}#{m[2]}#{m[3]}|output_dir/#{m[1]}#{m[2]}html"} | ||
^ ------ input file pattern ----------- ^ ^ ---- input file path -------- ^|^ ----- output file path ---^ | ||
|
||
The "input file pattern" is a regular expression that is used to determine which files are watched by the guard. It'll be applied recursively to all files and folders starting in the current working directory. | ||
|
||
Any matches are passed into the block and used to construct the conversion command. The conversion command is a string containing the path to the source file and the desired path to the output file separated by a "|" | ||
|
||
I hope that makes sense :) | ||
|
||
|
||
|
||
## Have Fun ## | ||
|
||
Go see the other [great guards available](https://github.com/guard/guard/wiki/List-of-available-Guards) | ||
|
||
Oh yeah, I'm using [Kramdown](http://kramdown.rubyforge.org/) for the conversion engine. So if you want to know what markdown syntax it supports, [go here](http://kramdown.rubyforge.org/syntax.html) | ||
|
||
# TODO # | ||
|
||
* Simplify the required watch statement | ||
* Seems a little wasteful to have to recreate the input path in the regexp. Must find a way around it. | ||
* Allow the passing of Kramdown options into the guard | ||
* Allow the conversion of more doc types using Kramdown | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Guard | ||
module MarkdownVersion | ||
VERSION = "0.0.3" | ||
VERSION = "0.1.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters