Class: PolicyManager::ExporterView

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers, ERB::Util, WillPaginate::ActionView, WillPaginate::ViewHelpers
Defined in:
lib/policy_manager/exporter/view.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, date = Time.now) ⇒ ExporterView

Returns a new instance of ExporterView.



22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#assignsObject

Returns the value of attribute assigns.



16
17
18
# File 'lib/policy_manager/exporter/view.rb', line 16

def assigns
  @assigns
end

#base_pathObject

Returns the value of attribute base_path.



16
17
18
# File 'lib/policy_manager/exporter/view.rb', line 16

def base_path
  @base_path
end

#templateObject

Returns the value of attribute template.



16
17
18
# File 'lib/policy_manager/exporter/view.rb', line 16

def template
  @template
end

Class Method Details

.templateObject



18
19
20
# File 'lib/policy_manager/exporter/view.rb', line 18

def self.template
  "Welcome, <%= @name %>"
end

Instance Method Details

#handled_templateObject

TODO: method duplicated from json



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# 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_pathObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

#renderObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# 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) ⇒ Object



60
61
62
63
64
# File 'lib/policy_manager/exporter/view.rb', line 60

def save(file)
  File.open(file, "w+") do |f|
    f.write(render)
  end
end