Module: MarkdownRecord::RenderingHelpers

Defined in:
lib/markdown_record/rendering/rendering.rb

Instance Method Summary collapse

Instance Method Details

#generate_render_strategy_options(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/markdown_record/rendering/rendering.rb', line 3

def generate_render_strategy_options(options)

  strategy_options = if options[:strat].present?
                       ::MarkdownRecord.config.render_strategy_options(options[:strat].to_sym)
                     else
                       ::MarkdownRecord.config.render_strategy_options
                     end

  strategy_options.merge!(:save => options[:save])
  strategy_options[:render_content_fragment_json] = options[:frag] || ::MarkdownRecord.config.render_content_fragment_json
  strategy_options
end

#record_and_save(lines, text, color = nil) ⇒ Object



44
45
46
47
# File 'lib/markdown_record/rendering/rendering.rb', line 44

def record_and_save(lines, text, color = nil)
  lines << text
  say text, color
end

#report_line_color(saved) ⇒ Object



40
41
42
# File 'lib/markdown_record/rendering/rendering.rb', line 40

def report_line_color(saved)
  color = saved ? :green : :yellow
end

#report_rendered_files(lines, file_saver) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/markdown_record/rendering/rendering.rb', line 16

def report_rendered_files(lines, file_saver)
  file_count = (file_saver.saved_files[:json].count + file_saver.saved_files[:html].count)
  
  record_and_save lines, "---------------------------------------------------------------"
  file_saver.saved_files[:json].each do |file_name|
    record_and_save lines, "rendered: #{file_name}", report_line_color(options[:save])
  end
  file_saver.saved_files[:html].each do |file_name|
    record_and_save lines, "rendered: #{file_name}", report_line_color(options[:save])
  end
  record_and_save lines, "---------------------------------------------------------------"
  record_and_save lines, "#{file_count} files rendered."
  record_and_save lines, "#{options[:save] ? file_count : 0} files saved."

  ::MarkdownRecord.config.rendered_content_root.join("rendered.txt").open('wb') do |file|
    file << lines.join("\n")
  end
end

#report_start(lines, strategy_options, formats) ⇒ Object



35
36
37
38
# File 'lib/markdown_record/rendering/rendering.rb', line 35

def report_start(lines, strategy_options, formats)
  record_and_save lines, "---------------------------------------------------------------"
  record_and_save lines, "rendering #{formats} content with options #{strategy_options} ..."
end

#validateObject



49
50
51
52
53
54
55
# File 'lib/markdown_record/rendering/rendering.rb', line 49

def validate
  MarkdownRecord::Validator.new.validate
  true
rescue MarkdownRecord::Errors::Base => e
  say e.message, :red
  false
end