Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tang rufus add skip display none #218

Merged
merged 2 commits into from
Jan 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Lint/HandleExceptions:

# Offense count: 1
Metrics/AbcSize:
Max: 23
Max: 24

# Offense count: 1
# Configuration parameters: CountComments.
Expand All @@ -69,4 +69,3 @@ Metrics/ModuleLength:
Style/GlobalVars:
Exclude:
- 'spec/dummy/config/environments/development.rb'

2 changes: 1 addition & 1 deletion app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def react_component(component_name, props = {}, options = {})
content_tag(:div,
"",
class: "js-react-on-rails-component",
style: "display:none",
style: ReactOnRails.configuration.skip_display_none ? nil : "display:none",
data: data)

# Create the HTML rendering part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
config.prerender = false
# Default is true for development, off otherwise
config.trace = Rails.env.development?
# Default is false, enable if your content security policy doesn't include `style-src: 'unsafe-inline'`
config.skip_display_none = false
end
10 changes: 7 additions & 3 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ def self.configuration
trace: Rails.env.development?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these files getting permissions changes. Sounds accidental.

lib/react_on_rails/configuration.rb 100644 → 100755

I'd change the files back to the original settings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this, I believe the were changed in the original PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

development_mode: Rails.env.development?,
server_renderer_pool_size: 1,
server_renderer_timeout: 20)
server_renderer_timeout: 20,
skip_display_none: false)
end

class Configuration
attr_accessor :server_bundle_js_file, :prerender, :replay_console,
:trace, :development_mode,
:logging_on_server, :server_renderer_pool_size,
:server_renderer_timeout, :raise_on_prerender_error
:server_renderer_timeout, :raise_on_prerender_error,
:skip_display_none

def initialize(server_bundle_js_file: nil, prerender: nil, replay_console: nil,
trace: nil, development_mode: nil,
logging_on_server: nil, server_renderer_pool_size: nil,
server_renderer_timeout: nil, raise_on_prerender_error: nil)
server_renderer_timeout: nil, raise_on_prerender_error: nil,
skip_display_none: nil)
if File.exist?(server_bundle_js_file)
self.server_bundle_js_file = server_bundle_js_file
else
Expand All @@ -43,6 +46,7 @@ def initialize(server_bundle_js_file: nil, prerender: nil, replay_console: nil,
end
self.trace = trace.nil? ? Rails.env.development? : trace
self.raise_on_prerender_error = raise_on_prerender_error
self.skip_display_none = skip_display_none

# Server rendering:
self.server_renderer_pool_size = self.development_mode ? 1 : server_renderer_pool_size
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/config/initializers/react_on_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
# Server rendering only (not for render_component helper)
config.server_renderer_pool_size = 1 # increase if you're on JRuby
config.server_renderer_timeout = 20 # seconds

# Default is false, enable if your content security policy doesn't include `style-src: 'unsafe-inline'`
config.skip_display_none = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go into the generators as well? or too obscure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end
31 changes: 31 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 @@ -74,6 +74,37 @@
it { is_expected.not_to include react_component_div }
it { is_expected.to include react_definition_div }
end

context "with skip_display_none option true" do
before { ReactOnRails.configuration.skip_display_none = true }

let(:react_definition_div_skip_display_none_true) do
"<div class=\"js-react-on-rails-component\"
data-component-name=\"App\"
data-props=\"{&quot;name&quot;:&quot;My Test Name&quot;}\"
data-trace=\"false\"
data-expect-turbolinks=\"true\"
data-dom-id=\"#{id}\"></div>".squish
end

it { is_expected.to include react_definition_div_skip_display_none_true }
end

context "with skip_display_none option false" do
before { ReactOnRails.configuration.skip_display_none = false }

let(:react_definition_div_skip_display_none_false) do
"<div class=\"js-react-on-rails-component\"
style=\"display:none\"
data-component-name=\"App\"
data-props=\"{&quot;name&quot;:&quot;My Test Name&quot;}\"
data-trace=\"false\"
data-expect-turbolinks=\"true\"
data-dom-id=\"#{id}\"></div>".squish
end

it { is_expected.to include react_definition_div_skip_display_none_false }
end
end

describe "#server_render_js" do
Expand Down
13 changes: 13 additions & 0 deletions spec/react_on_rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@ module ReactOnRails
expect(ReactOnRails.configuration.server_bundle_js_file).to eq("client/dist/something.js")
expect(ReactOnRails.configuration.prerender).to eq(true)
end

context "skip display: none" do
it "will default false" do
expect(ReactOnRails.configuration.skip_display_none).to eq(false)
end

it "will be true if set to true" do
ReactOnRails.configure do |config|
config.skip_display_none = true
end
expect(ReactOnRails.configuration.skip_display_none).to eq(true)
end
end
end
end