Top Level Namespace

Defined Under Namespace

Modules: Asciibuild

Instance Method Summary collapse

Instance Method Details

#get_lang(lang) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/asciibuild/extensions.rb', line 34

def get_lang lang
  case lang
  when 'pyspark'
    'python'
  when 'spark-shell'
    'scala'
  when 'docker-compose'
    'yaml'
  else
    lang
  end
end

#include_section?(parent, attrs) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/asciibuild/extensions.rb', line 6

def include_section? parent, attrs
  if parent.document.attributes["error"]
    return false
  elsif parent.title == "Before All" or parent.title == "After All"
    return true
  end

  sections = if parent.document.attributes["sections"]
    parent.document.attributes["sections"].split(/,[ ]*/)
  else
    []
  end

  deps = []

  incl_sect = sections.empty?
  sections.each do |s|
    if not incl_sect
      if Regexp.new(s) =~ parent.title
        incl_sect = true
        deps << "Before " + parent.title << "After " + parent.title
      end
    end
  end

  incl_sect or deps.include?(parent.title)
end

#normalize(parent, attrs, lines) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/asciibuild/extensions.rb', line 56

def normalize parent, attrs, lines
  redact = parent.document.attributes['redact']
  patts = if redact
    if redact.class == Array
      redact
    else
      [redact]
    end
  else
    []
  end

  new_lines = []
  lines.each do |l|
    patts.each do |p|
      l = l.gsub(Regexp.new(p), "[****]")
    end
    new_lines << l.gsub(/\e\[([;\d]+)?m/, '') # Sneak in ANSI color stripping here as well
  end
  new_lines
end

#write_file(attrs, default_name, body) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/asciibuild/extensions.rb', line 47

def write_file attrs, default_name, body
  name = attrs['file'] ||= default_name
  mode = if attrs['overwrite'] == 'false' then File::WRONLY|File::CREAT|File::EXCL else 'w' end
  open(name, mode) do |f|
    f.write(body + "\n")
  end
  name
end