Module: LegalMarkdown
- Defined in:
- lib/legal_markdown.rb,
lib/legal_markdown/version.rb
Constant Summary collapse
- VERSION =
"0.4.11"
Class Method Summary collapse
- .caller(args, config) ⇒ Object
- .optsfooters(opt) ⇒ Object
- .optsheaders(opt) ⇒ Object
- .optsjason(opt, config, args) ⇒ Object
- .optsmakeother(opt, config, args) ⇒ Object
- .optsmakeyaml(opt, config, args) ⇒ Object
- .optsmarkdown(opt, config, args) ⇒ Object
- .optsparse(args, config) ⇒ Object
- .parse(*args) ⇒ Object
Class Method Details
.caller(args, config) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/legal_markdown.rb', line 43 def self.caller args, config if config[:headers] MakeYamlFrontMatter.new(args) elsif config[:output][:jason] LegalToMarkdown.parse_jason(args, config[:verbose]) elsif config[:output][:markdown] || args.size <= 2 LegalToMarkdown.parse_markdown(args, config[:verbose]) end end |
.optsfooters(opt) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/legal_markdown.rb', line 123 def self. opt opt.separator "" opt.separator "Notes:" opt.separator "If the command is --headers or with --to-markdown you can enter one file to be parsed if you wish." opt.separator "When these commands are called with only one file I will set the input_file and the output_file to be the same." opt.separator "The other commands will require the original legal_markdown file and the output file." opt.separator "There is no need to explicitly enter the --to-json if your output_file is *.json I can handle it." opt.separator "There is no need to explicitly enter the --to-markdown if your output_file is *.md or *.markdown I can handle it." opt.separator "" opt end |
.optsheaders(opt) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/legal_markdown.rb', line 53 def self.optsheaders opt opt. = "Usage: legal2md [commands] [input_file] [output_file]" opt.separator "" opt.separator "[input_file] can be a file or use \"-\" for STDIN" opt.separator "[output_file] can be a file or use \"-\" for STDOUT" opt.separator "" opt.separator "Specific Commands:" end |
.optsjason(opt, config, args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/legal_markdown.rb', line 76 def self.optsjason opt, config, args config[:output][:jason] = false opt.on( '-j', '--to-json', 'Parse the Legal Markdown file and produce a JSON document.' ) do config[:output][:jason] = true end if args.include?(:to_json) || (begin args[-1][/\.json/]; rescue; end;) config[:output][:jason] = true args.delete(:to_json) if args.include?( :to_json ) end end |
.optsmakeother(opt, config, args) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/legal_markdown.rb', line 104 def self.optsmakeother opt, config, args config[:verbose] = false opt.on('--debug', 'Debug legal_markdown. **Only works with output options, not with headers switch.**') do config[:verbose] = true end opt.on( '-v', '--version', 'Display the gem\'s current version that you are using.' ) do puts 'Legal Markdown version ' + LegalMarkdown::VERSION exit end opt.on( '-h', '--help', 'Display this screen at any time.' ) do puts @opt_parser exit end end |
.optsmakeyaml(opt, config, args) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/legal_markdown.rb', line 90 def self.optsmakeyaml opt, config, args config[:headers] = false opt.on( '-d', '--headers', 'Make the YAML Frontmatter automatically.' ) do config[:headers] = true end if args.include? :headers config[:headers] = true args.delete :headers end end |
.optsmarkdown(opt, config, args) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legal_markdown.rb', line 62 def self.optsmarkdown opt, config, args config[:output][:markdown] = false opt.on( '-m', '--to-markdown', 'Parse the Legal Markdown file and produce a Text document (md, rst, txt, etc.).' ) do config[:output][:markdown] = true end if args.include?(:to_markdown) || (begin args[-1][/\.md|\.markdown/]; rescue; end;) config[:output][:markdown] = true args.delete :markdown end end |
.optsparse(args, config) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/legal_markdown.rb', line 29 def self.optsparse args, config @opt_parser = OptionParser.new do |opt| optsheaders opt optsmarkdown opt, config, args optsjason opt, config, args optsmakeyaml opt, config, args optsmakeother opt, config, args opt end @opt_parser.parse!(args) return args, config end |
.parse(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legal_markdown.rb', line 10 def self.parse(*args) config={} config[:input] = {} config[:output] = {} if args.size == 1 && args.first.class == Array args = args.first end args, config = optsparse args, config if args.size >= 1 caller args, config else puts @opt_parser end end |