Skip to content

Commit

Permalink
Use a bootstrap_form_for wrapper for README examples that display e…
Browse files Browse the repository at this point in the history
…rrors (bootstrap-ruby#637)

* Removed the wrapping `form` tag for examples that don't include the `bootstrap_form_for` wrapper
* Added email to the standard user + help text in example 2
  • Loading branch information
donv authored Apr 28, 2022
1 parent c0318db commit 8a9e34c
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 293 deletions.
530 changes: 249 additions & 281 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demo/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
capybara-screenshot-diff (1.6.0)
capybara-screenshot-diff (1.6.1)
actionpack (>= 4.2, < 8)
capybara (>= 2, < 4)
chunky_png (~> 1.3)
Expand Down Expand Up @@ -177,7 +177,7 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
regexp_parser (2.3.0)
regexp_parser (2.3.1)
reline (0.3.1)
io-console (~> 0.5)
rexml (3.2.5)
Expand Down
8 changes: 2 additions & 6 deletions demo/app/controllers/bootstrap_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ def form
def fragment
@erb = params[:erb]

unless @erb.start_with? "<%= bootstrap"
@erb.prepend "<%= bootstrap_form_with model: @user, layout: :horizontal, local: true do |f| %>\n"
@erb << "<% end %>"
end
@erb.prepend '<div class="p-3 border">'
@erb << "</div>"
load_models
Expand All @@ -24,9 +20,9 @@ def load_models
Address.new(id: 2, street: "Bar")
]

@user = User.new
@user = User.new email: '[email protected]'

@user_with_error = User.new
@user_with_error = User.new email: 'steve.example.com'
@user_with_error.errors.add(:email)
@user_with_error.errors.add(:misc)
end
Expand Down
Binary file modified demo/doc/screenshots/bootstrap/readme/00_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/02_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/05_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/06_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/07_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/12_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/22_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/31_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/32_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/34_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/35_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/36_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/37_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/38_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/39_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/40_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/41_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/42_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/45_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 19 additions & 4 deletions demo/test/system/bootstrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,37 @@ class BootstrapTest < ApplicationSystemTestCase
end
end

HEADERS = "This generates|Which outputs|will be rendered as".freeze
HEADERS = ["Generated HTML", "This generates", "Which outputs", "will be rendered as"].join("|").freeze
REGEXP =
/(?:!\[[^\]]*\]\([^)]+\)\s*)?```erb\n(.*?)\n```\s*((?:#{HEADERS}).*?$)?\s*(```html\n(?:.*?)\n```\s*)?/mi
.freeze
test "readme examples" do
screenshot_group :readme

readme = File.read(File.expand_path("../../../README.md", __dir__))
augmented_readme = readme.gsub(REGEXP).with_index do |_, i|
augmented_readme = readme.gsub(REGEXP) do |_|
erb = Regexp.last_match(1)
header = Regexp.last_match(2)
unless /\A<%= bootstrap[^>]*>\n\s*...\s*<% end %>\z/.match? erb
visit fragment_path erb: erb
if erb.start_with? "<%= bootstrap"
wrapped_erb = erb
else
wrapped_erb = <<~ERB
<%= bootstrap_form_with model: @user, layout: :horizontal, local: true do |f| %>
#{erb}
<% end %>
ERB
end

visit fragment_path erb: wrapped_erb
wrapper = find(".p-3")
i = @screenshot_counter
screenshot :example, crop: bounds(wrapper)
if wrapped_erb != erb
wrapper = wrapper.find('form')
end
html = wrapper["innerHTML"].strip.gsub("><", ">\n<")
assert html.present?, erb
doc = Nokogiri::HTML.fragment(html)
doc.traverse do |node|
if node.is_a?(Nokogiri::XML::Element)
Expand All @@ -48,7 +63,7 @@ class BootstrapTest < ApplicationSystemTestCase
MD
html = <<~MD
#{header || 'This generates:'}
#{header || 'Generated HTML:'}
```html
#{HtmlBeautifier.beautify(html)}
Expand Down

0 comments on commit 8a9e34c

Please sign in to comment.