From d3984f0cd78a1e7f400fbb9e49a38f1f289ccb96 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 5 Sep 2023 10:55:02 +0300 Subject: [PATCH] Convert erb2hamlit --- Gemfile | 5 ++ Gemfile.lock | 27 ++++++++ app/views/api_wrapper/index.html.erb | 66 ------------------- app/views/api_wrapper/index.html.haml | 42 ++++++++++++ .../api_wrapper/latest_activities.html.erb | 45 ------------- .../api_wrapper/latest_activities.html.haml | 29 ++++++++ app/views/layouts/application.html.erb | 17 ----- app/views/layouts/application.html.haml | 13 ++++ app/views/layouts/mailer.html.erb | 13 ---- app/views/layouts/mailer.html.haml | 8 +++ app/views/layouts/mailer.text.erb | 1 - app/views/layouts/mailer.text.haml | 1 + app/views/shared/_flash_message.html.erb | 19 ------ app/views/shared/_flash_message.html.haml | 11 ++++ 14 files changed, 136 insertions(+), 161 deletions(-) delete mode 100644 app/views/api_wrapper/index.html.erb create mode 100644 app/views/api_wrapper/index.html.haml delete mode 100644 app/views/api_wrapper/latest_activities.html.erb create mode 100644 app/views/api_wrapper/latest_activities.html.haml delete mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/application.html.haml delete mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.html.haml delete mode 100644 app/views/layouts/mailer.text.erb create mode 100644 app/views/layouts/mailer.text.haml delete mode 100644 app/views/shared/_flash_message.html.erb create mode 100644 app/views/shared/_flash_message.html.haml diff --git a/Gemfile b/Gemfile index 2d0bc78..32f5349 100644 --- a/Gemfile +++ b/Gemfile @@ -52,3 +52,8 @@ group :test do gem 'rspec-rails', '~> 6.0.2' gem 'shoulda-matchers', '~> 5.3.0' end + +gem "hamlit", "~> 3.0" +gem "hamlit-rails", "~> 0.2.3" + +gem "html2haml", "~> 2.3" diff --git a/Gemfile.lock b/Gemfile.lock index 300361b..9a7a8c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -130,6 +130,7 @@ GEM dry-schema (>= 1.12, < 2) zeitwerk (~> 2.6) erubi (1.12.0) + erubis (2.7.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -142,6 +143,24 @@ GEM ffaker (2.21.0) globalid (1.1.0) activesupport (>= 5.0) + haml (6.1.2) + temple (>= 0.8.2) + thor + tilt + hamlit (3.0.3) + temple (>= 0.8.2) + thor + tilt + hamlit-rails (0.2.3) + actionpack (>= 4.0.1) + activesupport (>= 4.0.1) + hamlit (>= 1.2.0) + railties (>= 4.0.1) + html2haml (2.3.0) + erubis (~> 2.7.0) + haml (>= 4.0) + nokogiri (>= 1.6.0) + ruby_parser (~> 3.5) i18n (1.14.1) concurrent-ruby (~> 1.0) interactor (3.1.2) @@ -296,6 +315,9 @@ GEM rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) + ruby_parser (3.20.3) + sexp_processor (~> 4.16) + sexp_processor (4.17.0) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) sprockets (4.2.0) @@ -308,7 +330,9 @@ GEM stringio (3.0.8) strong_migrations (1.6.1) activerecord (>= 5.2) + temple (0.10.2) thor (1.2.2) + tilt (2.2.0) timeout (0.4.0) traceroute (0.8.1) rails (>= 3.0.0) @@ -343,6 +367,9 @@ DEPENDENCIES factory_bot_rails (~> 6.2.0) faraday (~> 2.7.10) ffaker (~> 2.21.0) + hamlit (~> 3.0) + hamlit-rails (~> 0.2.3) + html2haml (~> 2.3) interactor-rails (~> 2.2.1) jbuilder (~> 2.11.5) jsbundling-rails (~> 1.1.2) diff --git a/app/views/api_wrapper/index.html.erb b/app/views/api_wrapper/index.html.erb deleted file mode 100644 index bf670ad..0000000 --- a/app/views/api_wrapper/index.html.erb +++ /dev/null @@ -1,66 +0,0 @@ -
-

Find Your Activity for Today

-
- <%= form_with url: "/api_wrapper", method: :get, class: 'form-inline' do |form| %> -
- <%= form.label :type, "Activity type:", class: 'mr-2' %> - <%= form.select :type, %w[education recreational social diy charity cooking relaxation music busywork], { :include_blank => true }, { class: "form-control mr-2" } %> -
- -
- <%= form.label :participants, "Number of participants:", class: 'mr-2' %> - <%= form.number_field :participants, placeholder: "1-8", step: 1, class: "form-control mr-2" %> -
- -
- <%= form.label :minprice, "Minimum price:", class: 'mr-2' %> - <%= form.number_field :minprice, placeholder: "0-0.8", step: 0.1, class: "form-control mr-2" %> -
- -
- <%= form.label :maxprice, "Maximum price:", class: 'mr-2' %> - <%= form.number_field :maxprice, placeholder: "0-0.9", step: 0.1, class: "form-control mr-2" %> -
- -
- <%= form.label :minaccessibility, "Minimum accessibility:", class: 'mr-2' %> - <%= form.number_field :minaccessibility, placeholder: "0-0.9", step: 0.1, class: "form-control mr-2" %> -
- -
- <%= form.label :maxaccessibility, "Maximum accessibility:", class: 'mr-2' %> - <%= form.number_field :maxaccessibility, placeholder: "0-0.9", step: 0.1, class: "form-control mr-2" %> -
- - <%= form.submit "Search", class: "btn btn-primary mt-2 mb-2" %> - <% end %> -
- - <% if @activity.present? %> -
-

Activity details:

- - - - - - - - - - - - - - - - - - - -
ActivityTypeParticipantsPriceLink
<%= @activity["activity"] %><%= @activity["type"] %><%= @activity["participants"] %><%= @activity["price"] %><%= link_to @activity["link"], @activity["link"], target: "_blank" %>
-
- <% end %> - - <%= link_to 'View Activity History', latest_activities_path, class: 'btn btn-primary mt-2 mb-2' %> -
\ No newline at end of file diff --git a/app/views/api_wrapper/index.html.haml b/app/views/api_wrapper/index.html.haml new file mode 100644 index 0000000..48e0ef3 --- /dev/null +++ b/app/views/api_wrapper/index.html.haml @@ -0,0 +1,42 @@ +.container + %h1 Find Your Activity for Today + %div + = form_with url: "/api_wrapper", method: :get, class: 'form-inline' do |form| + .form-group.mt-2.mb-2 + = form.label :type, "Activity type:", class: 'mr-2' + = form.select :type, %w[education recreational social diy charity cooking relaxation music busywork], { :include_blank => true }, { class: "form-control mr-2" } + .form-group.mt-2.mb-2 + = form.label :participants, "Number of participants:", class: 'mr-2' + = form.number_field :participants, placeholder: "1-8", step: 1, class: "form-control mr-2" + .form-group.mt-2.mb-2 + = form.label :minprice, "Minimum price:", class: 'mr-2' + = form.number_field :minprice, placeholder: "0-0.8", step: 0.1, class: "form-control mr-2" + .form-group.mt-2.mb-2 + = form.label :maxprice, "Maximum price:", class: 'mr-2' + = form.number_field :maxprice, placeholder: "0-0.9", step: 0.1, class: "form-control mr-2" + .form-group.mt-2.mb-2 + = form.label :minaccessibility, "Minimum accessibility:", class: 'mr-2' + = form.number_field :minaccessibility, placeholder: "0-0.9", step: 0.1, class: "form-control mr-2" + .form-group.mt-2.mb-2 + = form.label :maxaccessibility, "Maximum accessibility:", class: 'mr-2' + = form.number_field :maxaccessibility, placeholder: "0-0.9", step: 0.1, class: "form-control mr-2" + = form.submit "Search", class: "btn btn-primary mt-2 mb-2" + - if @activity.present? + %div + %h2 Activity details: + %table.table.table-striped + %thead + %tr + %th Activity + %th Type + %th Participants + %th Price + %th Link + %tbody + %tr + %td= @activity["activity"] + %td= @activity["type"] + %td= @activity["participants"] + %td= @activity["price"] + %td= link_to @activity["link"], @activity["link"], target: "_blank" + = link_to 'View Activity History', latest_activities_path, class: 'btn btn-primary mt-2 mb-2' diff --git a/app/views/api_wrapper/latest_activities.html.erb b/app/views/api_wrapper/latest_activities.html.erb deleted file mode 100644 index 1ac2c1d..0000000 --- a/app/views/api_wrapper/latest_activities.html.erb +++ /dev/null @@ -1,45 +0,0 @@ -
-

Activities search history

- - <%= form_with url: latest_activities_path, method: :get, class: 'form-inline mb-3' do |form| %> -
- <%= form.label :sort, "Sort By:", class: 'mr-2' %> - <%= form.select :sort, %w[activity_type participants price created_at accessibility], {selected: params[:sort]}, { class: "form-control mr-2" } %> -
-
- <%= form.label :order, "Order:", class: 'mr-2' %> - <%= form.select :order, %w[asc desc], {selected: params[:order]}, { class: "form-control mr-2" } %> -
- <%= form.submit "Apply", class: "btn btn-primary mt-2 mb-2" %> - <% end %> - - <% if @activities.present? %> - - - - - - - - - - - <% @activities.each do |activity| %> - - - - - - - <% end %> - -
TypeParticipantsPriceDate
<%= activity.activity_type %><%= activity.participants %><%= activity.price %><%= activity.created_at.strftime('%Y-%m-%d %H:%M:%S') %>
- - <%== pagy_bootstrap_nav @pagy if @pagy && @pagy.pages > 1 %> - - <% else %> -

No activities found.

- <% end %> - - <%= link_to 'Back and find your activity', api_wrapper_path, class: 'btn btn-primary mt-2 mb-2' %> -
diff --git a/app/views/api_wrapper/latest_activities.html.haml b/app/views/api_wrapper/latest_activities.html.haml new file mode 100644 index 0000000..2c10822 --- /dev/null +++ b/app/views/api_wrapper/latest_activities.html.haml @@ -0,0 +1,29 @@ +.container + %h1 Activities search history + = form_with url: latest_activities_path, method: :get, class: 'form-inline mb-3' do |form| + .form-group.mt-2.mb-2 + = form.label :sort, "Sort By:", class: 'mr-2' + = form.select :sort, %w[activity_type participants price created_at accessibility], {selected: params[:sort]}, { class: "form-control mr-2" } + .form-group.mt-2.mb-2 + = form.label :order, "Order:", class: 'mr-2' + = form.select :order, %w[asc desc], {selected: params[:order]}, { class: "form-control mr-2" } + = form.submit "Apply", class: "btn btn-primary mt-2 mb-2" + - if @activities.present? + %table.table.table-striped + %thead + %tr + %th Type + %th Participants + %th Price + %th Date + %tbody + - @activities.each do |activity| + %tr + %td= activity.activity_type + %td= activity.participants + %td= activity.price + %td= activity.created_at.strftime('%Y-%m-%d %H:%M:%S') + != pagy_bootstrap_nav @pagy if @pagy && @pagy.pages > 1 + - else + %p No activities found. + = link_to 'Back and find your activity', api_wrapper_path, class: 'btn btn-primary mt-2 mb-2' diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index 3c2f5c9..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,17 +0,0 @@ - - - - Simple api wrapper - - <%= csrf_meta_tags %> - <%= csp_meta_tag %> - - <%= stylesheet_link_tag "application" %> - <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> - - - - <%= render partial: 'shared/flash_message' %> - <%= yield %> - - diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..a4fb2bf --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,13 @@ +!!! +%html + %head + %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ + %title Simple api wrapper + %meta{:content => "width=device-width,initial-scale=1", :name => "viewport"}/ + = csrf_meta_tags + = csp_meta_tag + = stylesheet_link_tag "application" + = javascript_include_tag "application", "data-turbo-track": "reload", defer: true + %body + = render partial: 'shared/flash_message' + = yield diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb deleted file mode 100644 index cbd34d2..0000000 --- a/app/views/layouts/mailer.html.erb +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - <%= yield %> - - diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml new file mode 100644 index 0000000..cbf6b8e --- /dev/null +++ b/app/views/layouts/mailer.html.haml @@ -0,0 +1,8 @@ +!!! +%html + %head + %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/ + :css + /* Email styles need to be inline */ + %body + = yield diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb deleted file mode 100644 index 37f0bdd..0000000 --- a/app/views/layouts/mailer.text.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> diff --git a/app/views/layouts/mailer.text.haml b/app/views/layouts/mailer.text.haml new file mode 100644 index 0000000..0a90f09 --- /dev/null +++ b/app/views/layouts/mailer.text.haml @@ -0,0 +1 @@ += yield diff --git a/app/views/shared/_flash_message.html.erb b/app/views/shared/_flash_message.html.erb deleted file mode 100644 index 4c1a669..0000000 --- a/app/views/shared/_flash_message.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% if notice.present? %> - -<% end %> - -<% if alert.present? %> - -<% end %> diff --git a/app/views/shared/_flash_message.html.haml b/app/views/shared/_flash_message.html.haml new file mode 100644 index 0000000..6fe1d12 --- /dev/null +++ b/app/views/shared/_flash_message.html.haml @@ -0,0 +1,11 @@ +- if notice.present? + .alert.alert-success{:role => "alert"} + = notice +- if alert.present? + .alert.alert-danger{:role => "alert"} + - if alert.is_a?(Dry::Validation::MessageSet) + %ul + - alert.each do |error| + %li= "#{error.path.join(' ') } #{error.text}" + - else + = alert