guard-toc 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+
7
+ ## MAC OS
8
+ .DS_Store
9
+ .Trashes
10
+ .com.apple.timemachine.supported
11
+ .fseventsd
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-krammer.gemspec
4
+ gemspec
data/LICENSE ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Guard::Toc #
2
+ Toc guard will watch a folder for changes and add each of the files in the specified folder to a specified file as links.
3
+
4
+ ## Install ##
5
+
6
+ You're going to need [Guard](https://github.com/guard/guard) too.
7
+
8
+ Install with
9
+
10
+ $ gem install guard-toc
11
+
12
+ Or add it to your Gemfile
13
+
14
+ gem 'guard-toc'
15
+
16
+ ## Usage ##
17
+
18
+ Go see the [Guard usage doc](https://github.com/guard/guard#readme) for general instructions
19
+
20
+ ## The Guardfile - where the magic happens
21
+
22
+ The Guardfile is where you define your desired input and output paths.
23
+ Create it with:
24
+
25
+ $ guard init toc
26
+
27
+ Then tweak the watch statements to your hearts content. It'll look a lot like this:
28
+
29
+ guard 'toc', :convert_on_start => true, :dry_run => true do
30
+ # Will not convert while :dry_run is true. Once you're happy with your watch statements remove it
31
+ watch (/source_dir\/(.+\/)*(.+\.)(html_or_other_extension)/i) {"input_dir|output_dir|output_file|path_to_optional_template.html.erb"}
32
+ end
33
+
34
+ The guard statement defines which guard your configuring and sets any optional parameters.
35
+
36
+ * :convert_on_start - if true will run all conversions when you start the guard. Defaults to true
37
+ * :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.
38
+
39
+ ## Have Fun ##
40
+
41
+ Go see the other [great guards available](https://github.com/guard/guard/wiki/List-of-available-Guards)
42
+
43
+ # TODO #
44
+
45
+ * Test
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/guard-toc.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/toc/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-toc"
7
+ s.version = Guard::TocVersion::VERSION
8
+ s.authors = ["Jon Kinney"]
9
+ s.email = ["jonkinney@gmail.com"]
10
+ s.homepage = "https://github.com/j2fly/guard-toc"
11
+ s.summary = %q{Markdown folder > html folder conversion}
12
+ s.description = %q{Watches a source folder and converts markdown docs to html docs in a target folder}
13
+
14
+ s.rubyforge_project = "guard-toc"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ # s.files = Dir.glob('{lib}/**/*')
18
+ #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'guard', '>= 0.2.2'
23
+ s.add_dependency 'kramdown', '~> 0.13.3'
24
+ end
data/lib/guard/toc.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/watcher'
4
+ require 'Kramdown'
5
+
6
+ module Guard
7
+ class Toc < Guard
8
+
9
+ def initialize(watchers=[], options={})
10
+ super
11
+ @options = {
12
+ :convert_on_start => true,
13
+ :dry_run => false
14
+ }.update(options)
15
+ end
16
+
17
+ def start
18
+ UI.info("Guard::Toc is building a list of links\n")
19
+ run_all if @options[:convert_on_start]
20
+ end
21
+
22
+ def run_all
23
+ files = Dir.glob("**/*.*")
24
+ targets = Watcher.match_files(self, files)
25
+ run_on_change targets
26
+ end
27
+
28
+ def run_on_change(paths)
29
+ paths.uniq.each do |path|
30
+ input, output, outfile, template = path.split("|")
31
+ info = "Created '#{output}/#{outfile}' from the directory '#{input}'"
32
+ info = "#{info} via '#{template}'" unless template.nil?
33
+ UI.info info
34
+ unless @options[:dry_run]
35
+ # make sure directory path exists
36
+ reg = /(.+\/).+\.\w+/i
37
+ target_path = output.gsub(reg,"\\1")
38
+ FileUtils.mkpath target_path unless target_path.empty?
39
+
40
+ full_file_list = Dir.entries(input)
41
+
42
+ # Trim "." and ".." off of the file list
43
+ file_list = full_file_list[2,full_file_list.length-2]
44
+
45
+ # Don't list the index.html file (or whatever it is named) in itself
46
+ if input==output
47
+ file_list = file_list - ["#{outfile}"]
48
+ end
49
+
50
+ source = "<ul class='toc_links'>\n"
51
+ if file_list.length > 0
52
+ file_list.each do |file|
53
+ file_name = file.gsub(/.html/ix,'').gsub(/_/ix,' ').capitalize
54
+ source += " <li><a href='#{output}/#{file}'>#{file_name}</a></li>\n"
55
+ end
56
+ end
57
+ source += " </ul>"
58
+
59
+ kram_ops = { :input => "kramdown", :output => "html" }
60
+ kram_ops.update({ :template => template }) unless template.nil?
61
+
62
+ doc = Kramdown::Document.new(source, kram_ops).to_html
63
+
64
+ File.open("#{output}/#{outfile}", "w") do |f|
65
+ f.write(doc)
66
+ end
67
+ end
68
+ end
69
+ true
70
+ end
71
+
72
+
73
+ end
74
+ end
@@ -0,0 +1,4 @@
1
+ guard 'toc', :convert_on_start => true, :dry_run => true do
2
+ # Will not convert while :dry_run is true. Once you're happy with your watch statements remove it
3
+ watch (/source_dir\/(.+\/)*(.+\.)(html_or_other_extension)/i) {"input_dir|output_dir|output_file|path_to_optional_template.html.erb"}
4
+ end
@@ -0,0 +1,45 @@
1
+ # Guard::Toc #
2
+ Toc guard will watch a folder for changes and add each of the files in the specified folder to a specified file as links.
3
+
4
+ ## Install ##
5
+
6
+ You're going to need [Guard](https://github.com/guard/guard) too.
7
+
8
+ Install with
9
+
10
+ $ gem install guard-toc
11
+
12
+ Or add it to your Gemfile
13
+
14
+ gem 'guard-toc'
15
+
16
+ ## Usage ##
17
+
18
+ Go see the [Guard usage doc](https://github.com/guard/guard#readme) for general instructions
19
+
20
+ ## The Guardfile - where the magic happens
21
+
22
+ The Guardfile is where you define your desired input and output paths.
23
+ Create it with:
24
+
25
+ $ guard init toc
26
+
27
+ Then tweak the watch statements to your hearts content. It'll look a lot like this:
28
+
29
+ guard 'toc', :convert_on_start => true, :dry_run => true do
30
+ # Will not convert while :dry_run is true. Once you're happy with your watch statements remove it
31
+ watch (/source_dir\/(.+\/)*(.+\.)(html_or_other_extension)/i) {"input_dir|output_dir|output_file|path_to_optional_template.html.erb"}
32
+ end
33
+
34
+ The guard statement defines which guard your configuring and sets any optional parameters.
35
+
36
+ * :convert_on_start - if true will run all conversions when you start the guard. Defaults to true
37
+ * :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.
38
+
39
+ ## Have Fun ##
40
+
41
+ Go see the other [great guards available](https://github.com/guard/guard/wiki/List-of-available-Guards)
42
+
43
+ # TODO #
44
+
45
+ * Test
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module TocVersion
3
+ VERSION = "0.1.4"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-toc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Kinney
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: &70143896591140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70143896591140
25
+ - !ruby/object:Gem::Dependency
26
+ name: kramdown
27
+ requirement: &70143896589700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.13.3
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70143896589700
36
+ description: Watches a source folder and converts markdown docs to html docs in a
37
+ target folder
38
+ email:
39
+ - jonkinney@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - guard-toc.gemspec
50
+ - lib/guard/toc.rb
51
+ - lib/guard/toc/templates/Guardfile
52
+ - lib/guard/toc/templates/README.md
53
+ - lib/guard/toc/version.rb
54
+ homepage: https://github.com/j2fly/guard-toc
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project: guard-toc
74
+ rubygems_version: 1.8.10
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Markdown folder > html folder conversion
78
+ test_files: []