madmin 1.0.0.beta2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e0427cd7d7dd77a86ef9b7cfd6b08af93cc2f6f542a7992b69d63328c483e26
4
- data.tar.gz: f85af965580b168e7efa890049ca58a46d9710ab3484ed99b45acf7267a7859c
3
+ metadata.gz: 40199d348bebb973f7b9dc6b6a850bd5c68ff022643384a65acfc59960f86dbb
4
+ data.tar.gz: 7f672c9ad00abe803c5be58c57da8c163d944a5a7d152af6e4471830f3460ee9
5
5
  SHA512:
6
- metadata.gz: b63ca0956bd1a730d686b7f35252e951f0bb88743df2a2d9fa025120a82647a141e1e20dae3052f889e4d1db7bbf69328ab26e1285d1c602a58b0e625f084eed
7
- data.tar.gz: 11783c59ee3445c594dd2ce51ea5b24ee5942d59f59a2ae6f444ff8991f353e298473f6dfcf8e38c923248458dd38957cd3d8aead6e4c18d1821abcce023a10e
6
+ metadata.gz: c27c66fa995081db788c99036b9a5cd4ea1bec2aaf7d3450a4c633fed0b9e8a9b73658dbc8eda4df0e9f894010f88f4696126c3f1322a886706f8f91195ca3fe
7
+ data.tar.gz: 4311d571bca085e92b2dad5902a2ede438347efdb910897fe391efe5764bb9a37b2c1c1228d376e305d11d2fb6712f3d8f4077e4d024dc5d017fdf9e53a14dbe
data/README.md CHANGED
@@ -37,6 +37,29 @@ To generate a resource for a model, you can run:
37
37
  rails g madmin:resource ActionText::RichText
38
38
  ```
39
39
 
40
+ ## Configuring Views
41
+
42
+ The views packaged within the gem are a great starting point, but inevitably people will need to be able to customize those views.
43
+
44
+ You can use the included generator to create the appropriate view files, which can then be customized.
45
+
46
+ For example, running the following will copy over all of the views into your application that will be used for every resource:
47
+ ```bash
48
+ rails generate madmin:views
49
+ ```
50
+
51
+ If you only need to customize specific views, you can restrict which views are copied by the generator:
52
+ ```bash
53
+ rails g madmin:views:index
54
+ # -> app/views/madmin/application/index.html.erb
55
+ ```
56
+
57
+ You can also scope the copied view(s) to a specific Resource/Model:
58
+ ```bash
59
+ rails generate madmin:views:index Book
60
+ # -> app/views/madmin/books/index.html.erb
61
+ ```
62
+
40
63
  ## 🙏 Contributing
41
64
 
42
65
  This project uses Standard for formatting Ruby code. Please make sure to run standardrb before submitting pull requests.
@@ -0,0 +1,16 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class EditGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_edit
10
+ copy_resource_template("edit")
11
+ copy_resource_template("_form")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class FormGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_form
10
+ copy_resource_template("_form")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class IndexGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_template
10
+ copy_resource_template("index")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class LayoutGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_template
10
+ copy_file(
11
+ "../../layouts/madmin/application.html.erb",
12
+ "app/views/layouts/madmin/application.html.erb"
13
+ )
14
+
15
+ call_generator("madmin:views:navigation")
16
+ copy_resource_template("_javascript")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class NavigationGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_navigation
10
+ copy_resource_template("_navigation")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class NewGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_new
10
+ copy_resource_template("new")
11
+ copy_resource_template("_form")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ module Views
6
+ class ShowGenerator < Madmin::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_template
10
+ copy_resource_template("show")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "madmin/view_generator"
2
+
3
+ module Madmin
4
+ module Generators
5
+ class ViewsGenerator < Madmin::ViewGenerator
6
+ def copy_templates
7
+ view = "madmin:views:"
8
+ call_generator("#{view}index", resource_path, "--namespace", namespace)
9
+ call_generator("#{view}show", resource_path, "--namespace", namespace)
10
+ call_generator("#{view}new", resource_path, "--namespace", namespace)
11
+ call_generator("#{view}edit", resource_path, "--namespace", namespace)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ module Madmin
2
+ class Namespace
3
+ def initialize(namespace)
4
+ @namespace = namespace
5
+ end
6
+
7
+ def resources
8
+ @resources ||= routes.map(&:first).uniq.map { |path|
9
+ Resource.new(namespace, path)
10
+ }
11
+ end
12
+
13
+ def routes
14
+ @routes ||= all_routes.select { |controller, _action|
15
+ controller.starts_with?("#{namespace}/")
16
+ }.map { |controller, action|
17
+ [controller.gsub(/^#{namespace}\//, ""), action]
18
+ }
19
+ end
20
+
21
+ def resources_with_index_route
22
+ routes.select { |_resource, route| route == "index" }.map(&:first).uniq
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :namespace
28
+
29
+ def all_routes
30
+ Rails.application.routes.routes.map do |route|
31
+ route.defaults.values_at(:controller, :action).map(&:to_s)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "1.0.0.beta2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require "rails/generators/base"
2
+ require "madmin/generator_helpers"
3
+ require "madmin/namespace"
4
+
5
+ module Madmin
6
+ class ViewGenerator < Rails::Generators::Base
7
+ include Madmin::GeneratorHelpers
8
+ class_option :namespace, type: :string, default: "madmin"
9
+
10
+ def self.template_source_path
11
+ File.expand_path(
12
+ "../../../app/views/madmin/application",
13
+ __FILE__
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ def namespace
20
+ options[:namespace]
21
+ end
22
+
23
+ def copy_resource_template(template_name)
24
+ template_file = "#{template_name}.html.erb"
25
+
26
+ copy_file(
27
+ template_file,
28
+ "app/views/#{namespace}/#{resource_path}/#{template_file}"
29
+ )
30
+ end
31
+
32
+ def resource_path
33
+ args.first.try(:underscore).try(:pluralize) || BaseResourcePath.new
34
+ end
35
+
36
+ class BaseResourcePath
37
+ def to_s
38
+ "application"
39
+ end
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
@@ -131,6 +131,14 @@ files:
131
131
  - lib/generators/madmin/resource/resource_generator.rb
132
132
  - lib/generators/madmin/resource/templates/controller.rb.tt
133
133
  - lib/generators/madmin/resource/templates/resource.rb.tt
134
+ - lib/generators/madmin/views/edit_generator.rb
135
+ - lib/generators/madmin/views/form_generator.rb
136
+ - lib/generators/madmin/views/index_generator.rb
137
+ - lib/generators/madmin/views/layout_generator.rb
138
+ - lib/generators/madmin/views/navigation_generator.rb
139
+ - lib/generators/madmin/views/new_generator.rb
140
+ - lib/generators/madmin/views/show_generator.rb
141
+ - lib/generators/madmin/views/views_generator.rb
134
142
  - lib/madmin.rb
135
143
  - lib/madmin/engine.rb
136
144
  - lib/madmin/field.rb
@@ -153,8 +161,10 @@ files:
153
161
  - lib/madmin/fields/text.rb
154
162
  - lib/madmin/fields/time.rb
155
163
  - lib/madmin/generator_helpers.rb
164
+ - lib/madmin/namespace.rb
156
165
  - lib/madmin/resource.rb
157
166
  - lib/madmin/version.rb
167
+ - lib/madmin/view_generator.rb
158
168
  - lib/tasks/madmin_tasks.rake
159
169
  homepage: https://github.com/excid3/madmin
160
170
  licenses:
@@ -171,9 +181,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
181
  version: 2.5.0
172
182
  required_rubygems_version: !ruby/object:Gem::Requirement
173
183
  requirements:
174
- - - ">"
184
+ - - ">="
175
185
  - !ruby/object:Gem::Version
176
- version: 1.3.1
186
+ version: '0'
177
187
  requirements: []
178
188
  rubygems_version: 3.2.3
179
189
  signing_key: