templates-rails 0.1.6 → 0.2.1

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: 9ba3404b80094f0d0f90ed138958043745a3baa8ce34dc8d53f8b23687a35110
4
- data.tar.gz: 391039bac56e0ea87e23095ff32a99698a31c9d700e2baf99e7ff21129e87ba0
3
+ metadata.gz: e9a04898081b6a1962d47d73e9d1e1a328e10dc957135808f8da06335fd3a43b
4
+ data.tar.gz: 770942c7484c6174911b7e4653c2f32bbfdfc63d5f0c296e710b717ed29c1c7f
5
5
  SHA512:
6
- metadata.gz: cffb5d6fdab47c90b9490cbe1a7ef46f259acc9cc700651cca738eb1b1bbd549dc14cddb9893e46f7bb7303f17450be9fc48e80f1a0f9d4cf723eab150dadd53
7
- data.tar.gz: b8cf1abb68cdae12b7a18c19a087c187657419f149b866b2b7292edeb2d3911b43a4ec61499d2aefdad4bb38ea64d0bd785ebdad0c83f9c826053733a6a4eac7
6
+ metadata.gz: b99c74fc2347ef62109b75abb0f660a189dbafa9cff3a1c1d5346ad32c309326b883e6d3ac24792ed938408195b1543f1bab8c96aaf332a42780fb8f85f0a9dc
7
+ data.tar.gz: f343e9a9d4900b4fb5df9135400646615e82a8b5da5159dd020b83fdf828cfc6a005a72eb1212eb579d3c2996253281a225ab565df280d497fac7d6b156079f7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.2.1 - 07-05-2026
4
+ * **Bug fix**: Move the engine's bundled `index` and `nested_index` views from `app/views/templates/` to `app/views/templates/templates/` (matching the namespaced `Templates::TemplatesController` view path). Host apps with their own `app/views/templates/` views were shadowing the engine's templates, causing `MissingTemplate` errors at the engine root. No host-app changes are needed — Rails resolves the views via the controller's natural lookup path.
5
+
6
+ ### 0.2.0 - 07-05-2026
7
+ * **Breaking**: `TemplatesController` is now namespaced as `Templates::TemplatesController` to avoid collisions with controllers of the same name in host apps. Routes inside the engine point at `templates/templates#index` / `templates/templates#show` automatically; no host-app changes are needed unless you reference the controller class directly.
8
+ * Added `Templates.mount_at` (default `/templates`) — configures the auto-mount path
9
+ * Added `Templates.views_path` (default `templates`) — configures the directory under `app/views/` that the engine scans and renders from. Lets you point the engine at an existing styleguide views tree without moving files
10
+ * Added `Templates.auto_mount` (default `true`) — set to `false` to mount the engine manually in the host app's `routes.rb` (e.g. behind a namespace or auth constraint)
11
+
3
12
  ### 0.1.5 - 14-07-2023
4
13
  * Added `Templates.parent_controller` configuration option
5
14
  * Fixed CI and updated checkout/branch strategy from V2 to V3
data/README.md CHANGED
@@ -18,10 +18,34 @@ Or install it yourself as:
18
18
 
19
19
 
20
20
  ## Setup
21
- To override the default inheritance controller for e.g. compatibility with tenant based applications where there is a differently named inheritance controller copy the line below to your desired environment (most likely `development.rb`). Our default is set to `ApplicationController` as it's commonly used. If you don't have an `ApplicationController`, set the `parent_controller` to e.g. `ActionController::Base`
21
+
22
+ All configuration can go in an initializer (e.g. `config/initializers/templates.rb`) or in an environment file like `config/environments/development.rb`. All options have sensible defaults — set only what you need to change.
22
23
 
23
24
  ```ruby
25
+ # Parent controller for Templates::TemplatesController. Default: 'ApplicationController'.
26
+ # Change this for tenant-based apps or when you don't have an ApplicationController
27
+ # (e.g. set to 'ActionController::Base').
24
28
  Templates.parent_controller = 'ApplicationController'
29
+
30
+ # Path the engine mounts at. Default: '/templates'.
31
+ Templates.mount_at = '/admin/styleguide'
32
+
33
+ # Directory under app/views/ that the engine reads templates from. Default: 'templates'.
34
+ # Set this to point the engine at an existing views tree without moving files.
35
+ Templates.views_path = 'admin/styleguide'
36
+
37
+ # When true (default) the engine auto-mounts at `Templates.mount_at`. Set to false to
38
+ # mount manually in your routes.rb — useful when you only want the styleguide
39
+ # available locally, or want to mount it inside a scope/constraint.
40
+ Templates.auto_mount = false
41
+ ```
42
+
43
+ If you set `auto_mount = false`, mount the engine yourself. A common pattern is
44
+ to expose the styleguide only in development and test:
45
+
46
+ ```ruby
47
+ # config/routes.rb
48
+ mount Templates::Engine => '/admin/styleguide' if Rails.env.local?
25
49
  ```
26
50
 
27
51
  ## TODO
@@ -0,0 +1,15 @@
1
+ module Templates
2
+ class TemplatesController < Templates.parent_controller.constantize
3
+ def index
4
+ render template: 'templates/templates/index', layout: 'templates/index'
5
+ end
6
+
7
+ def show
8
+ if params[:id].present? && File.directory?("./app/views/#{Templates.views_path}/#{params[:id]}")
9
+ render template: 'templates/templates/nested_index', layout: 'templates/index'
10
+ else
11
+ render "#{Templates.views_path}/#{params[:id]}", layout: 'templates/show'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  <% provide(:title, 'Templates') %>
2
2
 
3
3
  <div>
4
- <% Dir.children('./app/views/templates').excluding('partials').sort.each do |child| %>
4
+ <% Dir.children("./app/views/#{Templates.views_path}").excluding('partials').sort.each do |child| %>
5
5
  <%= link_to child.chomp('.html.erb').humanize.titleize, templates_engine.template_path(child.chomp('.html.erb')), class: 'button button--blue' %>
6
6
  <% end %>
7
7
  </div>
@@ -1,7 +1,7 @@
1
1
  <% provide(:title, params[:id].gsub('/', ' / ').titleize) %>
2
2
 
3
3
  <div>
4
- <% Dir.children("./app/views/templates/#{params[:id]}").excluding('partials').sort.each do |child| %>
4
+ <% Dir.children("./app/views/#{Templates.views_path}/#{params[:id]}").excluding('partials').sort.each do |child| %>
5
5
  <%= link_to child.chomp('.html.erb').humanize.titleize, templates_engine.template_path('') + params[:id] + '/' + child.chomp('.html.erb'), class: 'button button--blue' %>
6
6
  <% end %>
7
7
  </div>
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  Templates::Engine.routes.draw do
2
- root 'templates#index'
3
- get ':id', to: 'templates#show', as: :template, constraints: { id: /.*/ }
2
+ root 'templates/templates#index'
3
+ get ':id', to: 'templates/templates#show', as: :template, constraints: { id: /.*/ }
4
4
  end
@@ -1,8 +1,10 @@
1
1
  module Templates
2
2
  class Engine < ::Rails::Engine
3
3
  initializer 'templates', before: :load_config_initializers do
4
- Rails.application.routes.append do
5
- mount Templates::Engine => '/templates'
4
+ if Templates.auto_mount
5
+ Rails.application.routes.append do
6
+ mount Templates::Engine => Templates.mount_at
7
+ end
6
8
  end
7
9
  end
8
10
 
@@ -1,3 +1,3 @@
1
1
  module Templates
2
- VERSION = '0.1.6'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -7,4 +7,22 @@ module Templates
7
7
  # It needs to be a string so the parent controller reloads whenever there are changes in development.
8
8
  mattr_accessor :parent_controller
9
9
  @@parent_controller = 'ApplicationController'
10
+
11
+ # Path the engine mounts at. Used when `auto_mount` is true and as the default
12
+ # for users who mount the engine themselves.
13
+ mattr_accessor :mount_at
14
+ @@mount_at = '/templates'
15
+
16
+ # Directory under `app/views/` that the engine reads templates from. Used both
17
+ # for `Dir.children` listings on the index/nested_index pages and for the
18
+ # `render` paths in the controller. Set this to use an existing views tree
19
+ # without moving files.
20
+ mattr_accessor :views_path
21
+ @@views_path = 'templates'
22
+
23
+ # When true (default), the engine appends a mount point at `Templates.mount_at`
24
+ # during initialization. Set to false to mount manually in the host app's
25
+ # routes.rb (e.g. inside a namespace or behind authentication constraints).
26
+ mattr_accessor :auto_mount
27
+ @@auto_mount = true
10
28
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templates-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukasz Czapiewski
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -30,9 +29,9 @@ dependencies:
30
29
  - - ">="
31
30
  - !ruby/object:Gem::Version
32
31
  version: 7.0.0
33
- description: A templating system for creating and making design decisions for your
34
- Rails application. Make your design decisions before you build your application
35
- views.
32
+ description: Create View templates and bootstrap interfaces in HTML without controllers.
33
+ A system for creating and making design decisions. Make design decisions before
34
+ building your app.
36
35
  email:
37
36
  - luke@mmtm.io
38
37
  executables: []
@@ -43,11 +42,11 @@ files:
43
42
  - README.md
44
43
  - app/assets/config/templates_manifest.js
45
44
  - app/assets/stylesheets/templates/application.css
46
- - app/controllers/templates_controller.rb
45
+ - app/controllers/templates/templates_controller.rb
47
46
  - app/views/layouts/templates/index.html.erb
48
47
  - app/views/layouts/templates/show.html.erb
49
- - app/views/templates/index.html.erb
50
- - app/views/templates/nested_index.html.erb
48
+ - app/views/templates/templates/index.html.erb
49
+ - app/views/templates/templates/nested_index.html.erb
51
50
  - config/routes.rb
52
51
  - lib/install/templates.rb
53
52
  - lib/tasks/templates_tasks.rake
@@ -61,7 +60,6 @@ metadata:
61
60
  homepage_uri: https://github.com/Ancez/templates-rails
62
61
  source_code_uri: https://github.com/Ancez/templates-rails
63
62
  changelog_uri: https://github.com/Ancez/templates-rails/blob/master/CHANGELOG.md
64
- post_install_message:
65
63
  rdoc_options: []
66
64
  require_paths:
67
65
  - lib
@@ -76,9 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
74
  - !ruby/object:Gem::Version
77
75
  version: '0'
78
76
  requirements: []
79
- rubygems_version: 3.2.3
80
- signing_key:
77
+ rubygems_version: 4.0.6
81
78
  specification_version: 4
82
- summary: Simple to use templating system for your Rails application. Design your views
83
- before implementation.
79
+ summary: View templating system for your Rails application. Design your app.
84
80
  test_files: []
@@ -1,13 +0,0 @@
1
- class TemplatesController < Templates.parent_controller.constantize
2
- def index
3
- render :index, layout: 'templates/index'
4
- end
5
-
6
- def show
7
- if params[:id].present? && File.directory?("./app/views/templates/#{params[:id]}")
8
- render :nested_index, layout: 'templates/index'
9
- else
10
- render "templates/#{params[:id]}", layout: 'templates/show'
11
- end
12
- end
13
- end