Skip to content
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ ReActionView.configure do |config|

# Enable debug mode
config.debug_mode = Rails.env.development?

# Validation mode (:raise or :overlay) — defaults to :raise in test, :overlay otherwise
# config.validation_mode = :overlay
end
```

Expand All @@ -62,6 +65,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/marcor

Everyone interacting in the ReActionView project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/reactionview/blob/main/CODE_OF_CONDUCT.md).

## License
## License

This project is available as open source under the terms of the [MIT License](https://github.com/marcoroth/reactionview/blob/main/LICENSE.txt).
3 changes: 3 additions & 0 deletions lib/generators/reactionview/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def create_initializer
# Enable debug mode in development (adds debug attributes to HTML)
config.debug_mode = Rails.env.development?

# Validation mode (:raise or :overlay) — defaults to :raise in test, :overlay otherwise
# config.validation_mode = :overlay

# Add custom transform visitors to process templates before compilation
# config.transform_visitors = [
# Herb::Visitor::new
Expand Down
7 changes: 7 additions & 0 deletions lib/reactionview/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ class Config
attr_accessor :intercept_erb
attr_accessor :debug_mode
attr_accessor :transform_visitors
attr_writer :validation_mode

def initialize
@intercept_erb = false
@debug_mode = nil
@transform_visitors = []
end

def validation_mode
return @validation_mode unless @validation_mode.nil?

test? ? :raise : :overlay
end

def development?
defined?(Rails) && Rails.env.development?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/reactionview/template/handlers/herb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def call(template, source)
config = {
filename: template.identifier,
project_path: Rails.root.to_s,
validation_mode: :overlay,
validation_mode: ReActionView.config.validation_mode,
content_for_head: reactionview_dev_tools_markup(template),
visitors: visitors + ReActionView.config.transform_visitors,
}
Expand Down
49 changes: 49 additions & 0 deletions test/reactionview/config_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require_relative "../test_helper"

class ReActionView::ConfigTest < Minitest::Spec
test "defaults to :raise in test environment" do
config = ReActionView::Config.new

def config.test?
true
end

assert_equal :raise, config.validation_mode
end

test "defaults to :overlay in non-test environments" do
config = ReActionView::Config.new

def config.test?
false
end

assert_equal :overlay, config.validation_mode
end

test "explicit :overlay overrides test environment default" do
config = ReActionView::Config.new

def config.test?
true
end

config.validation_mode = :overlay

assert_equal :overlay, config.validation_mode
end

test "explicit :raise overrides non-test environment default" do
config = ReActionView::Config.new

def config.test?
false
end

config.validation_mode = :raise

assert_equal :raise, config.validation_mode
end
end
Loading