legal_markdown 0.4.10 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/README.md +1 -0
- data/Rakefile +26 -29
- data/legal_markdown.gemspec +1 -0
- data/lib/legal_markdown.rb +6 -5
- data/lib/legal_markdown/legal_to_markdown.rb +2 -0
- data/lib/legal_markdown/legal_to_markdown/json_builder.rb +4 -0
- data/lib/legal_markdown/legal_to_markdown/load_source.rb +9 -1
- data/lib/legal_markdown/legal_to_markdown/meta.rb +43 -0
- data/lib/legal_markdown/legal_to_markdown/mixins.rb +0 -1
- data/lib/legal_markdown/make_yaml_frontmatter.rb +22 -3
- data/lib/legal_markdown/version.rb +1 -1
- data/{test/tests → spec/fixtures}/00.load_write_no_action.headers +0 -0
- data/{test/tests → spec/fixtures}/00.load_write_no_action.json +0 -0
- data/{test/tests → spec/fixtures}/00.load_write_no_action.lmd +0 -0
- data/{test/tests → spec/fixtures}/00.load_write_no_action.md +0 -0
- data/{test/tests → spec/fixtures}/01.load_partial_no_action.headers +1 -1
- data/{test/tests → spec/fixtures}/01.load_partial_no_action.json +0 -0
- data/{test/tests → spec/fixtures}/01.load_partial_no_action.lmd +1 -1
- data/{test/tests → spec/fixtures}/01.load_partial_no_action.md +0 -0
- data/{test/tests → spec/fixtures}/02.load_partials_no_action.headers +2 -2
- data/{test/tests → spec/fixtures}/02.load_partials_no_action.json +0 -0
- data/{test/tests → spec/fixtures}/02.load_partials_no_action.lmd +2 -2
- data/{test/tests → spec/fixtures}/02.load_partials_no_action.md +0 -0
- data/{test/tests → spec/fixtures}/10.mixins_in_headers_and_text.headers +0 -0
- data/{test/tests → spec/fixtures}/10.mixins_in_headers_and_text.json +0 -0
- data/{test/tests → spec/fixtures}/10.mixins_in_headers_and_text.lmd +0 -0
- data/{test/tests → spec/fixtures}/10.mixins_in_headers_and_text.md +0 -0
- data/{test/tests → spec/fixtures}/12.opt_clauses_no_subs.headers +0 -0
- data/{test/tests → spec/fixtures}/12.opt_clauses_no_subs.json +0 -0
- data/{test/tests → spec/fixtures}/12.opt_clauses_no_subs.lmd +0 -0
- data/{test/tests → spec/fixtures}/12.opt_clauses_no_subs.md +0 -0
- data/{test/tests → spec/fixtures}/13.opt_clauses_subs.headers +0 -0
- data/{test/tests → spec/fixtures}/13.opt_clauses_subs.json +0 -0
- data/{test/tests → spec/fixtures}/13.opt_clauses_subs.lmd +0 -0
- data/{test/tests → spec/fixtures}/13.opt_clauses_subs.md +0 -0
- data/{test/tests → spec/fixtures}/14.opt_clauses_with_mixins.headers +0 -0
- data/{test/tests → spec/fixtures}/14.opt_clauses_with_mixins.json +0 -0
- data/{test/tests → spec/fixtures}/14.opt_clauses_with_mixins.lmd +0 -0
- data/{test/tests → spec/fixtures}/14.opt_clauses_with_mixins.md +0 -0
- data/{test/tests → spec/fixtures}/20.block_no_addons.headers +0 -0
- data/{test/tests → spec/fixtures}/20.block_no_addons.json +0 -0
- data/{test/tests → spec/fixtures}/20.block_no_addons.lmd +0 -0
- data/{test/tests → spec/fixtures}/20.block_no_addons.md +0 -0
- data/{test/tests → spec/fixtures}/21.block_no_indents.headers +0 -0
- data/{test/tests → spec/fixtures}/21.block_no_indents.json +0 -0
- data/{test/tests → spec/fixtures}/21.block_no_indents.lmd +0 -0
- data/{test/tests → spec/fixtures}/21.block_no_indents.md +0 -0
- data/{test/tests → spec/fixtures}/22.block_all_indents.headers +0 -0
- data/{test/tests → spec/fixtures}/22.block_all_indents.json +0 -0
- data/{test/tests → spec/fixtures}/22.block_all_indents.lmd +0 -0
- data/{test/tests → spec/fixtures}/22.block_all_indents.md +0 -0
- data/{test/tests → spec/fixtures}/23.block_part_indents.headers +0 -0
- data/{test/tests → spec/fixtures}/23.block_part_indents.json +0 -0
- data/{test/tests → spec/fixtures}/23.block_part_indents.lmd +0 -0
- data/{test/tests → spec/fixtures}/23.block_part_indents.md +0 -0
- data/{test/tests → spec/fixtures}/24.block_no_closing_ticks.headers +0 -0
- data/{test/tests → spec/fixtures}/24.block_no_closing_ticks.json +0 -0
- data/{test/tests → spec/fixtures}/24.block_no_closing_ticks.lmd +0 -0
- data/{test/tests → spec/fixtures}/24.block_no_closing_ticks.md +0 -0
- data/{test/tests → spec/fixtures}/25.block_no_resets.headers +0 -0
- data/{test/tests → spec/fixtures}/25.block_no_resets.json +0 -0
- data/{test/tests → spec/fixtures}/25.block_no_resets.lmd +0 -0
- data/{test/tests → spec/fixtures}/25.block_no_resets.md +0 -0
- data/{test/tests → spec/fixtures}/26.block_all_resets.headers +0 -0
- data/{test/tests → spec/fixtures}/26.block_all_resets.json +0 -0
- data/{test/tests → spec/fixtures}/26.block_all_resets.lmd +0 -0
- data/{test/tests → spec/fixtures}/26.block_all_resets.md +0 -0
- data/{test/tests → spec/fixtures}/27.block_part_resets.headers +0 -0
- data/{test/tests → spec/fixtures}/27.block_part_resets.json +0 -0
- data/{test/tests → spec/fixtures}/27.block_part_resets.lmd +0 -0
- data/{test/tests → spec/fixtures}/27.block_part_resets.md +0 -0
- data/{test/tests → spec/fixtures}/28.block_provs_multi_line_no_indent.headers +0 -0
- data/{test/tests → spec/fixtures}/28.block_provs_multi_line_no_indent.json +0 -0
- data/{test/tests → spec/fixtures}/28.block_provs_multi_line_no_indent.lmd +0 -0
- data/{test/tests → spec/fixtures}/28.block_provs_multi_line_no_indent.md +0 -0
- data/{test/tests → spec/fixtures}/29.block_provs_multi_line_indents.headers +0 -0
- data/{test/tests → spec/fixtures}/29.block_provs_multi_line_indents.json +0 -0
- data/{test/tests → spec/fixtures}/29.block_provs_multi_line_indents.lmd +0 -0
- data/{test/tests → spec/fixtures}/29.block_provs_multi_line_indents.md +0 -0
- data/{test/tests → spec/fixtures}/30.block_all_leader_types.headers +0 -0
- data/{test/tests → spec/fixtures}/30.block_all_leader_types.json +0 -0
- data/{test/tests → spec/fixtures}/30.block_all_leader_types.lmd +0 -0
- data/{test/tests → spec/fixtures}/30.block_all_leader_types.md +0 -0
- data/{test/tests → spec/fixtures}/31.block_complex_leader_types.headers +0 -0
- data/{test/tests → spec/fixtures}/31.block_complex_leader_types.json +0 -0
- data/{test/tests → spec/fixtures}/31.block_complex_leader_types.lmd +0 -0
- data/{test/tests → spec/fixtures}/31.block_complex_leader_types.md +0 -0
- data/{test/tests → spec/fixtures}/32.block_new_leader_style.headers +0 -0
- data/{test/tests → spec/fixtures}/32.block_new_leader_style.json +0 -0
- data/{test/tests → spec/fixtures}/32.block_new_leader_style.lmd +0 -0
- data/{test/tests → spec/fixtures}/32.block_new_leader_style.md +0 -0
- data/{test/tests → spec/fixtures}/33.block_with_pre_simple.headers +0 -0
- data/{test/tests → spec/fixtures}/33.block_with_pre_simple.json +0 -0
- data/{test/tests → spec/fixtures}/33.block_with_pre_simple.lmd +0 -0
- data/{test/tests → spec/fixtures}/33.block_with_pre_simple.md +0 -0
- data/{test/tests → spec/fixtures}/34.block_with_pre_complex.headers +0 -0
- data/{test/tests → spec/fixtures}/34.block_with_pre_complex.json +0 -0
- data/{test/tests → spec/fixtures}/34.block_with_pre_complex.lmd +0 -0
- data/{test/tests → spec/fixtures}/34.block_with_pre_complex.md +0 -0
- data/{test/tests → spec/fixtures}/35.block_with_preval.headers +0 -0
- data/{test/tests → spec/fixtures}/35.block_with_preval.json +0 -0
- data/{test/tests → spec/fixtures}/35.block_with_preval.lmd +0 -0
- data/{test/tests → spec/fixtures}/35.block_with_preval.md +0 -0
- data/{test/tests → spec/fixtures}/36.block_with_crossrefs.headers +0 -0
- data/{test/tests → spec/fixtures}/36.block_with_crossrefs.json +0 -0
- data/{test/tests → spec/fixtures}/36.block_with_crossrefs.lmd +0 -0
- data/{test/tests → spec/fixtures}/36.block_with_crossrefs.md +0 -0
- data/{test/tests → spec/fixtures}/37.block_with_diff_start_pt.headers +0 -0
- data/{test/tests → spec/fixtures}/37.block_with_diff_start_pt.json +0 -0
- data/{test/tests → spec/fixtures}/37.block_with_diff_start_pt.lmd +0 -0
- data/{test/tests → spec/fixtures}/37.block_with_diff_start_pt.md +0 -0
- data/{test/tests → spec/fixtures}/38.block_with_bom_characters_windows_produces.headers +0 -0
- data/{test/tests → spec/fixtures}/38.block_with_bom_characters_windows_produces.json +0 -0
- data/{test/tests → spec/fixtures}/38.block_with_bom_characters_windows_produces.lmd +0 -0
- data/{test/tests → spec/fixtures}/38.block_with_bom_characters_windows_produces.md +0 -0
- data/spec/fixtures/38.block_with_more_bom_characters_windows_produces.headers +50 -0
- data/spec/fixtures/38.block_with_more_bom_characters_windows_produces.json +256 -0
- data/spec/fixtures/38.block_with_more_bom_characters_windows_produces.lmd +0 -0
- data/spec/fixtures/38.block_with_more_bom_characters_windows_produces.md +26 -0
- data/spec/fixtures/39.block_with_windows_default_encoding.headers +50 -0
- data/spec/fixtures/39.block_with_windows_default_encoding.json +256 -0
- data/spec/fixtures/39.block_with_windows_default_encoding.lmd +50 -0
- data/spec/fixtures/39.block_with_windows_default_encoding.md +26 -0
- data/{test/tests → spec/fixtures}/40.block_with_mixins.headers +0 -0
- data/{test/tests → spec/fixtures}/40.block_with_mixins.json +0 -0
- data/{test/tests → spec/fixtures}/40.block_with_mixins.lmd +0 -0
- data/{test/tests → spec/fixtures}/40.block_with_mixins.md +0 -0
- data/{test/tests → spec/fixtures}/41.block_with_opt_clauses.headers +0 -0
- data/{test/tests → spec/fixtures}/41.block_with_opt_clauses.json +0 -0
- data/{test/tests → spec/fixtures}/41.block_with_opt_clauses.lmd +0 -0
- data/{test/tests → spec/fixtures}/41.block_with_opt_clauses.md +0 -0
- data/spec/fixtures/42.block_with_opt_clauses_and_mixins.debug +193 -0
- data/spec/fixtures/42.block_with_opt_clauses_and_mixins.debugd +193 -0
- data/{test/tests → spec/fixtures}/42.block_with_opt_clauses_and_mixins.headers +0 -0
- data/{test/tests → spec/fixtures}/42.block_with_opt_clauses_and_mixins.json +0 -0
- data/{test/tests → spec/fixtures}/42.block_with_opt_clauses_and_mixins.lmd +0 -0
- data/{test/tests → spec/fixtures}/42.block_with_opt_clauses_and_mixins.md +0 -0
- data/spec/fixtures/43.throw_some_erroris.headers +90 -0
- data/spec/fixtures/43.throw_some_erroris.json +200 -0
- data/spec/fixtures/43.throw_some_erroris.lmd +39 -0
- data/spec/fixtures/43.throw_some_erroris.md +26 -0
- data/spec/fixtures/44.block_with_meta_kept.headers +60 -0
- data/spec/fixtures/44.block_with_meta_kept.json +477 -0
- data/spec/fixtures/44.block_with_meta_kept.lmd +56 -0
- data/spec/fixtures/44.block_with_meta_kept.md +55 -0
- data/spec/fixtures/45.block_with_meta_stripped_no_output.headers +57 -0
- data/spec/fixtures/45.block_with_meta_stripped_no_output.json +476 -0
- data/spec/fixtures/45.block_with_meta_stripped_no_output.lmd +53 -0
- data/spec/fixtures/45.block_with_meta_stripped_no_output.md +50 -0
- data/spec/fixtures/46.block_with_meta_no_instructions.headers +57 -0
- data/spec/fixtures/46.block_with_meta_no_instructions.json +477 -0
- data/spec/fixtures/46.block_with_meta_no_instructions.lmd +57 -0
- data/spec/fixtures/46.block_with_meta_no_instructions.md +55 -0
- data/spec/fixtures/47.block_with_multi_meta.headers +59 -0
- data/spec/fixtures/47.block_with_multi_meta.json +477 -0
- data/spec/fixtures/47.block_with_multi_meta.lmd +55 -0
- data/spec/fixtures/47.block_with_multi_meta.md +55 -0
- data/{test/tests/45.all_features_speed_ratchet.headers → spec/fixtures/99.all_features_speed_ratchet.headers} +0 -0
- data/{test/tests/45.all_features_speed_ratchet.json → spec/fixtures/99.all_features_speed_ratchet.json} +0 -0
- data/{test/tests/45.all_features_speed_ratchet.lmd → spec/fixtures/99.all_features_speed_ratchet.lmd} +0 -0
- data/{test/tests/45.all_features_speed_ratchet.md → spec/fixtures/99.all_features_speed_ratchet.md} +0 -0
- data/{test/tests → spec/fixtures}/partials/z.partial1 +0 -0
- data/{test/tests → spec/fixtures}/partials/z.partial2 +0 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/samples_helper.rb +60 -0
- data/spec/unit/legal_markdown_spec.rb +76 -0
- data/spec/unit/legal_to_markdown/legal_to_markdown_spec.rb +35 -0
- data/spec/unit/legal_to_markdown/make_yaml_frontmatter_spec.rb +15 -0
- metadata +335 -260
- data/test/legal_markdown_test.rb +0 -130
- data/test/tests/45.all_features_speed_ratchet.debug +0 -550
- data/test/tests/46.throw_some_erroris.headers +0 -209
- data/test/tests/46.throw_some_erroris.json +0 -1
- data/test/tests/46.throw_some_erroris.lmd +0 -107
- data/test/tests/46.throw_some_erroris.md +0 -94
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -331,6 +331,7 @@ At this point legal_markdown does not have a native citation handling ability. F
|
|
331
331
|
|
332
332
|
* Legal_markdown is optimized primarily for contracts, legislation, and regulations. It is not optimized for cases. For memoranda and filings I use the mixin portion but not the structured headers functionality which is enough to meet my needs - in particular, when matched with Sublime Text snippets. If you area looking for a solution for cases and filings I would recommend the [Precedent Gem](https://github.com/BlackacreLabs/precedent) built by [Kyle Mitchell](https://github.com/kemitchell) for [Blackacre Labs](https://github.com/BlackacreLabs)
|
333
333
|
* At this point, you cannot have more than 9 levels for headers, but if you have more than 9 levels of headers you have some insane case study which will require more than this tool to cope with.
|
334
|
+
* If you are using windows `legal_markdown` *should* be able to deal with most of the file types, but to be safe it is preferable to save your files with UTF-8 encoding. In Notepad and Notepad++ you can select the encoding from the drop down dialog at the bottom of the Save window.
|
334
335
|
|
335
336
|
## Roadmap / TODO
|
336
337
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
require 'bundler'
|
2
|
-
require 'bundler/gem_tasks'
|
3
4
|
begin
|
4
5
|
Bundler.setup(:default, :development)
|
5
6
|
rescue Bundler::BundlerError => e
|
@@ -7,26 +8,35 @@ rescue Bundler::BundlerError => e
|
|
7
8
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
9
|
exit e.status_code
|
9
10
|
end
|
10
|
-
require 'rake
|
11
|
+
require 'rake'
|
12
|
+
require 'rspec'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
Bundler::GemHelper.install_tasks
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
desc "Run all RSpec test examples"
|
17
|
+
task :spec do
|
18
|
+
RSpec::Core::RakeTask.new do |spec|
|
19
|
+
spec.rspec_opts = ["-c", "-f progress"]
|
20
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
|
-
desc "
|
19
|
-
task :
|
20
|
-
|
21
|
-
|
24
|
+
desc "Update Sublime Package"
|
25
|
+
task :sublime do
|
26
|
+
begin
|
27
|
+
tag = LegalMarkdown::VERSION
|
28
|
+
rescue
|
29
|
+
require Dir.pwd + "/lib/legal_markdown/version.rb"
|
30
|
+
tag = LegalMarkdown::VERSION
|
31
|
+
end
|
22
32
|
Dir.chdir(File.dirname(__FILE__))
|
23
|
-
pkg = ENV['HOME'] + "
|
33
|
+
pkg = ENV['HOME'] + "/sites/sublime/Legal Document Creator"
|
24
34
|
FileUtils.cp_r( File.dirname(__FILE__) + "/lib" , pkg )
|
25
35
|
Dir.chdir(pkg)
|
26
36
|
f = "lib/legal_markdown.rb"
|
27
37
|
c = File::read(f) + "\n\nLegalMarkdown::parse(ARGV)"
|
28
38
|
File.open(f, "w") { |f| f.write( c ); f.close }
|
29
|
-
message = "Package updated at
|
39
|
+
message = "Package updated at reflect changes in Gem to version #{tag}."
|
30
40
|
system "git add -A"
|
31
41
|
system "git commit -m #{message.shellescape}"
|
32
42
|
system "git push github master"
|
@@ -34,9 +44,8 @@ task :publish do
|
|
34
44
|
Dir.chdir(File.dirname(__FILE__))
|
35
45
|
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
task :pushit do
|
47
|
+
desc "Publish New Version of Gem & Update Sublime Package"
|
48
|
+
task :publish do
|
40
49
|
fail "Does not look like the Version file is updated!" unless `git status -s`.split("\n").include?(" M lib/legal_markdown/version.rb")
|
41
50
|
require Dir.pwd + "/lib/legal_markdown/version.rb"
|
42
51
|
tag = LegalMarkdown::VERSION
|
@@ -48,20 +57,8 @@ task :pushit do
|
|
48
57
|
system "git push wsl master --tags"
|
49
58
|
system "rake install"
|
50
59
|
system "gem push pkg/legal_markdown-#{tag}.gem"
|
51
|
-
|
52
|
-
pkg = ENV['HOME'] + "/.config/sublime-text-2/Packages/Legal Document Creator"
|
53
|
-
FileUtils.cp_r( File.dirname(__FILE__) + "/lib" , pkg )
|
54
|
-
Dir.chdir(pkg)
|
55
|
-
f = "lib/legal_markdown.rb"
|
56
|
-
c = File::read(f) + "\n\nLegalMarkdown::parse(ARGV)"
|
57
|
-
File.open(f, "w") { |f| f.write( c ); f.close }
|
58
|
-
message = "Package updated at reflect changes in Gem to version #{tag}."
|
59
|
-
system "git add -A"
|
60
|
-
system "git commit -m #{message.shellescape}"
|
61
|
-
system "git push github master"
|
62
|
-
system "git push wsl master"
|
63
|
-
Dir.chdir(File.dirname(__FILE__))
|
60
|
+
Rake::Task["build"].invoke
|
64
61
|
system "google-chrome https://github.com/compleatang/legal-markdown/releases"
|
65
62
|
end
|
66
63
|
|
67
|
-
task :default =>
|
64
|
+
task :default => :spec
|
data/legal_markdown.gemspec
CHANGED
data/lib/legal_markdown.rb
CHANGED
@@ -21,13 +21,13 @@ module LegalMarkdown
|
|
21
21
|
if args.size >= 1
|
22
22
|
caller args, config
|
23
23
|
else
|
24
|
-
puts opt_parser
|
24
|
+
puts @opt_parser
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.optsparse args, config
|
30
|
-
opt_parser = OptionParser.new do |opt|
|
30
|
+
@opt_parser = OptionParser.new do |opt|
|
31
31
|
optsheaders opt
|
32
32
|
optsmarkdown opt, config, args
|
33
33
|
optsjason opt, config, args
|
@@ -36,7 +36,7 @@ module LegalMarkdown
|
|
36
36
|
optsfooters opt
|
37
37
|
end
|
38
38
|
|
39
|
-
opt_parser.parse!(args)
|
39
|
+
@opt_parser.parse!(args)
|
40
40
|
return args, config
|
41
41
|
end
|
42
42
|
|
@@ -104,7 +104,7 @@ module LegalMarkdown
|
|
104
104
|
def self.optsmakeother opt, config, args
|
105
105
|
|
106
106
|
config[:verbose] = false
|
107
|
-
opt.on('--
|
107
|
+
opt.on('--debug', 'Debug legal_markdown. **Only works with output options, not with headers switch.**') do
|
108
108
|
config[:verbose] = true
|
109
109
|
end
|
110
110
|
|
@@ -114,7 +114,7 @@ module LegalMarkdown
|
|
114
114
|
end
|
115
115
|
|
116
116
|
opt.on( '-h', '--help', 'Display this screen at any time.' ) do
|
117
|
-
puts opt_parser
|
117
|
+
puts @opt_parser
|
118
118
|
exit
|
119
119
|
end
|
120
120
|
|
@@ -129,6 +129,7 @@ module LegalMarkdown
|
|
129
129
|
opt.separator "There is no need to explicitly enter the --to-json if your output_file is *.json I can handle it."
|
130
130
|
opt.separator "There is no need to explicitly enter the --to-markdown if your output_file is *.md or *.markdown I can handle it."
|
131
131
|
opt.separator ""
|
132
|
+
opt
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
@@ -3,6 +3,7 @@ require 'legal_to_markdown/load_source.rb'
|
|
3
3
|
require 'legal_to_markdown/mixins.rb'
|
4
4
|
require 'legal_to_markdown/leaders.rb'
|
5
5
|
require 'legal_to_markdown/json_builder.rb'
|
6
|
+
require 'legal_to_markdown/meta.rb'
|
6
7
|
require 'legal_to_markdown/writer.rb'
|
7
8
|
require 'roman_numerals'
|
8
9
|
require 'paint'
|
@@ -35,6 +36,7 @@ module LegalToMarkdown
|
|
35
36
|
verbose_after_process source, 'mixins'
|
36
37
|
source.run_leaders if source.leaders
|
37
38
|
verbose_after_process source, 'headers'
|
39
|
+
source.run_meta if source.docinfo
|
38
40
|
source.build_jason if source.writer == :jason
|
39
41
|
write_it(source.content, source.writer)
|
40
42
|
end
|
@@ -50,6 +50,10 @@ module LegalToMarkdown
|
|
50
50
|
|
51
51
|
def build_front_portion
|
52
52
|
document_hash = { "document" => { "title" => "", "abstract" => "", "views" => ["content"] }}
|
53
|
+
if @docinfo.is_a?(Hash)
|
54
|
+
document_hash = { "document" => document_hash['document'].merge(@docinfo) }
|
55
|
+
end
|
56
|
+
document_hash
|
53
57
|
end
|
54
58
|
|
55
59
|
def build_header_and_text_hashs( text_block )
|
@@ -3,11 +3,12 @@ module LegalToMarkdown
|
|
3
3
|
|
4
4
|
class FileToParse
|
5
5
|
|
6
|
-
attr_accessor :headers, :content, :mixins, :leaders, :writer
|
6
|
+
attr_accessor :headers, :content, :mixins, :leaders, :docinfo, :writer
|
7
7
|
|
8
8
|
def initialize(file, output)
|
9
9
|
@input_file = file; @headers = nil; @content = ""; @writer = output
|
10
10
|
load; get_the_partials; parse; set_the_parsers
|
11
|
+
@orig_headers = @headers.clone if @headers
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
@@ -56,6 +57,10 @@ module LegalToMarkdown
|
|
56
57
|
self.extend LegalToMarkdown::Leaders
|
57
58
|
@leaders = true
|
58
59
|
end
|
60
|
+
if @headers && ! @headers.keys.select{|k| k.to_s[/meta/] }.empty?
|
61
|
+
self.extend LegalToMarkdown::Meta
|
62
|
+
@docinfo = true
|
63
|
+
end
|
59
64
|
if @writer == :jason
|
60
65
|
self.extend LegalToMarkdown::JasonBuilder
|
61
66
|
end
|
@@ -64,8 +69,11 @@ module LegalToMarkdown
|
|
64
69
|
def get_file( file )
|
65
70
|
begin
|
66
71
|
f = File::read(file)
|
72
|
+
if f[1] == "\u0000" then f = f.force_encoding('utf-16le').encode('utf-8') end
|
67
73
|
f.gsub!("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
|
68
74
|
f.gsub!("\xC3\xAF\xC2\xBB\xC2\xBF".force_encoding("UTF-8"), '')
|
75
|
+
f.gsub!("\r", '')
|
76
|
+
f.force_encoding("UTF-8")
|
69
77
|
f
|
70
78
|
rescue => e
|
71
79
|
puts "Sorry, I could not read the file #{file}: #{e.message}."
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module LegalToMarkdown
|
2
|
+
extend self
|
3
|
+
|
4
|
+
module Meta
|
5
|
+
|
6
|
+
def run_meta
|
7
|
+
default_output
|
8
|
+
yaml_output if @writer == :markdown
|
9
|
+
json_output if @writer == :jason
|
10
|
+
no_output
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_output
|
14
|
+
case @writer
|
15
|
+
when :markdown
|
16
|
+
default = 'meta-yaml-output'
|
17
|
+
when :jason
|
18
|
+
default = 'meta-json-output'
|
19
|
+
end
|
20
|
+
if @orig_headers['meta']
|
21
|
+
@orig_headers[default] = @orig_headers['meta']
|
22
|
+
@orig_headers.delete('meta')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def yaml_output
|
27
|
+
if adder = @orig_headers['meta-yaml-output']
|
28
|
+
adder = YAML.dump(adder)
|
29
|
+
@content = adder + "---\n\n" + @content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def json_output
|
34
|
+
if adder = @orig_headers['meta-json-output']
|
35
|
+
@docinfo = adder
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def no_output
|
40
|
+
#hook for later processing
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -8,7 +8,7 @@ class MakeYamlFrontMatter
|
|
8
8
|
@output_file = args[-1]
|
9
9
|
find_yaml_if_yaml load
|
10
10
|
scan_and_filter_yaml
|
11
|
-
build_new_yaml_frontmatter unless @yaml_data_as_array == [{},{},{},{}]
|
11
|
+
build_new_yaml_frontmatter unless @yaml_data_as_array == [{},{},{},{},{}]
|
12
12
|
write_it
|
13
13
|
end
|
14
14
|
|
@@ -18,8 +18,11 @@ class MakeYamlFrontMatter
|
|
18
18
|
begin
|
19
19
|
source_file = @input_file == "-" ? STDIN.read : File::read(@input_file)
|
20
20
|
source_file = guard_partials_start source_file
|
21
|
+
if source_file[1] == "\u0000" then source_file = source_file.force_encoding('utf-16le').encode('utf-8') end
|
21
22
|
source_file.gsub!("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
|
22
23
|
source_file.gsub!("\xC3\xAF\xC2\xBB\xC2\xBF".force_encoding("UTF-8"), '')
|
24
|
+
source_file.gsub!("\r", '')
|
25
|
+
source_file.force_encoding("UTF-8")
|
23
26
|
source_file
|
24
27
|
rescue
|
25
28
|
puts "Sorry, I could not read the input file #{@input_file}."
|
@@ -49,15 +52,20 @@ class MakeYamlFrontMatter
|
|
49
52
|
@yaml_data_as_array << ( filter_yaml opt_clauses_pattern || {} )
|
50
53
|
@yaml_data_as_array << ( filter_yaml @structured_headers_pattern || {} )
|
51
54
|
@yaml_data_as_array << ( @yaml_data_as_array.last.empty? ? {} : filter_yaml(%w{no-indent no-reset level-style}) )
|
55
|
+
@yaml_data_as_array << ( filter_meta )
|
52
56
|
end
|
53
57
|
|
54
58
|
def build_new_yaml_frontmatter
|
55
59
|
@content = "\n---\n\n" + @content
|
56
|
-
replacers = {0=>"Mixins", 1=>"Optional Clauses", 2=>"Structured Headers", 3=>"Properties"}
|
60
|
+
replacers = {0=>"Mixins", 1=>"Optional Clauses", 2=>"Structured Headers", 3=>"Properties", 4=>"Document Meta-Data"}
|
57
61
|
stringy = @yaml_data_as_array.inject("") do |string, section|
|
58
62
|
unless section.empty?
|
59
63
|
string << "\n\# " + replacers[@yaml_data_as_array.index(section)] + "\n"
|
60
|
-
|
64
|
+
unless @yaml_data_as_array.index(section) == 4
|
65
|
+
string << sink_it(section)
|
66
|
+
else
|
67
|
+
string << YAML.dump(section).gsub("---\n", '')
|
68
|
+
end
|
61
69
|
end
|
62
70
|
string
|
63
71
|
end
|
@@ -84,6 +92,17 @@ class MakeYamlFrontMatter
|
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
95
|
+
def filter_meta
|
96
|
+
meta_tags = %w(meta meta-yaml-output meta-json-output meta-no-output)
|
97
|
+
meta_in_yaml = meta_tags.inject({}) do |hash, elem|
|
98
|
+
if @headers.has_key?(elem)
|
99
|
+
hash[elem] = @headers[elem]
|
100
|
+
end
|
101
|
+
hash
|
102
|
+
end
|
103
|
+
meta_in_yaml
|
104
|
+
end
|
105
|
+
|
87
106
|
def scan_doc pattern
|
88
107
|
found = @content.scan(pattern).uniq.sort.flatten
|
89
108
|
if pattern == @structured_headers_pattern
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,7 +5,7 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
|
5
5
|
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
6
6
|
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
7
7
|
|
8
|
-
@include partials/z.partial1
|
8
|
+
@include spec/fixtures/partials/z.partial1
|
9
9
|
|
10
10
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
11
11
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
File without changes
|
@@ -5,7 +5,7 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
|
5
5
|
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
6
6
|
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
7
7
|
|
8
|
-
@include partials/z.partial1
|
8
|
+
@include spec/fixtures/partials/z.partial1
|
9
9
|
|
10
10
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
11
11
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
File without changes
|
@@ -5,7 +5,7 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
|
5
5
|
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
6
6
|
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
7
7
|
|
8
|
-
@include partials/z.partial1
|
8
|
+
@include spec/fixtures/partials/z.partial1
|
9
9
|
|
10
10
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
11
11
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
@@ -14,7 +14,7 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
|
14
14
|
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
15
15
|
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
16
16
|
|
17
|
-
@include partials/z.partial2
|
17
|
+
@include spec/fixtures/partials/z.partial2
|
18
18
|
|
19
19
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
20
20
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
File without changes
|
@@ -5,7 +5,7 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
|
5
5
|
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
6
6
|
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
7
7
|
|
8
|
-
@include partials/z.partial1
|
8
|
+
@include spec/fixtures/partials/z.partial1
|
9
9
|
|
10
10
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
11
11
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
@@ -14,7 +14,7 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
|
14
14
|
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
15
15
|
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
16
16
|
|
17
|
-
@include partials/z.partial2
|
17
|
+
@include spec/fixtures/partials/z.partial2
|
18
18
|
|
19
19
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
20
20
|
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|