markdown_ruby_documentation 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00ade506279b6b5d39ffa42bb4fc50b61d255222
4
- data.tar.gz: c8426d9d8b851257d312552e13b6c84198b972b5
3
+ metadata.gz: e8c6f0e6b1c0fb7528b57ad280a000931265d2f2
4
+ data.tar.gz: 77ffedcd22721423e8467e5ffe01bb75fb80d4b7
5
5
  SHA512:
6
- metadata.gz: 1473d3b33e26b1b26b818281d8d9c15112aa63840bad2c0e1b56de1413ddad1166c3f954acf2b41f1ab402d865c5bb6616943ad1609b1df69c2cfc0106b896ac
7
- data.tar.gz: c41fc56eee17895ec7ee5f156ab3481b0ea6557aea8ddec81f55116fe67de990f099e684f2f1a5010f7b661c285a61b46a478e5b89a078c30dab190b71d2cc76
6
+ metadata.gz: 29f309277dc2b1bbcf9889b6163a38353de6fd891190c216e230b8224d7847247583971c813edbb33a270ca2b14d25f68564eecd1a6e123f7202618c4d377945
7
+ data.tar.gz: 06d6fdc408865c05d96b473468f933428c532d34153da397a6c9c68b3bf9b00d1be619c897a02850afa5a0badbb6de11fea16bda7263e0f7a7f7366b26c338d4
data/README.md CHANGED
@@ -98,18 +98,18 @@ Converts case statements and if statements to bulleted markdown
98
98
  `example ruby_to_markdown(ruby_operators_to_english: { proc: ->(replacement, match) { "do some alteration" }})`
99
99
 
100
100
  **processors**
101
- * readable_ruby_numbers
102
- * pretty_early_return
103
- * convert_early_return_to_if_else
104
- * ternary_to_if_else
105
- * ruby_if_statement_to_md
106
- * ruby_case_statement_to_md
101
+ * readable_ruby_numbers, options: proc(ruby_number_object, number_as_string)
102
+ * pretty_early_return, options: proc(replacement, match)
103
+ * convert_early_return_to_if_else, options: proc(replacement, match)
104
+ * ternary_to_if_else, options: proc(replacement, match)
105
+ * ruby_if_statement_to_md, options: proc(replacement, match)
106
+ * ruby_case_statement_to_md, options: proc(replacement, match)
107
107
  * ruby_operators_to_english, options: proc(replacement, match)
108
108
  * methods_as_local_links, options: method_to_class: { method_name => OwningConstant }
109
- * question_mark_method_format
110
- * remove_end_keyword
111
- * constants_with_name_and_value
112
- * remove_memoized_vars
109
+ * question_mark_method_format, options: proc(replacement, match)
110
+ * remove_end_keyword, options: proc(replacement, match)
111
+ * constants_with_name_and_value, options: proc(replacement, match, opt={})
112
+ * remove_memoized_vars, options: proc(replacement, match)
113
113
 
114
114
 
115
115
  #### `format_link`
@@ -142,39 +142,49 @@ module MarkdownRubyDocumentation
142
142
  ruby_source = any_args.source_code
143
143
 
144
144
  RUBY_TO_MARKDOWN_PROCESSORS.each do |processor|
145
- options = disable_processors.fetch(processor, {})
146
- ruby_source = send(processor, ruby_source, options) if options
145
+ options = disable_processors.fetch(processor, :enabled)
146
+ ruby_source = if options == :enabled
147
+ send(processor, ruby_source)
148
+ elsif options.is_a?(Hash)
149
+ send(processor, ruby_source, options)
150
+ end
147
151
  end
148
152
  ruby_source
149
153
  end
150
154
 
151
- def comment_format(source_code, proc: false)
155
+ def comment_format(source_code=print_method_source, proc: false)
152
156
  gsub_replacement(source_code, { /^#(.*)/ => "</br>*(\\1)*</br>" }, proc: proc)
153
157
  end
154
158
 
155
- def remove_memoized_vars(source_code=print_method_source, *)
156
- source_code.gsub(/@[a-z][a-z0-9_]+ \|\|=?\s/, "") # @memoized_vars ||=
159
+ def remove_memoized_vars(source_code=print_method_source, proc: false)
160
+ conversions = {
161
+ /@[a-z][a-z0-9_]+ \|\|=?\s/ => "" # @memoized_vars ||=
162
+ }
163
+ gsub_replacement(source_code, conversions, proc: proc)
157
164
  end
158
165
 
159
- def nil_check_readable(source_code, proc: false)
166
+ def nil_check_readable(source_code=print_method_source, proc: false)
160
167
  conversions = {
161
168
  ".nil?" => " is missing?"
162
169
  }
163
170
  gsub_replacement(source_code, conversions, proc: proc)
164
171
  end
165
172
 
166
- def elsif_to_else_if(source_code, proc: false)
173
+ def elsif_to_else_if(source_code=print_method_source, proc: false)
167
174
  conversions = {
168
175
  "elsif" => "else if"
169
176
  }
170
177
  gsub_replacement(source_code, conversions, proc: proc)
171
178
  end
172
179
 
173
- def remove_colons(source_code)
174
- source_code.gsub(":", '')
180
+ def remove_colons(source_code=print_method_source, proc: proc)
181
+ conversions = {
182
+ ":" => ''
183
+ }
184
+ gsub_replacement(source_code, conversions, proc: proc)
175
185
  end
176
186
 
177
- def ruby_operators_to_english(source_code, proc: false)
187
+ def ruby_operators_to_english(source_code=print_method_source, proc: false)
178
188
  conversions = {
179
189
  "&&" => "and",
180
190
  ">=" => "is greater than or equal to",
@@ -188,23 +198,32 @@ module MarkdownRubyDocumentation
188
198
  gsub_replacement(source_code, conversions, proc: proc)
189
199
  end
190
200
 
191
- def readable_ruby_numbers(source_code, proc: -> (value) { ActiveSupport::NumberHelper.number_to_delimited(value) })
201
+ def readable_ruby_numbers(source_code=print_method_source, proc: -> (replacement, _) { ActiveSupport::NumberHelper.number_to_delimited(replacement) })
192
202
  source_code.gsub(/([0-9][0-9_]+[0-9]+)/) do |match|
193
- proc.call(eval(match))
203
+ proc.call(eval(match), match)
194
204
  end
195
205
  end
196
206
 
197
- def convert_early_return_to_if_else(source_code, *)
198
- source_code = source_code.gsub(/(.+) if (.+)/, "if \\2\n\\1\nend")
199
- source_code.gsub(/(.+) unless (.+)/, "unless \\2\n\\1\nend")
207
+ def convert_early_return_to_if_else(source_code=print_method_source, proc: false)
208
+ conversions = {
209
+ /(.+) if (.+)/ => "if \\2\n\\1\nend",
210
+ /(.+) unless (.+)/ => "unless \\2\n\\1\nend"
211
+ }
212
+ gsub_replacement(source_code, conversions, proc: proc)
200
213
  end
201
214
 
202
- def pretty_early_return(source_code, *)
203
- source_code.gsub(/return (unless|if)/, 'return nothing \1')
215
+ def pretty_early_return(source_code=print_method_source, proc: false)
216
+ conversions = {
217
+ /return (unless|if)/ => 'return nothing \1'
218
+ }
219
+ gsub_replacement(source_code, conversions, proc: proc)
204
220
  end
205
221
 
206
- def ternary_to_if_else(ternary, *)
207
- ternary.gsub(/(.*) \? (.*) \: (.*)/, "if \\1\n\\2\nelse\n\\3\nend")
222
+ def ternary_to_if_else(source_code=print_method_source, proc: false)
223
+ conversions = {
224
+ /(.*) \? (.*) \: (.*)/ => "if \\1\n\\2\nelse\n\\3\nend"
225
+ }
226
+ gsub_replacement(source_code, conversions, proc: proc)
208
227
  end
209
228
 
210
229
  # @param [String] title the name of the link
@@ -334,11 +353,14 @@ module MarkdownRubyDocumentation
334
353
  end
335
354
  end
336
355
 
337
- def constants_with_name_and_value(ruby_source, *)
356
+ def constants_with_name_and_value(ruby_source, proc: false)
338
357
  ruby_source.gsub(/([A-Z]+[A-Z_0-9]+)/) do |match|
339
358
  begin
340
- value = ruby_class.const_get(match)
341
- "[#{ConstantsPresenter.format(value)}](##{match.dasherize.downcase})"
359
+ value = ruby_class.const_get(match)
360
+ link = "##{match.dasherize.downcase}"
361
+ formatted_value = ConstantsPresenter.format(value)
362
+ replacement = format_link(formatted_value, link)
363
+ proc ? proc.call(replacement, match, { value: value, link: link, formatted_value: formatted_value }) : replacement
342
364
  rescue NameError
343
365
  match
344
366
  end
@@ -1,3 +1,3 @@
1
1
  module MarkdownRubyDocumentation
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_ruby_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -163,4 +163,3 @@ specification_version: 4
163
163
  summary: Gem provides the ability to use markdown and ruby ERB with some helper methods
164
164
  inside of comments
165
165
  test_files: []
166
- has_rdoc: