Skip to content

Commit

Permalink
Builders::Base html_escape method added
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Jan 21, 2015
1 parent bb47cfc commit 2f3e94e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion releaf-core/app/helpers/releaf/builders/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Releaf::Builders::Base
:releaf_button, :params, :form_tag, :file_field_tag,
:request, :check_box_tag, :label_tag, :content_tag, :hidden_field_tag,
:render, :link_to, :flash, :truncate, :toolbox, :radio_button_tag,
:options_for_select, :action_name, :html_escape, :options_from_collection_for_select,
:options_for_select, :action_name, :options_from_collection_for_select,
:select_tag, :text_field_tag,
:image_tag, :jquery_date_format, :cookies, :button_tag, :merge_attributes, to: :template

Expand All @@ -22,6 +22,10 @@ def wrapper(content_or_attributes_with_block, attributes = {}, &block)
end
end

def html_escape(value)
ERB::Util.html_escape(value)
end

def tag(*args, &block)
return content_tag(*args) unless block_given?

Expand Down
10 changes: 9 additions & 1 deletion releaf-core/spec/helpers/builders/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BuilderIncluder
:releaf_button, :params, :form_tag, :file_field_tag,
:request, :check_box_tag, :label_tag, :content_tag, :hidden_field_tag,
:render, :link_to, :flash, :truncate, :toolbox, :radio_button_tag,
:options_for_select, :action_name, :html_escape, :options_from_collection_for_select,
:options_for_select, :action_name, :options_from_collection_for_select,
:select_tag, :text_field_tag,
:image_tag, :jquery_date_format, :cookies, :button_tag, :merge_attributes
].each do|method_name|
Expand All @@ -40,6 +40,14 @@ class BuilderIncluder
end
end

describe "#html_escape" do
it "escapes given value with " do
allow(ERB::Util).to receive(:html_escape).with("a").and_return("b")
expect(subject.html_escape("a")).to eq("b")
end
end


it "aliases #button to #releaf_button" do
allow(subject.template).to receive(:releaf_button).with("x", a: "y", b: "z").and_return("xx")
expect(subject.button("x", a: "y", b: "z")).to eq("xx")
Expand Down

0 comments on commit 2f3e94e

Please sign in to comment.