Class: Macrocosm::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/macrocosm/template.rb

Defined Under Namespace

Classes: Position

Constant Summary collapse

Raw =
File.read(File.join(__dir__, 'template.html'))
Positions =
[]
Engine =
ERB.new(Positions.reduce(Raw){ |file, pos| file.sub(pos.regexp, pos.mark) })
Css =
'<style>' + File.read(File.join(__dir__, 'frontend', 'iview.4.3.2.css')) + '</style>'
Js =
['vue.2.6.12.min.js', 'iview.min.js', 'echarts.4.8.0.2.min.js', 'vue-echarts.4.0.2.min.js'].each_with_object([]) do |file, arr|
  code = File.read(File.join(__dir__, 'frontend', file))
  arr << '<script>' << code << '</script>'
end.join

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binding_values) ⇒ Template

Returns a new instance of Template.



52
53
54
# File 'lib/macrocosm/template.rb', line 52

def initialize(binding_values)
  @binding_values = {css: false, js: Js}.merge(binding_values)
end

Instance Attribute Details

#binding_valuesObject (readonly)

Returns the value of attribute binding_values.



50
51
52
# File 'lib/macrocosm/template.rb', line 50

def binding_values
  @binding_values
end

Instance Method Details

#renderObject



56
57
58
# File 'lib/macrocosm/template.rb', line 56

def render
  Engine.result(binding)
end