Module: JekyllGithubSample::TextUtils

Included in:
CodeTag
Defined in:
lib/jekyll_github_sample/text_utils.rb

Constant Summary collapse

INDEN_REGEX =
/^\s+/

Instance Method Summary collapse

Instance Method Details

#extract_tagged_lines(lines, tag) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jekyll_github_sample/text_utils.rb', line 22

def extract_tagged_lines(lines, tag)
  start_tag = "[START #{tag}]"
  end_tag = "[END #{tag}]"
  tagged_lines = []
  in_tagged_content = false
  lines.each do |line|
    if in_tagged_content
      if line.include? end_tag
        in_tagged_content = false
      else
        tagged_lines << line
      end
    else
      in_tagged_content = line.include? start_tag
    end
  end
  tagged_lines
end

#remove_common_indentation(lines) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jekyll_github_sample/text_utils.rb', line 6

def remove_common_indentation(lines)
  leading_spaces = []
  lines.each do |line|
    next if line.length == 1
    if indentation_match = line.match(INDEN_REGEX)
      leading_spaces << indentation_match[0].length
    else
      leading_spaces << 0
    end
  end

  lines.collect do |line|
    line.length == 1 ? line : line[leading_spaces.min..-1]
  end
end