geo_scaffold 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79af904e67bbb7df082dd34d5b41c3ed63675404242b4d065b10eb3689385398
4
- data.tar.gz: 9aaa8a8c1c569a859e3081c664385c92abc84a0655bb2767a5497c8f4e1e83b8
3
+ metadata.gz: 37f4e153574fa4e376e1a1eb7b77d66e47c99394096e95fc12f018c2d2ee5a5c
4
+ data.tar.gz: 75d922313c9287144215fd8df9127b83f010cf2108827ac20b8790f3ef2ba305
5
5
  SHA512:
6
- metadata.gz: bf499763ac20ce1c5d51129b716d6beb177cedd452516049735713a34ed31064b295dc330275fa137aa6a51371df8f54a24a83d82f1c56ba2d23275b1c63103b
7
- data.tar.gz: 92ae4a8f89aa098d16359ffbd14a6bec758b4eb832b7bde97b24c8a366575b3b1f51d54c67b77f682ebdfe64d3d50e8c9be2a94f1236718b468bf757ba96e663
6
+ metadata.gz: a3a5cf5b536dda13778288d9a73e35e913a6bf05824123a521be676c48ea95653314dd493072c70e0fe2723a5ea726cbf3545920c2265f644b9ad063e1e11552
7
+ data.tar.gz: 416db3d052f9ebedf25b0a6224a5dddba181e76f614f3caa6e331b42976068b8df4660a6e4c14903b96d131088a3e9d5f5c5b132cf6ea169356bb9b91249f727
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geo_scaffold (0.1.1)
4
+ geo_scaffold (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,7 +4,7 @@ GeoScaffold generates views with [Geolonia Maps](https://geolonia.com/maps-dev/)
4
4
 
5
5
  Geolonia Maps can be freely used without API key on [development environments](https://docs.geolonia.com/tutorial/002/#%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E3%81%A7%E3%81%AE%E5%88%A9%E7%94%A8%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) such as localhost, CodePen and JSFiddle etc.
6
6
 
7
- ![Demo](geo_scaffold_demo.gif)
7
+ ![Demo](geo_scaffold.gif)
8
8
 
9
9
  ## Installation
10
10
 
@@ -24,24 +24,27 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- Generate a model for a new resource that has coordinates.
27
+ Use GeoScaffold generator to create model, view and controller files.
28
+ You need to add `name` and coordinates(`lat` and `lng`) as columns.
28
29
 
29
30
  ```
30
- % bin/rails g model <resource name> name:string lng:float lat:float
31
+ % bin/rails g geo_scaffold:scaffold <resource name> name:string lat:float lng:float
31
32
  ```
32
33
 
33
- Run the migration.
34
+ You may add attachment column like `photo` and it will be handled as an image.
34
35
 
35
36
  ```
36
- % bin/rails db:migrate
37
+ % bin/rails g geo_scaffold:scaffold <resource name> name:string photo:attachment lat:float lng:float
37
38
  ```
38
39
 
39
- Use GeoScaffold generator to create controllers and views.
40
+ In this case, you need to install Active Storage.
40
41
 
41
42
  ```
42
- % bin/rails g geo_scaffold:controller <resource name>
43
+ % bin/rails active_storage:install
43
44
  ```
44
45
 
46
+ ![Demo](install_geo_scaffold.gif)
47
+
45
48
  ## Development
46
49
 
47
50
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/geo_scaffold.gif ADDED
Binary file
Binary file
@@ -2,7 +2,7 @@ require 'generators/geo_scaffold/generator_helpers'
2
2
 
3
3
  module GeoScaffold
4
4
  module Generators
5
- class ControllerGenerator < Rails::Generators::NamedBase
5
+ class ScaffoldGenerator < Rails::Generators::NamedBase
6
6
  include Rails::Generators::ResourceHelpers
7
7
  include GeoScaffold::Generators::GeneratorHelpers
8
8
 
@@ -17,9 +17,11 @@ module GeoScaffold
17
17
  invoke resource_route
18
18
  end
19
19
 
20
- desc "Generates controller, controller_spec and views for the model with the given NAME."
20
+ hook_for :orm, as: :model
21
21
 
22
- def copy_controller_and_spec_files
22
+ desc "Generates model, controller and views for the model with the given NAME."
23
+
24
+ def copy_controller_file
23
25
  template "controller.rb", File.join("app/controllers", "#{controller_file_name}_controller.rb")
24
26
  end
25
27
 
@@ -38,19 +40,6 @@ module GeoScaffold
38
40
  def copy_helper_files
39
41
  template "helpers/helper.rb", File.join("app/helpers", "#{controller_file_name}_helper.rb")
40
42
  end
41
-
42
- protected
43
- def model_columns_for_attributes
44
- class_name.constantize.columns.reject do |column|
45
- column.name.to_s =~ /^(id|created_at|updated_at)$/
46
- end
47
- end
48
-
49
- def attributes
50
- model_columns_for_attributes.map do |column|
51
- Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
52
- end
53
- end
54
43
  end
55
44
  end
56
45
  end
@@ -1,64 +1,66 @@
1
1
  <% module_namespacing do -%>
2
- class <%= controller_class_name %>Controller < ApplicationController
3
- before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
4
-
5
- # GET <%= route_url %>
6
- def index
7
- @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
8
- end
9
-
10
- # GET <%= route_url %>/1
11
- def show
12
- end
13
-
14
- # GET <%= route_url %>/new
15
- def new
16
- @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
17
- end
18
-
19
- # GET <%= route_url %>/1/edit
20
- def edit
2
+ class <%= plural_table_name.capitalize %>Controller < ApplicationController
3
+ before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
4
+
5
+ # GET <%= route_url %>
6
+ def index
7
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
8
+ end
9
+
10
+ # GET <%= route_url %>/1
11
+ def show
12
+ end
13
+
14
+ # GET <%= route_url %>/new
15
+ def new
16
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
17
+ end
18
+
19
+ # GET <%= route_url %>/1/edit
20
+ def edit
21
+ end
22
+
23
+ # POST <%= route_url %>
24
+ def create
25
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
26
+
27
+ if @<%= orm_instance.save %>
28
+ redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
29
+ else
30
+ render :new, status: :unprocessable_entity
21
31
  end
22
-
23
- # POST <%= route_url %>
24
- def create
25
- @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
26
-
27
- if @<%= orm_instance.save %>
28
- redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
29
- else
30
- render :new, status: :unprocessable_entity
31
- end
32
+ end
33
+
34
+ # PATCH/PUT <%= route_url %>/1
35
+ def update
36
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
37
+ redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
38
+ else
39
+ render :edit, status: :unprocessable_entity
32
40
  end
33
-
34
- # PATCH/PUT <%= route_url %>/1
35
- def update
36
- if @<%= orm_instance.update("#{singular_table_name}_params") %>
37
- redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
38
- else
39
- render :edit, status: :unprocessable_entity
40
- end
41
+ end
42
+
43
+ # DELETE <%= route_url %>/1
44
+ def destroy
45
+ @<%= orm_instance.destroy %>
46
+ redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
47
+ end
48
+
49
+ private
50
+
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_<%= singular_table_name %>
53
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
41
54
  end
42
-
43
- # DELETE <%= route_url %>/1
44
- def destroy
45
- @<%= orm_instance.destroy %>
46
- redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
55
+
56
+ # Only allow a list of trusted parameters through.
57
+ def <%= "#{singular_table_name}_params" %>
58
+ <%- if attributes_names.empty? -%>
59
+ params.fetch(:<%= singular_table_name %>, {})
60
+ <%- else -%>
61
+ params.require(:<%= singular_table_name %>).permit(<%= attributes.map { |a| ":#{a.name}" }.join(', ') %>)
62
+ <%- end -%>
47
63
  end
48
-
49
- private
50
- # Use callbacks to share common setup or constraints between actions.
51
- def set_<%= singular_table_name %>
52
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
53
- end
54
-
55
- # Only allow a list of trusted parameters through.
56
- def <%= "#{singular_table_name}_params" %>
57
- <%- if attributes_names.empty? -%>
58
- params.fetch(:<%= singular_table_name %>, {})
59
- <%- else -%>
60
- params.require(:<%= singular_table_name %>).permit(<%= attributes.map { |a| ":#{a.name}" }.join(', ') %>)
61
- <%- end -%>
62
- end
63
- end
64
- <% end -%>
64
+
65
+ end
66
+ <% end -%>
@@ -1,7 +1,17 @@
1
1
  module <%= controller_class_name %>Helper
2
2
  def marker_content(<%= singular_table_name %>)
3
- <%= singular_table_name %>.attributes.except("id", "created_at", "updated_at", "lat", "lng").map do |key, value|
4
- "<strong>#{key}</strong> #{key == 'name' ? link_to(value, <%= singular_table_name %>) : value }<br />"
5
- end.join.html_safe
3
+ html = ""
4
+ <% attributes.reject {|attribute| attribute.password_digest? || ["lat", "lng"].include?(attribute.column_name)}.each do |attribute| -%>
5
+ <% if attribute.attachment? -%>
6
+
7
+ # To use variant of image, you need to add 'image_processing' gem to your Gemfile."
8
+ # html << "<strong><%= attribute.human_name %>:</strong> #{image_tag <%= singular_name %>.<%= attribute.column_name %>.variant(resize: "100x100^")}<br />" if <%= singular_name %>.<%= attribute.column_name %>.attached?
9
+ html << "<strong><%= attribute.human_name %>:</strong> #{image_tag <%= singular_name %>.<%= attribute.column_name %>, width: '100%'}<br />" if <%= singular_name %>.<%= attribute.column_name %>.attached?
10
+
11
+ <% else -%>
12
+ html << "<strong><%= attribute.human_name %>:</strong> #{<%= singular_name %>.<%= attribute.column_name %>}<br />"
13
+ <% end -%>
14
+ <% end -%>
15
+ return html.html_safe
6
16
  end
7
- end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GeoScaffold
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junya Ishihara
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-17 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: GeoScaffold generates views with Geolonia Maps for a new resource that
14
14
  has coordinates(lat and lng).
@@ -29,9 +29,10 @@ files:
29
29
  - Rakefile
30
30
  - bin/console
31
31
  - bin/setup
32
- - geo_scaffold_demo.gif
33
- - lib/generators/geo_scaffold/controller_generator.rb
32
+ - geo_scaffold.gif
33
+ - install_geo_scaffold.gif
34
34
  - lib/generators/geo_scaffold/generator_helpers.rb
35
+ - lib/generators/geo_scaffold/scaffold_generator.rb
35
36
  - lib/generators/geo_scaffold/templates/controller.rb
36
37
  - lib/generators/geo_scaffold/templates/helpers/helper.rb
37
38
  - lib/generators/geo_scaffold/templates/views/_form.html.erb
@@ -52,7 +53,7 @@ metadata:
52
53
  homepage_uri: https://github.com/champierre/geo_scaffold
53
54
  source_code_uri: https://github.com/champierre/geo_scaffold
54
55
  changelog_uri: https://github.com/champierre/geo_scaffold
55
- post_install_message:
56
+ post_install_message:
56
57
  rdoc_options: []
57
58
  require_paths:
58
59
  - lib
@@ -67,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  requirements: []
70
- rubygems_version: 3.3.26
71
- signing_key:
71
+ rubygems_version: 3.0.3
72
+ signing_key:
72
73
  specification_version: 4
73
74
  summary: GeoScaffold
74
75
  test_files: []
Binary file