-
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.
simple markdown to html working. Only partial testing of file write tho
- Loading branch information
Showing
6 changed files
with
109 additions
and
61 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 |
---|---|---|
|
@@ -7,21 +7,23 @@ Gem::Specification.new do |s| | |
s.version = Guard::MarkdownVersion::VERSION | ||
s.authors = ["Darren Wallace"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "http://www.cdsm.co.uk" | ||
s.summary = %q{Markdown folder > html folder conversion} | ||
s.homepage = "" | ||
s.summary = %q{Markdown folder > html folder conversion} | ||
s.description = %q{Watches a source folder and converts markdown docs to html docs in a target folder} | ||
|
||
s.rubyforge_project = "guard-krammer" | ||
s.rubyforge_project = "guard-markdown" | ||
|
||
# s.files = `git ls-files`.split("\n") # Bundler created line | ||
s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md] # copied from guard examples | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
# s.files = `git ls-files`.split("\n") | ||
s.files = Dir.glob('{lib}/**/*') | ||
#s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
#s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
s.add_dependency 'guard', '>= 0.2.2' | ||
s.add_dependency 'guard', '>= 0.2.2' | ||
s.add_dependency 'kramdown', '~> 0.13.3' | ||
|
||
s.add_development_dependency 'bundler', '~> 1.0' | ||
s.add_development_dependency 'rspec', '~> 2.5' | ||
end | ||
s.add_development_dependency 'rspec', '~> 2.6' | ||
s.add_development_dependency 'guard-rspec' | ||
s.add_development_dependency 'growl' | ||
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 |
---|---|---|
@@ -1,53 +1,42 @@ | ||
require "krammer/version" | ||
|
||
require 'guard' | ||
require 'guard/guard' | ||
require 'guard/watcher' | ||
require 'Kramdown' | ||
|
||
module Guard | ||
class Krammer < Guard | ||
|
||
module Guard | ||
class Markdown < Guard | ||
# Your code goes here... | ||
def initialize(watchers=[], options={}) | ||
super | ||
super | ||
# init stuff here, thx! | ||
end | ||
|
||
# ================= | ||
# = Guard methods = | ||
# ================= | ||
|
||
# If one of those methods raise an exception, the Guard::GuardName instance | ||
# will be removed from the active guards. | ||
|
||
# Called once when Guard starts | ||
# Please override initialize method to init stuff | ||
def start | ||
true | ||
end | ||
|
||
# Called on Ctrl-C signal (when Guard quits) | ||
def stop | ||
true | ||
end | ||
|
||
# Called on Ctrl-Z signal | ||
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/... | ||
def reload | ||
true | ||
end | ||
|
||
# Called on Ctrl-\ signal | ||
# This method should be principally used for long action like running all specs/tests/... | ||
end | ||
|
||
def run_all | ||
true | ||
files = Dir.glob("**/*.*") | ||
targets = Watcher.match_files(self, files) | ||
#puts "Running changes on these paths: #{targets}" | ||
run_on_change targets | ||
end | ||
|
||
# Called on file(s) modifications | ||
def run_on_change(pathss) | ||
def run_on_change(paths) | ||
paths.each do |path| | ||
puts path | ||
input, output = path.split("|") | ||
puts "#{input} >> #{output}" | ||
source = File.open(input,"rb").read | ||
|
||
# make sure directory path exists | ||
reg = /(.+\/).+\.\w+/i | ||
target_path = output.gsub(reg,"\\1") | ||
FileUtils.mkpath target_path unless target_path.empty? | ||
|
||
doc = Kramdown::Document.new(source, :input => "markdown").to_html | ||
|
||
File.open(output, "w") do |f| | ||
f.puts(doc) | ||
end | ||
end | ||
true | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Guard | ||
module MarkdownVersion | ||
VERSION = "0.0.1" | ||
VERSION = "0.0.3" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'spec_helper' | ||
require 'Kramdown' | ||
require "guard/watcher" | ||
|
||
describe "Guard-Markdown" do | ||
|
||
before(:each) do | ||
@subject = Guard::Markdown.new | ||
@input_paths = ["input1.md","input2.markdown","dir1/dir2/input3.md"] | ||
@output_paths = ["output1.html", "output2.html", "dir1/dir2/output3.html"] | ||
@changed_paths = [] | ||
@input_paths.each_index do |i| | ||
@changed_paths << "#{@input_paths[i]}|#{@output_paths[i]}" | ||
end | ||
end | ||
|
||
describe "run_on_change" do | ||
it "should read the changed files markdown and convert it to html " do | ||
@input_paths.each_index do |i| | ||
#mock file read | ||
file_double = double() | ||
file_double.should_receive(:read).and_return("#Title") | ||
File.should_receive(:open).with(@input_paths[i],"rb").and_return(file_double) | ||
|
||
mock_kramdown("#Title").should_receive(:to_html).and_return("<h1>Title</h1>") | ||
|
||
#mock file write | ||
file_out = double() | ||
File.should_receive(:open).with(@output_paths[i], "w").and_return(file_out) | ||
|
||
#TODO Not sure how to test actually writing to the file | ||
|
||
end | ||
@subject.run_on_change(@changed_paths) | ||
end | ||
end | ||
|
||
# describe "run_all" do | ||
# it "should call run_on_change for all matching paths" do | ||
# #mock Guard.watcher | ||
# mock_watch = double() | ||
# | ||
# #mock Dir | ||
# Dir.should_receive(:glob).with("**/*.*").and_return(@input_paths) | ||
# | ||
# subject = Guard::Markdown.new(mock_watch) | ||
# | ||
# #Guard::Watcher should handle the matching and path manipulation | ||
# ## TODO the following line throws an uninitilizd const error Guard::Guard::Watcher -> don't know why. It'll have to go untested for now | ||
# Watcher.should_receive(:match_files).with(subject, mock_watch).and_return(@changed_paths) | ||
# | ||
# subject.should_receive(:run_on_change).with(@changed_paths) | ||
# | ||
# subject.run_all | ||
# end | ||
# end | ||
end | ||
|
||
private | ||
|
||
def mock_kramdown text | ||
kram_doc = double() | ||
Kramdown::Document.should_receive(:new).with(text, :input => "markdown").and_return(kram_doc) | ||
kram_doc | ||
end |
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
require 'guard/markdown' | ||
ENV["GUARD_ENV"] = 'test' |