turbo_material 0.2.15 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/app/assets/dist/turbo_material/tailwind.css +2552 -1
- data/app/assets/javascripts/turbo_material/material_menu_button_controller.js +8 -9
- data/app/helpers/turbo_material/menu_button_helper.rb +5 -3
- data/app/views/components/_menu_button.html.erb +10 -5
- data/config/tailwind.config.js +17 -15
- data/lib/generators/turbo_material/install_generator.rb +79 -0
- data/lib/tasks/install.rake +8 -0
- data/lib/turbo_material/configuration.rb +7 -0
- data/lib/turbo_material/version.rb +1 -1
- data/lib/turbo_material.rb +12 -1
- metadata +5 -2
@@ -1,7 +1,9 @@
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
2
|
-
import {
|
2
|
+
import { destroy } from "@rails/request.js";
|
3
|
+
|
3
4
|
export default class extends Controller {
|
4
5
|
menu = undefined;
|
6
|
+
static values = { logoutPath: String };
|
5
7
|
|
6
8
|
connect() {
|
7
9
|
mdc.ripple.MDCRipple.attachTo(this.element);
|
@@ -10,13 +12,12 @@ export default class extends Controller {
|
|
10
12
|
this.menu.setAnchorElement(button);
|
11
13
|
this.menu.setAnchorCorner(mdc.menu.Corner.BOTTOM_START);
|
12
14
|
this.menu.setFixedPosition(true);
|
13
|
-
useClickOutside(this);
|
14
15
|
}
|
15
16
|
|
16
17
|
disconnect() {
|
17
18
|
}
|
18
19
|
|
19
|
-
|
20
|
+
toggleMenu(event) {
|
20
21
|
if (this.menu.open) {
|
21
22
|
this.close();
|
22
23
|
} else {
|
@@ -32,12 +33,10 @@ export default class extends Controller {
|
|
32
33
|
this.menu.open = false;
|
33
34
|
}
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
event.preventDefault();
|
40
|
-
this.close();
|
36
|
+
async logout() {
|
37
|
+
const response = await destroy(this.logoutPathValue);
|
38
|
+
if (response.ok) {
|
39
|
+
window.location.reload();
|
41
40
|
}
|
42
41
|
}
|
43
42
|
}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module TurboMaterial
|
2
|
-
module MenuButtonHelper
|
3
|
-
def material_menu_button(kwargs = {})
|
4
|
-
render "components/menu_button", **kwargs
|
2
|
+
module MenuButtonHelper
|
3
|
+
def material_menu_button(kwargs = {}, &block)
|
4
|
+
render "components/menu_button", **kwargs do
|
5
|
+
capture(&block) if block_given?
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
-
<%# locals: (button_text:, menu_contents_partial:) %>
|
2
|
-
<div data-controller="material-menu-button" class="
|
1
|
+
<%# locals: (button_text:, menu_contents_partial: nil, logout_path: nil, custom_css: '!z-100', custom_surface_css: '') %>
|
2
|
+
<div data-controller="material-menu-button" class="<%= custom_css %>"
|
3
|
+
data-material-menu-button-logout-path-value="<%= logout_path %>">
|
3
4
|
<button class="mdc-button mdc-button--touch menu-item menu-button"
|
4
|
-
data-action="click->material-menu-button#
|
5
|
+
data-action="click->material-menu-button#toggleMenu">
|
5
6
|
<span class="mdc-button__ripple"></span>
|
6
7
|
<span class="mdc-button__focus-ring"></span>
|
7
8
|
<span class="mdc-button__label flex items-center">
|
@@ -9,7 +10,11 @@
|
|
9
10
|
<span class="material-icons">expand_more</span>
|
10
11
|
</span>
|
11
12
|
</button>
|
12
|
-
<div class="mdc-menu mdc-menu-surface
|
13
|
-
|
13
|
+
<div class="mdc-menu mdc-menu-surface <%= custom_surface_css %>">
|
14
|
+
<%- if block_given? -%>
|
15
|
+
<%= yield %>
|
16
|
+
<%- else -%>
|
17
|
+
<%= render partial: menu_contents_partial %>
|
18
|
+
<% end %>
|
14
19
|
</div>
|
15
20
|
</div>
|
data/config/tailwind.config.js
CHANGED
@@ -6,20 +6,22 @@ module.exports = {
|
|
6
6
|
pattern: /prose/,
|
7
7
|
},
|
8
8
|
],
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
content: [
|
10
|
+
'./public/*.html',
|
11
|
+
'./app/helpers/**/*.rb',
|
12
|
+
'./app/assets/javascript/**/*.js',
|
13
|
+
'./app/views/**/*.{erb,haml,html,slim}'
|
14
|
+
],
|
15
|
+
theme: {
|
16
|
+
extend: {
|
17
|
+
fontFamily: {
|
18
|
+
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
|
19
|
+
},
|
19
20
|
},
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
},
|
22
|
+
plugins: [
|
23
|
+
require('@tailwindcss/aspect-ratio'),
|
24
|
+
require('@tailwindcss/typography'),
|
25
|
+
require('@tailwindcss/container-queries'),
|
26
|
+
]
|
25
27
|
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboMaterial
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
START_MARKER = "// #{Engine.name} raw CSS. This section is auto-generated by the turbo_material installer.".freeze
|
8
|
+
END_MARKER = "// End of auto-generated #{Engine.name} raw CSS. Version:".freeze
|
9
|
+
HEAD_LINKS = <<-HTML.rstrip.freeze
|
10
|
+
|
11
|
+
|
12
|
+
<link href="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
|
13
|
+
<script src="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.js"></script>
|
14
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
15
|
+
HTML
|
16
|
+
|
17
|
+
def update_tailwind_config
|
18
|
+
tailwind_css_path = TurboMaterial::Engine.root.join('app/assets/dist/turbo_material/tailwind.css')
|
19
|
+
css_content = File.read(tailwind_css_path)
|
20
|
+
css_content.gsub!(/\/\*.*?\*\//m, '')
|
21
|
+
css_content.gsub!(/\{[^}]*}/m, '{}')
|
22
|
+
css_content.gsub!(/\\\[/, '[')
|
23
|
+
css_content.gsub!( /\\\]/, ']')
|
24
|
+
|
25
|
+
class_regex = /\.\\?(!?[-_a-zA-Z0-9\[\]]+)(?=[^}]*\{)/
|
26
|
+
classes = css_content.scan(class_regex).flatten.uniq.sort
|
27
|
+
|
28
|
+
tailwind_config_path = Rails.root.join('config/tailwind.config.js')
|
29
|
+
|
30
|
+
if tailwind_config_path.exist?
|
31
|
+
content_config = <<~CONFIG.strip_heredoc
|
32
|
+
#{START_MARKER}
|
33
|
+
{ raw: '<div class="#{classes.join(' ')}"></div>', extension: 'html' },
|
34
|
+
#{END_MARKER} #{TurboMaterial::VERSION}
|
35
|
+
CONFIG
|
36
|
+
|
37
|
+
if File.read(tailwind_config_path.to_s).include?(START_MARKER)
|
38
|
+
gsub_file tailwind_config_path, /#{Regexp.escape(START_MARKER)}.*?#{Regexp.escape(END_MARKER)}.*?$/m do |match|
|
39
|
+
content_config.strip
|
40
|
+
end
|
41
|
+
else
|
42
|
+
insert_into_file tailwind_config_path, after: "content: [" do
|
43
|
+
"\n" + content_config.strip
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_turbo_material_js_controllers
|
50
|
+
controllers_path = Rails.root.join('app/javascript/controllers/index.js')
|
51
|
+
if controllers_path.exist? && controllers_path.read.include?('eagerLoadControllersFrom("controllers", application)')
|
52
|
+
if controllers_path.read.include?('eagerLoadControllersFrom("turbo_material", application)')
|
53
|
+
puts "`app/javascript/controllers/index.js` already contains `eagerLoadControllersFrom(\"turbo_material\", application)`"
|
54
|
+
else
|
55
|
+
insert_into_file controllers_path, after: 'eagerLoadControllersFrom("controllers", application)' do
|
56
|
+
"\neagerLoadControllersFrom(\"turbo_material\", application)\n"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
puts "`app/javascript/controllers/index.js` does not exist or does not contain `eagerLoadControllersFrom(\"controllers\", application)`"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_material_components_web_to_app_layout
|
65
|
+
layout_path = Rails.root.join('app/views/layouts/application.html.erb')
|
66
|
+
if layout_path.exist? && layout_path.read.include?('<%= csp_meta_tag %>')
|
67
|
+
if layout_path.read.include?('<link href="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">')
|
68
|
+
puts "`app/views/layouts/application.html.erb` head already contains material components web links"
|
69
|
+
else
|
70
|
+
insert_into_file layout_path, after: '<%= csp_meta_tag %>' do
|
71
|
+
HEAD_LINKS
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
raise "`app/views/layouts/application.html.erb` does not exist or does not contain `<%= csp_meta_tag %>`"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/turbo_material.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
require "turbo_material/version"
|
2
2
|
require "turbo_material/engine"
|
3
|
+
require "turbo_material/configuration"
|
3
4
|
|
4
5
|
module TurboMaterial
|
5
|
-
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
6
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo_material
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Moiseev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- config/importmap.rb
|
156
156
|
- config/routes.rb
|
157
157
|
- config/tailwind.config.js
|
158
|
+
- lib/generators/turbo_material/install_generator.rb
|
158
159
|
- lib/lookbook/checkbox_preview.rb
|
159
160
|
- lib/lookbook/chips_input_preview.rb
|
160
161
|
- lib/lookbook/chips_select_preview.rb
|
@@ -165,8 +166,10 @@ files:
|
|
165
166
|
- lib/lookbook/select_preview.rb
|
166
167
|
- lib/lookbook/switch_preview.rb
|
167
168
|
- lib/lookbook/textarea_preview.rb
|
169
|
+
- lib/tasks/install.rake
|
168
170
|
- lib/tasks/turbo_material_tasks.rake
|
169
171
|
- lib/turbo_material.rb
|
172
|
+
- lib/turbo_material/configuration.rb
|
170
173
|
- lib/turbo_material/engine.rb
|
171
174
|
- lib/turbo_material/version.rb
|
172
175
|
homepage: https://github.com/full-stack-biz/turbo_material
|