Class: PolicyManager::ExporterView
- Inherits:
-
Object
- Object
- PolicyManager::ExporterView
- Includes:
- ActionView::Helpers, ERB::Util, WillPaginate::ActionView, WillPaginate::ViewHelpers
- Defined in:
- lib/policy_manager/exporter/view.rb
Instance Attribute Summary collapse
-
#assigns ⇒ Object
Returns the value of attribute assigns.
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
-
#handled_template ⇒ Object
TODO: method duplicated from json.
- #index_path ⇒ Object
-
#initialize(options = {}, date = Time.now) ⇒ ExporterView
constructor
A new instance of ExporterView.
- #render ⇒ Object
- #save(file) ⇒ Object
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(={}, date=Time.now) @base_path = [:base_path] @build_path = [:build_path] self.assigns = [:assigns] index_path @template = .fetch(:template, self.class.template) return self end |
Instance Attribute Details
#assigns ⇒ Object
Returns the value of attribute assigns.
16 17 18 |
# File 'lib/policy_manager/exporter/view.rb', line 16 def assigns @assigns end |
#base_path ⇒ Object
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 |
#template ⇒ Object
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
.template ⇒ Object
18 19 20 |
# File 'lib/policy_manager/exporter/view.rb', line 18 def self.template "Welcome, <%= @name %>" end |
Instance Method Details
#handled_template ⇒ Object
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_path ⇒ Object
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 |
#render ⇒ Object
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() = 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() 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 |