markdown-tools 1.2.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f3adbb9b02a6e53a558a9a653c4456d5e01fa62
4
+ data.tar.gz: c761e052d58d2c46429483993a509af57fe319c9
5
+ SHA512:
6
+ metadata.gz: f2fc96086bb08604a9dd7796456771a3215ef62cdfe28e5b934abd34453f8b9ae8426ba7567266f2086af8af7feb3f7573af77d69da1f36dac92f79130667cb0
7
+ data.tar.gz: 50dc4014020252314ff4c18e3d2e45e5b766b71495f8ced19c396ab471c9675a31b3021ec9a4799758a8ab63c3e3e04002a3a590aea1ce57fcc8c2af7b8b1726
@@ -0,0 +1,3 @@
1
+ ### 0.1 / 2014-12-06
2
+
3
+ * Everything is new. First release
@@ -0,0 +1,10 @@
1
+ HISTORY.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ bin/markdown
6
+ lib/markdown/cli/gen.rb
7
+ lib/markdown/cli/opts.rb
8
+ lib/markdown/cli/runner.rb
9
+ lib/markdown/cli/version.rb
10
+ lib/markdown/tools.rb
@@ -0,0 +1,53 @@
1
+ # markdown-tools gem - markdown command line tools
2
+
3
+ * home :: [github.com/rubylibs/markdown-tools](https://github.com/rubylibs/markdown-tools)
4
+ * bugs :: [github.com/rubylibs/markdown-tools/issues](https://github.com/rubylibs/markdown-tools/issues)
5
+ * gem :: [rubygems.org/gems/markdown-tools](https://rubygems.org/gems/markdown-tools)
6
+ * rdoc :: [rubydoc.info/gems/markdown-tools](http://rubydoc.info/gems/markdown-tools)
7
+
8
+
9
+
10
+
11
+ ## Usage - Command Line
12
+
13
+ The `markdown-tools` gem includes a little command line tool. Try `markdown -h` for details:
14
+
15
+ markdown - Lets you convert plain text documents to hypertext with your Markdown engine of choice
16
+ and preprocessing text filters.
17
+
18
+ Usage: markdown [options] files_or_dirs
19
+ -o, --output PATH Output Path
20
+ -v, --verbose Show debug trace
21
+
22
+
23
+ Examples:
24
+ markdown # Process all documents in working folder (that is, .)
25
+ markdown quickref # Process document or folder using Markdown
26
+ markdown quickref.text # Process document using Markdown
27
+ markdown -o site quickref # Output documents to site folder
28
+
29
+ Note:
30
+ markdown server # Starts builtin markdown server
31
+ # (aliases for server include serve, service, s)
32
+
33
+
34
+
35
+ ## Install
36
+
37
+ Just install the gem:
38
+
39
+ $ gem install markdown-tools
40
+
41
+
42
+
43
+ ## License
44
+
45
+ The `markdown-tools` scripts are dedicated to the public domain.
46
+ Use it as you please with no restrictions whatsoever.
47
+
48
+
49
+ ## Questions? Comments?
50
+
51
+ Send them along to the
52
+ [Free Web Slide Show Alternatives (S5, S6, S9, Slidy And Friends) Forum/Mailing List](http://groups.google.com/group/webslideshow).
53
+ Thanks!
@@ -0,0 +1,31 @@
1
+ require 'hoe'
2
+ require './lib/markdown/cli/version.rb'
3
+
4
+ Hoe.spec 'markdown-tools' do
5
+
6
+ self.version = MarkdownCli::VERSION
7
+
8
+ self.summary = 'markdown-tools gem - markdown command line tools'
9
+ self.description = summary
10
+
11
+ self.urls = ['https://github.com/rubylibs/markdown-tools']
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'webslideshow@googlegroups.com'
15
+
16
+ self.extra_deps = [
17
+ ['markdown'],
18
+ ['markdown-service'],
19
+ ]
20
+
21
+ # switch extension to .markdown for gihub formatting
22
+ self.readme_file = 'README.md'
23
+ self.history_file = 'HISTORY.md'
24
+
25
+ self.licenses = ['Public Domain']
26
+
27
+ self.spec_extras = {
28
+ required_ruby_version: '>= 1.9.2'
29
+ }
30
+
31
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###################
4
+ # == DEV TIPS:
5
+ #
6
+ # For local testing run like:
7
+ #
8
+ # ruby -Ilib bin/markdown
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/markdown
13
+ #
14
+
15
+ require 'markdown/tools'
16
+
17
+ Markdown.main
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ module Markdown
4
+
5
+ class Gen
6
+
7
+ include TextUtils::Filter # include filters such as comments_percent_style, etc. (see textutils gem)
8
+
9
+ attr_reader :logger
10
+ attr_reader :opts
11
+
12
+ def initialize( logger, opts )
13
+ @logger = logger
14
+ @opts = opts
15
+ end
16
+
17
+ def create_doc( fn )
18
+ dirname = File.dirname( fn )
19
+ basename = File.basename( fn, '.*' )
20
+ extname = File.extname( fn )
21
+
22
+ logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
23
+
24
+ if opts.output_path == '.'
25
+ # expand output path in current dir
26
+ outpath = File.expand_path( dirname )
27
+ else
28
+ # expand output path in user supplied dir and make sure output path exists
29
+ outpath = File.expand_path( opts.output_path )
30
+ FileUtils.makedirs( outpath ) unless File.directory? outpath
31
+ end
32
+ logger.debug "outpath=#{outpath}"
33
+
34
+ # todo: add a -c option to commandline? to let you set cwd?
35
+
36
+
37
+ # change working dir to sourcefile dir (that is, dirname); push working folder/dir
38
+ newcwd = File.expand_path( dirname )
39
+ oldcwd = File.expand_path( Dir.pwd )
40
+
41
+ unless newcwd == oldcwd
42
+ logger.debug "oldcwd=>#{oldcwd}<, newcwd=>#{newcwd}<"
43
+ Dir.chdir( newcwd )
44
+ end
45
+
46
+ inname = "#{basename}#{extname}"
47
+ outname = "#{basename}.html"
48
+
49
+ logger.debug "inname=#{inname}, outname=#{outname}"
50
+
51
+ puts "*** #{inname} (#{dirname}) => #{outname} (#{(opts.output_path == '.') ? dirname : opts.output_path})..."
52
+
53
+ content = File.read( inname )
54
+
55
+ # step 1) run (optional) preprocessing text filters
56
+ Markdown.filters.each do |filter|
57
+ mn = filter.tr( '-', '_' ).to_sym # construct method name (mn)
58
+ content = send( mn, content ) # call filter e.g. include_helper_hack( content )
59
+ end
60
+
61
+ # step 2) convert light-weight markup to hypertext
62
+ content = Markdown.new( content ).to_html
63
+
64
+
65
+ ## todo: add Markdown.lib_options inspect/dump to banner
66
+
67
+ banner =<<EOS
68
+ <!-- ======================================================================
69
+ generated by #{Markdown.banner}
70
+ on #{Time.now} with Markdown engine '#{Markdown.lib}'
71
+ ====================================================================== -->
72
+ EOS
73
+
74
+ out = File.new( File.join( outpath, outname ), "w+" )
75
+ #### out << banner
76
+ out << content
77
+ out.flush
78
+ out.close
79
+
80
+ ## pop/restore working folder/dir
81
+ unless newcwd == oldcwd
82
+ logger.debug "oldcwd=>#{oldcwd}<, newcwd=>#{newcwd}<"
83
+ Dir.chdir( oldcwd )
84
+ end
85
+
86
+ end # method create_doc
87
+
88
+
89
+
90
+ end # class Gen
91
+ end # module Markdown
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ module Markdown
4
+
5
+ class Opts
6
+
7
+ def output_path=(value)
8
+ @output_path = value
9
+ end
10
+
11
+ def output_path
12
+ @output_path || '.'
13
+ end
14
+
15
+ end # class Opts
16
+ end # module Markdown
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module Markdown
5
+
6
+ class Runner
7
+
8
+ attr_reader :logger
9
+ attr_reader :opts
10
+
11
+ def initialize
12
+ @logger = Logger.new(STDOUT)
13
+ @logger.level = Logger::INFO
14
+ @opts = Opts.new
15
+ end
16
+
17
+ def has_markdown_extension?( fn )
18
+ dirname = File.dirname( fn )
19
+ basename = File.basename( fn, '.*' )
20
+ extname = File.extname( fn )
21
+ logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
22
+
23
+ return false if extname.empty? # no extension
24
+
25
+ Markdown.extnames.include?( extname.downcase )
26
+ end
27
+
28
+ def find_file_with_markdown_extension( fn )
29
+ dirname = File.dirname( fn )
30
+ basename = File.basename( fn, '.*' )
31
+ extname = File.extname( fn )
32
+ logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
33
+
34
+ Markdown.extnames.each do |e|
35
+ newname = File.join( dirname, "#{basename}#{e}" )
36
+ logger.debug "File.exists? #{newname}"
37
+ return newname if File.exists?( newname )
38
+ end # each extension (e)
39
+
40
+ nil # not found; return nil
41
+ end
42
+
43
+
44
+ def find_files( file_or_dir_or_pattern )
45
+
46
+ filtered_files = []
47
+
48
+ # assume pattern if includes * or ? or {} or []
49
+ if file_or_dir_or_pattern =~ /[*?{}\[\]]/
50
+ puts "searching glob pattern '#{file_or_dir_or_pattern}'..."
51
+ Dir.glob( file_or_dir_or_pattern ).each do |file|
52
+ if File.directory?( file ) # skip (sub)directories
53
+ puts " skipping folder '#{file}'..."
54
+ next
55
+ else
56
+ if has_markdown_extension?( file )
57
+ logger.debug " adding file '#{file}'..."
58
+ filtered_files << file
59
+ else
60
+ puts " skipping file '#{file}'..."
61
+ end
62
+ end
63
+ end
64
+ elsif File.directory?(file_or_dir_or_pattern)
65
+ puts "searching folder '#{file_or_dir_or_pattern}'..."
66
+ Dir.entries( file_or_dir_or_pattern ).each do |entry|
67
+ next if entry == '.' || entry == '..' # silently skip current and up dirs
68
+
69
+ if file_or_dir_or_pattern == '.'
70
+ file = entry
71
+ else # add dir (if not working dir)
72
+ file = File.join( file_or_dir_or_pattern, entry )
73
+ end
74
+
75
+ if File.directory?( file ) # skip (sub)directories
76
+ puts " skipping folder '#{file}'..."
77
+ next
78
+ else
79
+ if has_markdown_extension?( file )
80
+ logger.debug " adding file '#{file}'..."
81
+ filtered_files << file
82
+ else
83
+ puts " skipping file '#{file}'..."
84
+ end
85
+ end
86
+ end
87
+ else # assume it's a single file (check for missing extension)
88
+ if File.exists?( file_or_dir_or_pattern )
89
+ file = file_or_dir_or_pattern
90
+ if has_markdown_extension?( file )
91
+ logger.debug " adding file '#{file}'..."
92
+ filtered_files << file
93
+ else
94
+ puts " skipping file '#{file}'..."
95
+ end
96
+ else # check for existing file w/ missing extension
97
+ file = find_file_with_markdown_extension( file_or_dir_or_pattern )
98
+ if file.nil?
99
+ puts " skipping missing file '#{file_or_dir_or_pattern}{#{Markdown.extnames.join(',')}}'..."
100
+ else
101
+ logger.debug " adding file '#{file}'..."
102
+ filtered_files << file
103
+ end
104
+ end
105
+ end
106
+
107
+ filtered_files
108
+ end # find_files
109
+
110
+
111
+ def run( args )
112
+ opt=OptionParser.new do |cmd|
113
+
114
+ cmd.banner = "Usage: markdown [options] files_or_dirs"
115
+
116
+ cmd.on( '-o', '--output PATH', "Output Path (default is #{opts.output_path})" ) { |path| opts.output_path = path }
117
+
118
+ cmd.on( '-v', '--version', "Show version" ) do
119
+ puts Markdown.banner
120
+ exit
121
+ end
122
+
123
+ cmd.on( '--about', "(Debug) Show more version info" ) do
124
+ puts
125
+ puts Markdown.banner
126
+ puts
127
+
128
+ # dump settings
129
+ Markdown.dump
130
+ puts
131
+
132
+ exit
133
+ end
134
+
135
+ cmd.on( "--verbose", "(Debug) Show debug trace" ) do
136
+ logger.datetime_format = "%H:%H:%S"
137
+ logger.level = Logger::DEBUG
138
+ end
139
+
140
+ ## todo: add markdown.lib options (e.g. extensions,etc)
141
+
142
+ cmd.on_tail( "-h", "--help", "Show this message" ) do
143
+ puts <<EOS
144
+
145
+ markdown - Lets you convert plain text documents (#{Markdown.extnames.join(', ')}) to hypertext (.html) with your Markdown engine of choice (#{Markdown.lib}) and preprocessing text filters (#{Markdown.filters.join(', ')}).
146
+
147
+ #{cmd.help}
148
+
149
+ Examples:
150
+ markdown # Process all documents in working folder (that is, .)
151
+ markdown quickref # Process document or folder using Markdown
152
+ markdown quickref.text # Process document using Markdown
153
+ markdown -o site quickref # Output documents to site folder
154
+
155
+ Note:
156
+ markdown server # Starts builtin markdown server
157
+ # (aliases for server include serve, service, s)
158
+
159
+
160
+ Further information:
161
+ https://github.com/rubylibs/markdown-tools
162
+
163
+ EOS
164
+ exit
165
+ end
166
+ end
167
+
168
+ opt.parse!( args )
169
+
170
+ puts MarkdownCli.banner
171
+
172
+ # force loading of config
173
+ Markdown.lib
174
+
175
+ Markdown.dump if logger.level == Logger::DEBUG # dump settings if verbose/debug flag on
176
+
177
+
178
+ logger.debug "args.length: #{args.length}"
179
+ logger.debug "args: >#{args.join(',')}<"
180
+
181
+ if args.length == 1 && ['server', 'serve', 'service', 's' ].include?( args[0] )
182
+ # start service/server
183
+ # NB: server (HTTP service) not included in standard default require
184
+ require 'markdown/server'
185
+
186
+ Markdown::Server.run!
187
+ else
188
+
189
+ # if no file args given; default to working folder (that is, .)
190
+ args = ['.'] if args.length == 0
191
+
192
+ args.each do |arg|
193
+ files = find_files( arg )
194
+ files.each do |file|
195
+ Gen.new( logger, opts ).create_doc( file )
196
+ end
197
+ end
198
+ end
199
+
200
+ puts 'Done. Bye.'
201
+
202
+ end # method run
203
+
204
+ end # class Runner
205
+ end # module Markdown
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ module MarkdownCli
4
+
5
+ MAJOR = 1
6
+ MINOR = 2
7
+ PATCH = 0
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ "markdown-tools/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
16
+ end
17
+
18
+ def self.root
19
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
20
+ end
21
+
22
+ end # module MarkdownCli
23
+
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'markdown'
4
+ require 'markdown/service' # pull in markdown HTTP JSON service addon
5
+
6
+
7
+ # our own code
8
+
9
+ require 'markdown/cli/version' # note: let version always go first
10
+ require 'markdown/cli/gen'
11
+ require 'markdown/cli/opts'
12
+ require 'markdown/cli/runner'
13
+
14
+
15
+ module Markdown
16
+
17
+ def self.main
18
+
19
+ # allow env variable to set RUBYOPT-style default command line options
20
+ # e.g. -o site
21
+ markdownopt = ENV[ 'MARKDOWNOPT' ]
22
+
23
+ args = []
24
+ args += markdownopt.split if markdownopt
25
+ args += ARGV.dup
26
+
27
+ Runner.new.run(args)
28
+ end
29
+
30
+ end # module Markdown
31
+
32
+
33
+ Markdown.main if __FILE__ == $0
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: markdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: markdown-service
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.13'
69
+ description: markdown-tools gem - markdown command line tools
70
+ email: webslideshow@googlegroups.com
71
+ executables:
72
+ - markdown
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - HISTORY.md
76
+ - Manifest.txt
77
+ - README.md
78
+ files:
79
+ - HISTORY.md
80
+ - Manifest.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/markdown
84
+ - lib/markdown/cli/gen.rb
85
+ - lib/markdown/cli/opts.rb
86
+ - lib/markdown/cli/runner.rb
87
+ - lib/markdown/cli/version.rb
88
+ - lib/markdown/tools.rb
89
+ homepage: https://github.com/rubylibs/markdown-tools
90
+ licenses:
91
+ - Public Domain
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options:
95
+ - "--main"
96
+ - README.md
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 1.9.2
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: markdown-tools gem - markdown command line tools
115
+ test_files: []