class PolicyManager::ExporterView

Attributes

assigns[RW]
base_path[RW]
template[RW]

Public Class Methods

new(options={}, date=Time.now) click to toggle source
# File lib/policy_manager/exporter/view.rb, line 22
def initialize(options={}, date=Time.now)
  @base_path = options[:base_path]
  @build_path = options[:build_path]
  self.assigns = options[:assigns]
  index_path
  @template = options.fetch(:template, self.class.template)
  return self
end
template() click to toggle source
# File lib/policy_manager/exporter/view.rb, line 18
def self.template
  "Welcome, <%= @name %>"
end

Public Instance Methods

handled_template() click to toggle source

TODO: method duplicated from json

# File lib/policy_manager/exporter/view.rb, line 67
def handled_template
  begin
    if URI.parse(@template)
      return {template: @template}
    end
  rescue URI::InvalidURIError
  end

  if @template.is_a?(String) 
    return {inline: @template}
  elsif @template.is_a?(Pathname)
    return {file: @template }
  end
end
index_path() click to toggle source
# File lib/policy_manager/exporter/view.rb, line 31
def index_path
  path = @base_path.to_s.gsub(@build_path.to_s, "")
  len = path.split("/").size 
  case len
  when 2
    @index_path = "./"
  when 3
    @index_path = "../"
  when 4
    @index_path = "../../"
  else
    @index_path = "../../"
  end
end
render() click to toggle source
# File lib/policy_manager/exporter/view.rb, line 46
def render()
  context = self
  ac = PolicyManager::ExporterController.new()
  options = handled_template.merge!({
    assigns: self.assigns.merge!({
      base_path: base_path, 
      build_path: @build_path,
      index_path: index_path
    }),
    layout: PolicyManager::Config.exporter.layout 
  })
  ac.render_to_string(options)
end
save(file) click to toggle source
# File lib/policy_manager/exporter/view.rb, line 60
def save(file)
  File.open(file, "w+") do |f|
    f.write(render)
  end
end