Skip to content

Commit

Permalink
dynamic html tag. html_options{tag:span} Wrapper component in SPAN #480
Browse files Browse the repository at this point in the history
… (#1208)
  • Loading branch information
tahsin352 authored and justin808 committed Apr 23, 2019
1 parent 58bdc34 commit e6c6d0f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*
### [11.3.0] - 2019-04-20
#### Added
- html_options can now has option for 'tag' to add dynamically html element. like this : html_options{tag:'span'}.
[PR 1208](https://github.com/shakacode/react_on_rails/pull/1208) by [tahsin352](https://github.com/tahsin352).

### [11.2.2] - 2018-12-24
#### Improved
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ gem "web-console", group: :development
# below are copied from spec/dummy/Gemfile
gem "capybara"
gem "capybara-screenshot"
gem "chromedriver-helper"
gem "launchy"
gem "rspec-rails"
gem "rspec-retry"
gem "selenium-webdriver"
gem "webdrivers", "~> 3.0"
gem "webpacker"

gem "equivalent-xml", github: "mbklein/equivalent-xml"
Expand Down
8 changes: 7 additions & 1 deletion lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,15 @@ def build_react_component_result_for_server_rendered_string(
render_options: required("render_options")
)
content_tag_options = render_options.html_options
if content_tag_options.key?(:tag)
content_tag_options_html_tag = content_tag_options[:tag]
content_tag_options.delete(:tag)
else
content_tag_options_html_tag = "div"
end
content_tag_options[:id] = render_options.dom_id

rendered_output = content_tag(:div,
rendered_output = content_tag(content_tag_options_html_tag.to_sym,
server_rendered_html.html_safe,
content_tag_options)

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ group :test do
gem "coveralls", require: false
# install trouble with updated
# gem "capybara-webkit"
gem "chromedriver-helper"
gem "equivalent-xml", github: "mbklein/equivalent-xml"
gem "generator_spec"
gem "launchy"
gem "rspec-rails"
gem "rspec-retry"
gem "selenium-webdriver"
gem "webdrivers", "~> 3.0"
end
14 changes: 14 additions & 0 deletions spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@
expect(result).not_to match(/data-trace=/)
end
end

context "with 'html_options' tag option" do
subject { react_component("App", html_options: { tag: "span" }) }

it { is_expected.to include '<span id="App-react-component-0"></span>' }
it { is_expected.not_to include '<div id="App-react-component-0"></div>' }
end

context "without 'html_options' tag option" do
subject { react_component("App") }

it { is_expected.not_to include '<span id="App-react-component-0"></span>' }
it { is_expected.to include '<div id="App-react-component-0"></div>' }
end
end

describe "#redux_store" do
Expand Down

0 comments on commit e6c6d0f

Please sign in to comment.