Class: ProScribe::Extractor::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/proscribe/extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Block

Returns a new instance of Block.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/proscribe/extractor.rb', line 105

def initialize(options)
  options[:type].downcase!
  body = options.delete(:body)
  type = options.delete(:type)
  file = to_filename(options[:title], options[:parent])

  # Build the hash thing.
  header  = Hash[options.map { |(k, v)| [k.to_s, v] }]

  # Extract the brief and other artifacts.
  body = body.split("\n")
  while true
    line = body.first
    if line.nil?
      break
    elsif line =~ /^(.*?): (.*?)$/
      header[$1.downcase] = $2.strip
      body.shift
    elsif line.strip.empty?
      body.shift
    else
      brief = body.shift
      break
    end
  end
  body = body.join("\n")

  # Build the hash thing.
  header['page_type'] = type
  header['brief'] = brief
  header['inherits'] = resolve(header['inherits']) { |fname, _, _| fname }  if header['inherits']
  heading = YAML::dump(header).gsub(/^[\-\n]*/, '').strip
  heading += "\n--\n"

  @file = file
  body  = Tilt.new(".md") { body }.render
  body  = fix_links(body, from: file)
  @body = heading + body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



102
103
104
# File 'lib/proscribe/extractor.rb', line 102

def body
  @body
end

#fileObject

Returns the value of attribute file.



103
104
105
# File 'lib/proscribe/extractor.rb', line 103

def file
  @file
end