guard-redcarpet 0.0.1
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/.gitignore +4 -0
- data/.rvmrc +55 -0
- data/Gemfile +4 -0
- data/LICENSE +18 -0
- data/README.md +95 -0
- data/Rakefile +1 -0
- data/guard-redcarpet.gemspec +25 -0
- data/lib/guard/redcarpet.rb +63 -0
- data/lib/guard/redcarpet/templates/Guardfile +4 -0
- data/lib/guard/redcarpet/version.rb +5 -0
- data/spec/guard/redcarpet_spec.rb +80 -0
- data/spec/spec_helper.rb +14 -0
- metadata +91 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-head@guard-redcarpet"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]]
|
45
|
+
# then
|
46
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
47
|
+
# fi
|
48
|
+
|
49
|
+
# If you use bundler, this might be useful to you:
|
50
|
+
# if command -v bundle && [[ -s Gemfile ]]
|
51
|
+
# then
|
52
|
+
# bundle
|
53
|
+
# fi
|
54
|
+
|
55
|
+
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2011 Michael-Keith Bernard
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Guard::Redcarpet
|
2
|
+
|
3
|
+
[Guard](https://github.com/guard/guard) extension for Markdown using the
|
4
|
+
[Redcarpet](https://github.com/tanoku/redcarpet) gem. There is an existing
|
5
|
+
[guard-markdown](https://github.com/darwalenator/guard-markdown) gem, but it
|
6
|
+
uses Kramdown.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
This gem is an extension of Guard.
|
11
|
+
|
12
|
+
Installation (command-line):
|
13
|
+
|
14
|
+
gem install guard-redcarpet
|
15
|
+
|
16
|
+
Or via your Gemfile:
|
17
|
+
|
18
|
+
gem 'guard-redcarpet'
|
19
|
+
|
20
|
+
Add the template to your Guardfile:
|
21
|
+
|
22
|
+
guard init redcarpet
|
23
|
+
|
24
|
+
## Options
|
25
|
+
|
26
|
+
You should familiarize yourself with the Redcarpet documentation before
|
27
|
+
exploring some of the advanced features of this gem.
|
28
|
+
|
29
|
+
### Output directory
|
30
|
+
|
31
|
+
The default Guard template watches for .html.md and .html.markdown files:
|
32
|
+
|
33
|
+
guard 'redcarpet' do
|
34
|
+
watch(/^.+(\.html\.markdown)$/)
|
35
|
+
watch(/^.+(\.html\.md)$/)
|
36
|
+
end
|
37
|
+
|
38
|
+
You can overried the output directory with the `output` option:
|
39
|
+
|
40
|
+
guard 'redcarpet', :output => 'compiled' do
|
41
|
+
watch(/^.+(\.html\.markdown)$/)
|
42
|
+
watch(/^.+(\.html\.md)$/)
|
43
|
+
end
|
44
|
+
|
45
|
+
### Markdown and Render options
|
46
|
+
|
47
|
+
Options for the `Redcarpet::Markdown` and `Redcarpet::Render::HTML` can be
|
48
|
+
provided via the `markdown_options` and `render_options` options respectively.
|
49
|
+
|
50
|
+
guard 'redcarpet', :markdown_options => { :strikethrough => true } do
|
51
|
+
watch(/^.+(\.html\.markdown)$/)
|
52
|
+
watch(/^.+(\.html\.md)$/)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
guard 'redcarpet', :render_options => { :no_links => true } do
|
57
|
+
watch(/^.+(\.html\.markdown)$/)
|
58
|
+
watch(/^.+(\.html\.md)$/)
|
59
|
+
end
|
60
|
+
|
61
|
+
Consult the Redcarpet 2.0 documentation for details.
|
62
|
+
|
63
|
+
## Special Thanks
|
64
|
+
|
65
|
+
Much of the code for this gem was a direct port of the [guard-haml
|
66
|
+
gem](https://github.com/manufaktor/guard-haml) by [Immanuel
|
67
|
+
Häussermann](https://github.com/manufaktor)
|
68
|
+
|
69
|
+
## Contribute
|
70
|
+
|
71
|
+
* Hosted on [Github:
|
72
|
+
guard-redcarpet](https://github.com/SegFaultAX/guard-redcarpet)
|
73
|
+
* Report issues, questions, or comments to the [issue
|
74
|
+
tracker](https://github.com/SegFaultAX/guard-redcarpet/issues)
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
Copyright (c) 2011 Michael-Keith Bernard
|
79
|
+
|
80
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
81
|
+
this software and associated documentation files (the "Software"), to deal in
|
82
|
+
the Software without restriction, including without limitation the rights to
|
83
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
84
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
85
|
+
subject to the following conditions:
|
86
|
+
|
87
|
+
The above copyright notice and this permission notice shall be included in all
|
88
|
+
copies or substantial portions of the Software.
|
89
|
+
|
90
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
91
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
92
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
93
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
94
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
95
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'guard/redcarpet/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "guard-redcarpet"
|
7
|
+
s.version = Guard::RedcarpetVersion::VERSION
|
8
|
+
s.authors = ["Michael-Keith Bernard"]
|
9
|
+
s.email = ["mkbernard.dev@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/SegFaultAX/guard-redcarpet"
|
11
|
+
s.summary = %q{Guard for Redcarpet}
|
12
|
+
s.description = %q{Compiles file.html.md and file.html.markdown files to file.html using Redcarpet gem.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "guard-redcarpet"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
s.add_runtime_dependency "redcarpet", ">= 2.0.0b5"
|
24
|
+
s.add_runtime_dependency "guard", ">= 0.8.8"
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
require 'redcarpet'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Redcarpet < Guard
|
8
|
+
|
9
|
+
def initialize(watchers = [], options = {})
|
10
|
+
super(watchers, {
|
11
|
+
:notifications => true
|
12
|
+
}.merge(options))
|
13
|
+
@watchers, @options = watchers, options
|
14
|
+
end
|
15
|
+
|
16
|
+
def compile_file(file)
|
17
|
+
begin
|
18
|
+
compile_markdown(File.new(file).read)
|
19
|
+
rescue StandardError => e
|
20
|
+
::Guard::UI.info "Redcarpet File Error: #{e}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def compile_markdown(content)
|
25
|
+
begin
|
26
|
+
render = ::Redcarpet::Render::HTML.new(@options[:render_options] || {})
|
27
|
+
markdown = ::Redcarpet::Markdown.new(render, (@options[:markdown_options] || {}))
|
28
|
+
markdown.render content
|
29
|
+
rescue StandardError => e
|
30
|
+
::Guard::UI.info "Redcarpet Error: #{e}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_output(file)
|
35
|
+
file_dir = File.dirname(file)
|
36
|
+
file_dir = File.join(@options[:output], file_dir) if @options[:output]
|
37
|
+
file_name = File.basename(file).split(".")[0..-2].join(".") # remove extension
|
38
|
+
|
39
|
+
file_dir == '' ? file_name : File.join(file_dir, file_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_all
|
43
|
+
run_on_change Watcher.match_files(self, Dir.glob(File.join("**", "*.*")))
|
44
|
+
end
|
45
|
+
|
46
|
+
def run_on_change(paths)
|
47
|
+
paths.each do |file|
|
48
|
+
output_file = get_output file
|
49
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
50
|
+
File.open(output_file, 'w') { |f| f.write(compile_file(file)) }
|
51
|
+
::Guard::UI.info "# compiled markdown in '#{file}' to html in '#{output_file}'"
|
52
|
+
::Guard::Notifier.notify("# compiled markdown in #{file}", :title => "Guard::Redcarpet", :image => :success) if @options[:notifications]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def notify(changed_files)
|
57
|
+
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
58
|
+
paths = Watcher.match_files(guard, changed_files)
|
59
|
+
guard.run_on_change paths unless paths.empty?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::Redcarpet do
|
4
|
+
subject { Guard::Redcarpet.new }
|
5
|
+
|
6
|
+
describe "run all" do
|
7
|
+
it "should re-compile all files being watched" do
|
8
|
+
Guard::Redcarpet.stub(:run_on_change).with([]).and_return([])
|
9
|
+
Guard.stub(:guards).and_return([subject])
|
10
|
+
subject.run_all
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "compiling markdown" do
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "getting output" do
|
19
|
+
context "default" do
|
20
|
+
it "should return test/index.html.md as test/index.html" do
|
21
|
+
subject.get_output("test/index.html.md").should eq("test/index.html")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return test/index.html.markdown as test/index.html" do
|
25
|
+
subject.get_output("test/index.html.markdown").should eq("test/index.html")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with output option" do
|
30
|
+
before :each do
|
31
|
+
subject.options[:output] = "demo/output"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return test/index.html.md as demo/output/test/index.html" do
|
35
|
+
subject.get_output("test/index.html.md").should eq("demo/output/test/index.html")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return test/index.html.markdown as demo/output/test/index.html" do
|
39
|
+
subject.get_output("test/index.html.markdown").should eq("demo/output/test/index.html")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "compiling markdown" do
|
45
|
+
context "default" do
|
46
|
+
it "should use default html renderer" do
|
47
|
+
subject.compile_markdown("# Title").should eq("<h1>Title</h1>\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "markdown options" do
|
52
|
+
before :each do
|
53
|
+
subject.options[:markdown_options] = { :strikethrough => true }
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should use markdown options, if provided" do
|
57
|
+
subject.compile_markdown("~~blah~~").should eq("<p><del>blah</del></p>\n")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "render options" do
|
62
|
+
before :each do
|
63
|
+
subject.options[:render_options] = { :no_links => true }
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should use markdown options, if provided" do
|
67
|
+
subject.compile_markdown("[G](http://www.google.com)").should eq("<p>[G](http://www.google.com)</p>\n")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'building markdown to html' do
|
73
|
+
it 'should notify other guards upon completion' do
|
74
|
+
other_guard = mock('guard')
|
75
|
+
other_guard.should_receive(:watchers).and_return([])
|
76
|
+
Guard.stub(:guards).and_return([subject, other_guard])
|
77
|
+
subject.notify([])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'guard/redcarpet'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.color_enabled = true
|
6
|
+
config.filter_run :focus => true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
|
9
|
+
config.before(:each) do
|
10
|
+
ENV["GUARD_ENV"] = 'test'
|
11
|
+
@fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
|
12
|
+
@lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-redcarpet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael-Keith Bernard
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-30 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &21104300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *21104300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redcarpet
|
27
|
+
requirement: &21103800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0b5
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *21103800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard
|
38
|
+
requirement: &21103300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.8.8
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *21103300
|
47
|
+
description: Compiles file.html.md and file.html.markdown files to file.html using
|
48
|
+
Redcarpet gem.
|
49
|
+
email:
|
50
|
+
- mkbernard.dev@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- guard-redcarpet.gemspec
|
62
|
+
- lib/guard/redcarpet.rb
|
63
|
+
- lib/guard/redcarpet/templates/Guardfile
|
64
|
+
- lib/guard/redcarpet/version.rb
|
65
|
+
- spec/guard/redcarpet_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: https://github.com/SegFaultAX/guard-redcarpet
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project: guard-redcarpet
|
87
|
+
rubygems_version: 1.8.9
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Guard for Redcarpet
|
91
|
+
test_files: []
|