markdown 0.1.0.beta1 → 0.1.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.
Files changed (3) hide show
  1. data/lib/markdown.rb +1 -1
  2. data/lib/markdown/gen.rb +130 -22
  3. metadata +8 -12
@@ -28,7 +28,7 @@ require 'markdown/gen'
28
28
 
29
29
  module Markdown
30
30
 
31
- VERSION = '0.1.0.beta1'
31
+ VERSION = '0.1.0'
32
32
 
33
33
  # version string for generator meta tag (includes ruby version)
34
34
  def self.banner
@@ -18,7 +18,6 @@ module Markdown
18
18
  end # class Opts
19
19
 
20
20
 
21
-
22
21
  class Gen
23
22
 
24
23
  attr_reader :logger
@@ -30,6 +29,19 @@ module Markdown
30
29
  @opts = Opts.new
31
30
  end
32
31
 
32
+
33
+ ### fix/todo:
34
+ # make configureable
35
+ DEFAULT_MARKDOWN_EXTENSIONS = [
36
+ '.markdown',
37
+ '.m',
38
+ '.mark',
39
+ '.mkdn',
40
+ '.md',
41
+ '.txt',
42
+ '.text' ]
43
+
44
+
33
45
  def with_output_path( dest, output_path )
34
46
  dest_full = File.expand_path( dest, output_path )
35
47
  logger.debug "dest_full=#{dest_full}"
@@ -64,23 +76,10 @@ module Markdown
64
76
  logger.debug "newcwd=#{newcwd}"
65
77
  Dir.chdir newcwd
66
78
  end
67
-
68
- if extname.empty? then
69
- extname = ".markdown" # default to .markdown
70
-
71
- [ '.markdown', '.m', '.mark', '.mkdn', '.md', '.txt', '.text' ].each do |e|
72
- logger.debug "File.exists? #{dirname}/#{basename}#{e}"
73
- if File.exists?( "#{dirname}/#{basename}#{e}" ) then
74
- extname = e
75
- logger.debug "extname=#{extname}"
76
- break
77
- end
78
- end # each extension (e)
79
- end
80
79
 
81
80
  inname = "#{dirname}/#{basename}#{extname}"
82
81
 
83
- puts "Reading document '#{basename}#{extname}'..."
82
+ puts "Reading document '#{basename}#{extname} (in folder #{dirname})'..."
84
83
 
85
84
 
86
85
  logger.debug "inname=#{inname}"
@@ -92,7 +91,7 @@ module Markdown
92
91
  content = Markdown.new( content ).to_html
93
92
 
94
93
  outname = "#{basename}.html"
95
- puts "Preparing #{outname}..."
94
+ puts "Preparing #{outname} (in folder #{outpath})..."
96
95
 
97
96
  out = File.new( with_output_path( outname, outpath ), "w+" )
98
97
  out << "<!-- ======================================================================\n"
@@ -104,7 +103,99 @@ module Markdown
104
103
  out.close
105
104
 
106
105
  end # method create_doc
106
+
107
+
108
+ def has_markdown_extension?( fn )
109
+ dirname = File.dirname( fn )
110
+ basename = File.basename( fn, '.*' )
111
+ extname = File.extname( fn )
112
+ logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
113
+
114
+ return false if extname.empty? # no extension
115
+
116
+ DEFAULT_MARKDOWN_EXTENSIONS.include?( extname.downcase )
117
+ end
107
118
 
119
+ def find_file_with_markdown_extension( fn )
120
+ dirname = File.dirname( fn )
121
+ basename = File.basename( fn, '.*' )
122
+ extname = File.extname( fn )
123
+ logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
124
+
125
+ DEFAULT_MARKDOWN_EXTENSIONS.each do |e|
126
+ logger.debug "File.exists? #{dirname}/#{basename}#{e}"
127
+ return "#{dirname}/#{basename}#{e}" if File.exists?( "#{dirname}/#{basename}#{e}" )
128
+ end # each extension (e)
129
+
130
+ nil # not found; return nil
131
+ end
132
+
133
+
134
+ def find_files( file_or_dir_or_pattern )
135
+
136
+ filtered_files = []
137
+
138
+ # assume pattern if includes * or ? or {} or []
139
+ if file_or_dir_or_pattern =~ /[*?{}\[\]]/
140
+ puts "searching glob pattern '#{file_or_dir_or_pattern}'..."
141
+ Dir.glob( file_or_dir_or_pattern ).each do |file|
142
+ if File.directory?( file ) # skip (sub)directories
143
+ puts " skipping folder '#{file}'..."
144
+ next
145
+ else
146
+ if has_markdown_extension?( file )
147
+ logger.debug " adding file '#{file}'..."
148
+ filtered_files << file
149
+ else
150
+ puts " skipping file '#{file}'..."
151
+ end
152
+ end
153
+ end
154
+ elsif File.directory?(file_or_dir_or_pattern)
155
+ puts "searching folder '#{file_or_dir_or_pattern}'..."
156
+ Dir.entries( file_or_dir_or_pattern ).each do |entry|
157
+ next if entry == '.' || entry == '..' # silently skip current and up dirs
158
+
159
+ if file_or_dir_or_pattern == '.'
160
+ file = entry
161
+ else # add dir (if not working dir)
162
+ file = File.join( file_or_dir_or_pattern, entry )
163
+ end
164
+
165
+ if File.directory?( file ) # skip (sub)directories
166
+ puts " skipping folder '#{file}'..."
167
+ next
168
+ else
169
+ if has_markdown_extension?( file )
170
+ logger.debug " adding file '#{file}'..."
171
+ filtered_files << file
172
+ else
173
+ puts " skipping file '#{file}'..."
174
+ end
175
+ end
176
+ end
177
+ else # assume it's a single file (check for missing extension)
178
+ if File.exists?( file_or_dir_or_pattern )
179
+ file = file_or_dir_or_pattern
180
+ if has_markdown_extension?( file )
181
+ logger.debug " adding file '#{file}'..."
182
+ filtered_files << file
183
+ else
184
+ puts " skipping file '#{file}'..."
185
+ end
186
+ else # check for existing file w/ missing extension
187
+ file = find_file_with_markdown_extension( file_or_dir_or_pattern )
188
+ if file.nil?
189
+ puts " skipping missing file '#{file_or_dir_or_pattern}{#{DEFAULT_MARKDOWN_EXTENSIONS.join(',')}}'..."
190
+ else
191
+ logger.debug " adding file '#{file}'..."
192
+ filtered_files << file
193
+ end
194
+ end
195
+ end
196
+
197
+ filtered_files
198
+ end # find_files
108
199
 
109
200
  def run( args )
110
201
  opt=OptionParser.new do |cmd|
@@ -116,19 +207,22 @@ module Markdown
116
207
  # todo: find different letter for debug trace switch (use v for version?)
117
208
  cmd.on( "-v", "--verbose", "Show debug trace" ) do
118
209
  logger.datetime_format = "%H:%H:%S"
119
- logger.level = Logger::DEBUG
210
+ logger.level = Logger::DEBUG
120
211
  end
121
212
 
213
+ ## todo: add #{Markdown.lib} to help message?? yes/no
214
+
122
215
  cmd.on_tail( "-h", "--help", "Show this message" ) do
123
216
  puts
124
- puts "Markdown is ..."
217
+ puts "markdown - Lets you convert plain text documents (#{DEFAULT_MARKDOWN_EXTENSIONS.join(', ')}) to hypertext (.html) with your Markdown engine of choice."
125
218
  puts
126
219
  puts cmd.help
127
220
  puts
128
221
  puts "Examples:"
129
- puts " markdown microformats"
130
- puts " markdown microformats.text # Process slides using Markdown"
131
- puts " markdown -o site microformats # Output slideshow to slides folder"
222
+ puts " markdown # Process all documents in working folder (that is, .)"
223
+ puts " markdown ruby_tut # Process document or folder using Markdown"
224
+ puts " markdown ruby_tut.text # Process document using Markdown"
225
+ puts " markdown -o site ruby_tut # Output documents to site folder"
132
226
  puts
133
227
  puts "Further information:"
134
228
  puts " http://geraldb.github.com/markdown"
@@ -139,8 +233,22 @@ module Markdown
139
233
  opt.parse!( args )
140
234
 
141
235
  puts Markdown.banner
236
+
237
+ # force loading of config
238
+ Markdown.lib
239
+
240
+ logger.debug "args.length: #{args.length}"
241
+ logger.debug "args: >#{args.join(',')}<"
242
+
243
+ # if no file args given; default to working folder (that is, .)
244
+ args = ['.'] if args.length == 0
142
245
 
143
- args.each { |fn| create_doc( fn ) }
246
+ args.each do |arg|
247
+ files = find_files( arg )
248
+ files.each do |file|
249
+ create_doc( file )
250
+ end
251
+ end
144
252
 
145
253
  puts "Done."
146
254
 
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 321068176
5
- prerelease: 6
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 0
10
- - beta
11
- - 1
12
- version: 0.1.0.beta1
10
+ version: 0.1.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Gerald Bauer
@@ -112,18 +110,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
110
  required_rubygems_version: !ruby/object:Gem::Requirement
113
111
  none: false
114
112
  requirements:
115
- - - ">"
113
+ - - ">="
116
114
  - !ruby/object:Gem::Version
117
- hash: 25
115
+ hash: 3
118
116
  segments:
119
- - 1
120
- - 3
121
- - 1
122
- version: 1.3.1
117
+ - 0
118
+ version: "0"
123
119
  requirements: []
124
120
 
125
121
  rubyforge_project: markdown
126
- rubygems_version: 1.8.17
122
+ rubygems_version: 1.8.24
127
123
  signing_key:
128
124
  specification_version: 3
129
125
  summary: Markdown Engine Wrapper - Use Your Markdown Library of Choice