Module: LegalToMarkdown::Leaders

Defined in:
lib/legal_markdown/legal_to_markdown/leaders.rb

Instance Method Summary collapse

Instance Method Details

#chew_on_the_blockObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legal_markdown/legal_to_markdown/leaders.rb', line 48

def chew_on_the_block
  # @substitutions hash example
  # {"ll."OR "l2."=>[:type8, "Article ", "(", "1", ")", :no_reset || nil, :no_indent || nil, :preval || :pre || nil],}
  @cross_references = {}
  arrayed_block = []
  @block.each_line do |line|
    next if line[/^\s+$/]
    line[/(^l+\.|^l\d\.)\s*(\|.*?\|)*\s*(.*)$/] ? arrayed_block << [$1, $3, $2] : arrayed_block.last[1] << ("\n" + line.rstrip)
  end
  @block = build_the_block_for_markdown arrayed_block if @writer == :markdown
  @block = build_the_block_for_jason arrayed_block if @writer == :jason
end

#clean_up_leadersObject



61
62
63
64
65
66
67
68
# File 'lib/legal_markdown/legal_to_markdown/leaders.rb', line 61

def clean_up_leaders
  @content.gsub!("{{block}}", @block ) if @writer == :markdown
  if @writer == :jason
    @content = @content.partition( /\{\{block\}\}/ )
    @content[1] = @block
  end
  @block = ""
end

#find_the_blockObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/legal_markdown/legal_to_markdown/leaders.rb', line 36

def find_the_block
  block_pattern = /(^```+\s*\n?)(.*?\n?)(^```+\s*\n?|\z)/m
  parts = @content.partition( block_pattern )
  if parts[1] != ""
    @block = $2.chomp
    @content = parts[0] + "{{block}}" + parts[2]
  else
    @block = nil
    @content = @content
  end
end

#get_the_substitutionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/legal_markdown/legal_to_markdown/leaders.rb', line 17

def get_the_substitutions
  # find the headers in the remaining YAML
  # parse out the headers into level-X and pre-X headers
  # then combine them into a coherent package
  # returns a hash with the keys as the l., ll. searches
  # and the values as the replacements in the form of
  # an array where the first value is a symbol and the
  # second value is the precursor
  #
  # @substitutions hash example
  # {"ll." || "l2."=>[:type8, "Article ", "(", "1", ")", :no_reset || nil, "  ", :preval || :pre || nil]}

  @substitutions = {}
  get_level_style
  get_the_indents
  get_the_levels
  get_the_resets
end

#run_leadersObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/legal_markdown/legal_to_markdown/leaders.rb', line 6

def run_leaders
  get_the_substitutions
  unless @substitutions == {}
    find_the_block
    if @block
      chew_on_the_block
      clean_up_leaders
    end
  end
end