Skip to content

Commit

Permalink
Merge pull request #76 from skateman/view-helper
Browse files Browse the repository at this point in the history
Created a new helper for Controllers/Presenters capable of calling UI helper methods
  • Loading branch information
mzazrivec authored Jan 5, 2017
2 parents 7b500f7 + aec003d commit f23f5c4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
6 changes: 6 additions & 0 deletions app/helpers/view_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ViewHelper
extend ActionView::Context
extend ActionView::Helpers::TagHelper
extend ActionView::Helpers::TextHelper
extend ActionView::Helpers::CaptureHelper
end
2 changes: 1 addition & 1 deletion app/presenters/tree_node/assigned_server_role.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TreeNode
class AssignedServerRole < Node
set_attributes(:title, :image, :klass) do
title = content_tag(:strong) do
title = ViewHelper.content_tag(:strong) do
if @options[:tree] == :servers_by_role_tree
"#{_('Server')}: #{ERB::Util.html_escape(@object.name)} [#{@object.id}]"
else
Expand Down
6 changes: 3 additions & 3 deletions app/presenters/tree_node/compliance.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module TreeNode
class Compliance < Node
set_attribute(:title) do
capture do
concat content_tag(:strong, "#{_('Compliance Check on')}: ")
concat format_timezone(@object.timestamp, Time.zone, 'gtl')
ViewHelper.capture do
ViewHelper.concat ViewHelper.content_tag(:strong, "#{_('Compliance Check on')}: ")
ViewHelper.concat format_timezone(@object.timestamp, Time.zone, 'gtl')
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/presenters/tree_node/compliance_detail.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module TreeNode
class ComplianceDetail < Node
set_attribute(:title) do
capture do
concat content_tag(:strong, "#{_('Policy')}: ")
concat @object.miq_policy_desc
ViewHelper.capture do
ViewHelper.concat ViewHelper.content_tag(:strong, "#{_('Policy')}: ")
ViewHelper.concat @object.miq_policy_desc
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/presenters/tree_node/miq_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class MiqPolicy < Node
set_attribute(:image) { "100/miq_policy_#{@object.towhat.downcase}#{@object.active ? '' : '_inactive'}.png" }
set_attribute(:title) do
if @options[:tree] == :policy_profile_tree
capture do
concat content_tag(:strong, "#{ui_lookup(:model => @object.towhat)} #{@object.mode.titleize}: ")
concat ERB::Util.html_escape(@object.description)
ViewHelper.capture do
ViewHelper.concat ViewHelper.content_tag(:strong, "#{ui_lookup(:model => @object.towhat)} #{@object.mode.titleize}: ")
ViewHelper.concat ERB::Util.html_escape(@object.description)
end
else
@object.description
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/tree_node/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MiqServer < Node
tooltip = _("%{server}: %{server_name} [%{server_id}] (current)") %
{:server => ui_lookup(:model => @object.class.to_s), :server_name => @object.name, :server_id => @object.id}
tooltip += " (#{@object.status})" if @options[:tree] == :roles_by_server_tree
title = content_tag(:strong, ERB::Util.html_escape(tooltip))
title = ViewHelper.content_tag(:strong, ERB::Util.html_escape(tooltip))
else
tooltip = "#{ui_lookup(:model => @object.class.to_s)}: #{@object.name} [#{@object.id}]"
tooltip += " (#{@object.status})" if @options[:tree] == :roles_by_server_tree
Expand Down
5 changes: 0 additions & 5 deletions app/presenters/tree_node/node.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module TreeNode
class Node
include ActionView::Context
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::CaptureHelper

def initialize(object, parent_id, options)
@object = object
@parent_id = parent_id
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/tree_node/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Zone < Node
set_attributes(:title, :tooltip) do
if @options[:is_current]
tooltip = "#{ui_lookup(:model => @object.class.to_s)}: #{@object.description} (#{_('current')})"
title = content_tag(:strong, ERB::Util.html_escape(tooltip))
title = ViewHelper.content_tag(:strong, ERB::Util.html_escape(tooltip))
else
title = "#{ui_lookup(:model => @object.class.to_s)}: #{@object.description}"
tooltip = title
Expand Down

0 comments on commit f23f5c4

Please sign in to comment.