Module: Tungsten::DeploymentsHelper

Defined in:
app/helpers/tungsten/deployments_helper.rb

Instance Method Summary collapse

Instance Method Details

#deployment_data(name = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/tungsten/deployments_helper.rb', line 3

def deployment_data(name = nil)
  deployments = Cyborg.config_data['deployments']['deployments']

  if name.nil?
    deployments
  else
    deployment = deployments.find { |d|
      d[:name] =~ /#{name}/i || d[:slug] == name
    }

    if deployment.nil? && !Rails.env.production?
      raise %Q{No deployment type "#{name}" exists.}
    end

    deployment
  end
end

#deployment_graphicObject



21
22
23
# File 'app/helpers/tungsten/deployments_helper.rb', line 21

def deployment_graphic
  @deployment_icon ||= Esvg.find_symbol('deployment')
end

#deployment_icon(name, options = {}) ⇒ Object



54
55
56
57
58
# File 'app/helpers/tungsten/deployments_helper.rb', line 54

def deployment_icon(name, options={})
  options[:stroke_width] ||= 8
  options[:text] ||= { "font-weight" => 600, "font-size" => "76px" }
  deployment_svg name, options
end

#deployment_svg(name, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/tungsten/deployments_helper.rb', line 39

def deployment_svg(name, options={})
  data = deployment_data(name)
  (options[:use] ||= {})
  options[:use][:stroke] ||= options.delete(:stroke) || "currentColor"
  options[:use][:stroke_width] ||= options.delete(:stroke_width) || 4
  options[:use][:class] = "deployment-icon-hex #{options[:use][:class]}".strip

  options[:color]   ||= "#fff"
  options[:fill]    ||= "none"
  # options[:fill]    ||= "url(##{data[:name].downcase}-gradient-bg)"
  options[:content] ||= deployment_text(data[:short_name], options.delete(:text) || {})

  deployment_graphic.use(options).html_safe
end

#deployment_text(text, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/tungsten/deployments_helper.rb', line 25

def deployment_text(text, options={})
  options = {
    x: deployment_graphic.width.to_f / 2,
    y: deployment_graphic.height.to_f / 2, fill: "currentColor",
    "font-weight" => 700,
    "font-size" => "57px",
    "text-anchor" => "middle",
    "dominant-baseline" =>"central",
    "alignment-baseline" => "central"
  }.merge(options)

  (:text, text, options).html_safe
end