Module: Ratchet::IconHelper
- Defined in:
- app/helpers/ratchet/icon_helper.rb
Instance Method Summary collapse
- #deployment_graphic ⇒ Object
- #deployment_icon(name, options = {}) ⇒ Object
- #deployment_info(name) ⇒ Object
- #deployment_svg(name, options = {}) ⇒ Object
- #deployment_text(text, options = {}) ⇒ Object
- #deployment_topology(name, options = {}) ⇒ Object
- #deployments ⇒ Object
- #grid_bg(options = {}) ⇒ Object
- #topology_desc(part, deployment_name) ⇒ Object
Instance Method Details
#deployment_graphic ⇒ Object
18 19 20 |
# File 'app/helpers/ratchet/icon_helper.rb', line 18 def deployment_graphic Site.deployment_icon end |
#deployment_icon(name, options = {}) ⇒ Object
107 108 109 110 111 |
# File 'app/helpers/ratchet/icon_helper.rb', line 107 def deployment_icon(name, ={}) [:stroke_width] ||= 8 [:text] ||= { "font-weight" => 600, "font-size" => "76px" } deployment_svg name, end |
#deployment_info(name) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/ratchet/icon_helper.rb', line 4 def deployment_info(name) deployment = deployments[name.downcase] if deployment.nil? && !Rails.env.production? raise %Q{No deployment type "#{name}" exists.} end deployment end |
#deployment_svg(name, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/ratchet/icon_helper.rb', line 93 def deployment_svg(name, ={}) data = deployment_info(name) ([:use] ||= {}) [:use][:stroke] ||= .delete(:stroke) || "currentColor" [:use][:stroke_width] ||= .delete(:stroke_width) || 4 [:use][:class] ||= "deployment-icon-hex #{[:use][:class]}".strip [:fill] ||= "url(##{data[:gradient]})" [:color] ||= "#fff" [:content] ||= deployment_text(data[:short_name], .delete(:text) || {}) deployment_graphic.use().html_safe end |
#deployment_text(text, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/ratchet/icon_helper.rb', line 41 def deployment_text(text, ={}) = { 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() content_tag(:text, text, ).html_safe end |
#deployment_topology(name, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/ratchet/icon_helper.rb', line 56 def deployment_topology(name, ={}) data = deployment_info(name) components = data[:topology].map do |item| Esvg.find_symbol("topology/#{item}") end base = 153 # height of top plane [:spacing] ||= 10 # space between # Find height of each section heights = components.map(&:height).map { |h| h - base + [:spacing] } # Start coordinates at 0 y = [0].concat heights # Add previous height total to create next coordinate y = y.map.with_index { |h, i| y[0..i].reduce(:+) } # Full height = last calculated coordinate + base (minus the additional space) height = base + y.pop - [:spacing] use = components.map.with_index do |c, i| part_name = c.name.sub('topology-','') c.use_tag(y: y[i], width: c.width, height: c.height, class:'capsule', "aria-label" => topology_desc(part_name, name.downcase)) end.reverse.join attr = { version: "1.1", preserveAspectRatio: "xMidYMid meet", viewBox: "0 0 #{components.last.width} #{height}", 'aria-label' => "Topology of a #{data[:name]} deployment" }.merge() content_tag(:svg, attr) { use.html_safe } end |
#deployments ⇒ Object
14 15 16 |
# File 'app/helpers/ratchet/icon_helper.rb', line 14 def deployments Site.deployment_data['deployments'] end |
#grid_bg(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/ratchet/icon_helper.rb', line 22 def grid_bg(={}) = { scale: true, class: "svg-bg bottom centered", "aria-hidden" => true }.merge() use_svg "graphics/grid", end |
#topology_desc(part, deployment_name) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'app/helpers/ratchet/icon_helper.rb', line 32 def topology_desc(part, deployment_name) parts = Site.deployment_data['parts'] if parts[deployment_name] && parts[deployment_name][part] parts[deployment_name][part] else parts[part] end end |