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

Hanami 2 #199

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bdf9560
Make the specs to build again
jodosha Mar 2, 2022
dddcaec
Move `Hanami::Helpers::RoutingHelper` to `hanami` as `Hanami::Helpers…
jodosha Mar 4, 2022
38c940f
Port `Hanami::Helpers::NumberFormattingHelper` to Hanami 2
jodosha Mar 4, 2022
d78bf5e
Removed empty file
jodosha Mar 4, 2022
88ef4cb
`Hanami::Helpers::NumberFormattingHelper` API docs and minor enhancem…
jodosha Mar 4, 2022
b712e0f
Only include helpers that have been ported to Hanami 2
jodosha Mar 4, 2022
2606095
Temporarily disable integration tests
jodosha Mar 4, 2022
6664ea2
Make `Hanami::Helpers::NumberFormattingHelper#format_number` a public…
jodosha Mar 4, 2022
ac8c477
Partially port `Hanami::Helpers::HtmlHelper` to 2.0
jodosha Mar 4, 2022
16d96b8
First draft of new implementation of HTMLBuilder
jodosha Mar 5, 2022
0324caa
Done with new implementation of `Hanami::Helpers::HtmlHelper::HtmlBui…
jodosha Mar 6, 2022
4625ccc
Remove unnecessary code under `Hanami::Helpers::HtmlHelper` namespace
jodosha Mar 6, 2022
537c6cb
Ported `Hanami::Helpers::LinkToHelper`
jodosha Mar 6, 2022
97ed532
Fix Rubocop. Remove file committed accidentally.
jodosha Mar 6, 2022
54a34a0
First draft to port `Hanami::Helpers::FormHelper` to Hanami 2
jodosha Mar 7, 2022
df40ce1
More work on Form builder
jodosha Mar 7, 2022
83ce540
Moar work on form builder
jodosha Mar 7, 2022
e4c4755
Even moar work on form builder
jodosha Mar 8, 2022
b6bdaea
Form helper, ya know..
jodosha Mar 8, 2022
71609a6
Yet more work on form builder
jodosha Mar 9, 2022
9fb4865
Still working on form helper
jodosha Mar 9, 2022
d94e1cf
Small work on form builder
jodosha Mar 9, 2022
60c3ee0
Ported more form helper methods
jodosha Mar 9, 2022
185960b
Remove no longer necessary class
jodosha Mar 10, 2022
acb79b1
Use `dry-inflector` for form label humanization
jodosha Mar 10, 2022
dc8575a
First pass of form builder cleanup
jodosha Mar 10, 2022
c4c14ce
Second pass of form helper cleanup
jodosha Mar 10, 2022
82bd172
Optimize the default case of HTML input `value` calculation
jodosha Mar 10, 2022
e9ebf71
`Hanami::Helpers::FormHelper::Values` remove from `case` statement `H…
jodosha Mar 10, 2022
50f2d47
Form builder API docs
jodosha Mar 10, 2022
fd542af
Include all the helpers when including `Hanami::Helpers`
jodosha Mar 10, 2022
2e5d7a8
CHANGELOG
jodosha Mar 11, 2022
72c38f1
Move `Hanami::Helpers::FormHelper` into `hanami`
jodosha Apr 22, 2022
c9861d7
`Hanami::Helpers::HtmlHelper::HtmlBuilder#clear`
jodosha Jun 14, 2022
03219f4
Point to the right branch for dry-rb/dry-core
jodosha Jun 14, 2022
d2b828c
Rubocop
jodosha Jun 14, 2022
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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Layout/LineLength:
- "spec/**/*.rb"
Lint/EmptyBlock:
Exclude:
- "spec/unit/hanami/helpers/form_helper_spec.rb"
- "spec/**/*.rb"
81 changes: 78 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,84 @@
# Hanami::Helpers
View helpers for Ruby web applications

## v2.0.0.alpha1 (unreleased)
## v2.0.0.alpha8 (unreleased)
### Fixed
- [Luca Guidi] `Hanami::Helpers::NumberFormattingHelper#format_number` to return consistent rounding. `1.0` will be formatted as `"1.00"` by default.

### Changed
- [Luca Guidi] Drop support for Ruby: MRI 2.3, 2.4, and 2.5
- [Luca Guidi] Drop support for Ruby: MRI 2.3, 2.4, 2.5, 2.6, and 2.7
- [Luca Guidi] Moved `Hanami::Helpers::RoutingHelper` to `hanami` as `Hanami::Helpers::Routes`
- [Luca Guidi] Made `Hanami::Helpers::NumberFormattingHelper#format_number` a public method
- [Luca Guidi] `Hanami::Helpers::NumberFormattingHelper#format_number` raises a `Hanami::Helpers::CoercionError` instead of `TypeError`
- [Luca Guidi] `Hanami::Helpers::NumberFormattingHelper#form_for` removed the first argument that used to indicate the form name prefix
```ruby
# 1.0
form_for(:book, routes.books_path) {}

# => <form action="/path" method="POST" id="book-form"></form>

# 2.0
form_for(routes.books_path, id: "book-form") {}

# => <form action="/path" method="POST" id="book-form"></form>
```
- [Luca Guidi] `Hanami::Helpers::NumberFormattingHelper#form_for` yields a `Hanami::Helpers::FormHelper::FormBuilder` object that MUST be used to generate form inputs
```ruby
# 1.0
form_for(:book, routes.books_path) do
text_field :title

submit "Create book"
end

# <form action="/path" method="POST" id="book-form">
# <input type="text" name="book[title]" id="book-title">
# <button type="submit">Create book</button>
# </form>

# 2.0
form_for(routes.books_path, id: "book-form") do |f|
f.text_field "book.title"

f.submit "Create book"
end

# <form action="/path" method="POST" id="book-form">
# <input type="text" name="book[title]" id="book-title">
# <button type="submit">Create book</button>
# </form>
```
- [Luca Guidi] Form input helpers now require full path to be always specified as a dot separated `String`
```ruby
# 1.0
form_for(:book, routes.books_path) do
fields_for :author do
fields_for :avatar do
text_field :url
end
end

submit "Create book"
end

# <form action="/path" method="POST" id="book-form">
# <input type="text" name="book[author][avatar][url]" id="book-author-avatar-url">
# <button type="submit">Create book</button>
# </form>

# 2.0
form_for(routes.books_path, id: "book-form") do |f|
f.text_field "book.author.avatar.url"

f.submit "Create book"
end

# <form action="/path" method="POST" id="book-form">
# <input type="text" name="book[author][avatar][url]" id="book-author-avatar-url">
# <button type="submit">Create book</button>
# </form>
```
- [Luca Guidi] Removed `fields_for` form helper

## v1.3.3 - 2020-02-03
### Added
Expand Down Expand Up @@ -165,5 +240,5 @@ View helpers for Ruby web applications
## v0.1.0 - 2015-03-23
### Added
- [Luca Guidi] Introduced `Lotus::Helpers::RoutingHelper`. It exposes `#routes` in views for compatibility with Lotus (`hanamirb` gem)
- [Alfonso Uceda Pompa] Introduced `Lotus::Helpers::EscapeHelper`. It implements OWASP/ESAPI suggestions for HTML, HTML attribute and URL escape helpers.
- [Alfonso Uceda Pompa] Introduced `Lotus::Helpers::EscapeHelper`. It implements O1.0P/ESAPI suggestions for HTML, HTML attribute and URL escape helpers.
Copy link

Choose a reason for hiding this comment

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

was this intentional?

- [Luca Guidi] Introduced `Lotus::Helpers::HtmlHelper`. It allows to generate complex HTML5 markup with Ruby.
12 changes: 8 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ gemspec
unless ENV["CI"]
gem "byebug", require: false, platforms: :mri
gem "yard", require: false
gem "benchmark-ips", require: false
end

gem "hanami-utils", "~> 1.3", git: "https://github.com/hanami/utils.git", branch: "1.3.x"
gem "dry-core", git: "http://github.com/dry-rb/dry-core", branch: "main"
gem "erbse"

gem "hanami-utils", "~> 2.0.alpha", git: "https://github.com/hanami/utils.git", branch: "main"
gem "hanami-validations", "~> 2.0.alpha", git: "https://github.com/hanami/validations.git", branch: "main"
gem "hanami-controller", "~> 1.3", git: "https://github.com/hanami/controller.git", branch: "1.3.x"
gem "hanami-view", "~> 1.3", git: "https://github.com/hanami/view.git", branch: "1.3.x"
gem "hanami-controller", "~> 2.0.alpha", git: "https://github.com/hanami/controller.git", branch: "main"
gem "hanami-view", "~> 2.0.alpha", git: "https://github.com/hanami/view.git", branch: "main"

gem "hanami-devtools", git: "https://github.com/hanami/devtools.git", branch: "1.3.x", require: false
gem "hanami-devtools", git: "https://github.com/hanami/devtools.git", branch: "main", require: false
10 changes: 8 additions & 2 deletions hanami-helpers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-helpers.gemspec`.split($/)

spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.metadata["rubygems_mfa_required"] = "true"

spec.required_ruby_version = ">= 3.0"

spec.add_dependency "hanami-utils", "~> 1.3"
spec.add_dependency "hanami-utils", "~> 2.0.alpha"
spec.add_dependency "escape_utils", "~> 1.2"
spec.add_dependency "temple", "~> 0.8"
spec.add_dependency "dry-types", "~> 1.5"
spec.add_dependency "dry-core", "~> 0.7"
spec.add_dependency "dry-inflector", "~> 0.2"

spec.add_development_dependency "bundler", ">= 1.6", "< 3"
spec.add_development_dependency "dry-struct", "~> 1.1"
spec.add_development_dependency "rake", "~> 13"
spec.add_development_dependency "rspec", "~> 3.9"
spec.add_development_dependency "rubocop", "~> 1.0"
spec.add_development_dependency "erbse", "~> 0.1"
spec.add_development_dependency "slim", "~> 4.1"
end
19 changes: 8 additions & 11 deletions lib/hanami/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# frozen_string_literal: true

require "hanami/helpers/version"
require "hanami/helpers/html_helper"
require "hanami/helpers/escape_helper"
require "hanami/helpers/routing_helper"
require "hanami/helpers/link_to_helper"
require "hanami/helpers/form_helper"
require "hanami/helpers/number_formatting_helper"

# @since 0.1.0
module Hanami
# View helpers for Ruby applications
#
# @since 0.1.0
module Helpers
require "hanami/helpers/version"
require "hanami/helpers/errors"
require "hanami/helpers/html_helper"
require "hanami/helpers/link_to_helper"
require "hanami/helpers/number_formatting_helper"

# Override for Module.included
#
# It injects all the available helpers.
Expand All @@ -25,12 +23,11 @@ module Helpers
def self.included(base)
base.class_eval do
include Hanami::Helpers::HtmlHelper
include Hanami::Helpers::EscapeHelper
include Hanami::Helpers::RoutingHelper
include Hanami::Helpers::LinkToHelper
include Hanami::Helpers::FormHelper
include Hanami::Helpers::NumberFormattingHelper
end

super
end
end
end
15 changes: 15 additions & 0 deletions lib/hanami/helpers/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Hanami
module Helpers
# @api public
# @since 2.0.0
class Error < ::StandardError
end

# @api public
# @since 2.0.0
class CoercionError < Error
end
end
end
23 changes: 23 additions & 0 deletions lib/hanami/helpers/escape.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "temple/utils"
require "temple/html/safe"
require "escape_utils"

module Hanami
module Helpers
module Escape
def self.call(string)
Temple::Utils.escape_html_safe(string)
end

def self.safe_string(string)
Temple::HTML::SafeString.new(string.to_s)
end

def self.uri(string)
::EscapeUtils.escape_uri(string)
end
end
end
end
5 changes: 3 additions & 2 deletions lib/hanami/helpers/escape_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "hanami/helpers/escape"
require "hanami/utils/escape"

module Hanami
Expand Down Expand Up @@ -74,7 +75,7 @@ module EscapeHelper
# view.evil_content
# # => "<div>\n&lt;script&gt;alert(&apos;xss&apos;)&lt;&#x2F;script&gt;</div>"
def escape_html(input)
Utils::Escape.html(input)
Helpers::Escape.(input)
end

# @since 0.1.0
Expand Down Expand Up @@ -267,7 +268,7 @@ def escape_url(input, schemes = Utils::Escape::DEFAULT_URL_SCHEMES)
# view.evil_content
# # => "<script>alert('xss')</script>"
def raw(input)
Utils::Escape::SafeString.new(input)
Helpers::Escape.safe_string(input)
end
end
end
Expand Down
Loading