Skip to content

Commit

Permalink
Merge branch 'release/v0.2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
bopm committed Sep 11, 2024
2 parents 145822e + b4eecb9 commit b674bba
Show file tree
Hide file tree
Showing 14 changed files with 2,718 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
turbo_material (0.2.16)
turbo_material (0.2.17)
importmap-rails (~> 2.0.1)
rails (~> 7.1, >= 7.1.2)
stimulus-rails (~> 1.3)
Expand Down
3 changes: 3 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web: bin/rails server --port 3200
css: bin/rails app:tailwindcss:watch

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ That list is based on the project from which this library is being extracted. If

## Usage

Run `rails turbo_material:install` to install the gem and add necessary files to your project. Alternatively, you can follow the steps below.

Add following to your `app/javascript/controllers/index.js` after `eagerLoadControllersFrom("controllers", application)` line:

```javascript
Expand All @@ -26,7 +28,6 @@ Add following to your `app/view/layouts/application.html.erb` in `<head>` sectio
<link href="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
<script src="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<%= stylesheet_link_tag "turbo_material/tailwind.css" %>
```

### Material Components for Web customizations
Expand Down
2,553 changes: 2,552 additions & 1 deletion app/assets/dist/turbo_material/tailwind.css

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

if ! gem list foreman -i --silent; then
echo "Installing foreman..."
gem install foreman
fi

# Default to port 3000 if not specified
export PORT="${PORT:-3000}"

# Let the debug gem allow remote connections,
# but avoid loading until `debugger` is called
export RUBY_DEBUG_OPEN="true"
export RUBY_DEBUG_LAZY="true"

exec foreman start -f Procfile.dev "$@"
32 changes: 17 additions & 15 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ module.exports = {
pattern: /prose/,
},
],
content: [
'./app/assets/stylesheets/**/*.css',
'./app/views/**/*.html.erb'
],
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
},
content: [
'./public/*.html',
'./app/helpers/**/*.rb',
'./app/assets/javascript/**/*.js',
'./app/views/**/*.{erb,haml,html,slim}'
],
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
},
plugins: [
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
]
},
plugins: [
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
]
}
79 changes: 79 additions & 0 deletions lib/generators/turbo_material/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

module TurboMaterial
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)

START_MARKER = "// #{Engine.name} raw CSS. This section is auto-generated by the turbo_material installer.".freeze
END_MARKER = "// End of auto-generated #{Engine.name} raw CSS. Version:".freeze
HEAD_LINKS = <<-HTML.rstrip.freeze
<link href="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
<script src="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
HTML

def update_tailwind_config
tailwind_css_path = TurboMaterial::Engine.root.join('app/assets/dist/turbo_material/tailwind.css')
css_content = File.read(tailwind_css_path)
css_content.gsub!(/\/\*.*?\*\//m, '')
css_content.gsub!(/\{[^}]*}/m, '{}')
css_content.gsub!(/\\\[/, '[')
css_content.gsub!( /\\\]/, ']')

class_regex = /\.\\?(!?[-_a-zA-Z0-9\[\]]+)(?=[^}]*\{)/
classes = css_content.scan(class_regex).flatten.uniq.sort

tailwind_config_path = Rails.root.join('config/tailwind.config.js')

if tailwind_config_path.exist?
content_config = <<~CONFIG.strip_heredoc
#{START_MARKER}
{ raw: '<div class="#{classes.join(' ')}"></div>', extension: 'html' },
#{END_MARKER} #{TurboMaterial::VERSION}
CONFIG

if File.read(tailwind_config_path.to_s).include?(START_MARKER)
gsub_file tailwind_config_path, /#{Regexp.escape(START_MARKER)}.*?#{Regexp.escape(END_MARKER)}.*?$/m do |match|
content_config.strip
end
else
insert_into_file tailwind_config_path, after: "content: [" do
"\n" + content_config.strip
end
end
end
end

def add_turbo_material_js_controllers
controllers_path = Rails.root.join('app/javascript/controllers/index.js')
if controllers_path.exist? && controllers_path.read.include?('eagerLoadControllersFrom("controllers", application)')
if controllers_path.read.include?('eagerLoadControllersFrom("turbo_material", application)')
puts "`app/javascript/controllers/index.js` already contains `eagerLoadControllersFrom(\"turbo_material\", application)`"
else
insert_into_file controllers_path, after: 'eagerLoadControllersFrom("controllers", application)' do
"\neagerLoadControllersFrom(\"turbo_material\", application)\n"
end
end
else
puts "`app/javascript/controllers/index.js` does not exist or does not contain `eagerLoadControllersFrom(\"controllers\", application)`"
end
end

def add_material_components_web_to_app_layout
layout_path = Rails.root.join('app/views/layouts/application.html.erb')
if layout_path.exist? && layout_path.read.include?('<%= csp_meta_tag %>')
if layout_path.read.include?('<link href="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">')
puts "`app/views/layouts/application.html.erb` head already contains material components web links"
else
insert_into_file layout_path, after: '<%= csp_meta_tag %>' do
HEAD_LINKS
end
end
else
raise "`app/views/layouts/application.html.erb` does not exist or does not contain `<%= csp_meta_tag %>`"
end
end
end
end
Empty file.
8 changes: 8 additions & 0 deletions lib/tasks/install.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

namespace :turbo_material do
desc 'Installs TurboMaterial'
task install: :environment do
Rails::Command.invoke :generate, ['turbo_material:install']
end
end
13 changes: 12 additions & 1 deletion lib/turbo_material.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
require "turbo_material/version"
require "turbo_material/engine"
require "turbo_material/configuration"

module TurboMaterial
# Your code goes here...
class << self
attr_accessor :configuration
end

def self.configuration
@configuration ||= Configuration.new
end

def self.configure
yield(configuration)
end
end
7 changes: 7 additions & 0 deletions lib/turbo_material/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module TurboMaterial
class Configuration

def initialize
end
end
end
2 changes: 1 addition & 1 deletion lib/turbo_material/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TurboMaterial
VERSION = "0.2.16"
VERSION = "0.2.17"
end
1 change: 0 additions & 1 deletion test/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<script src="//cdn.jsdelivr.net/npm/material-components-web@latest/dist/material-components-web.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<%= stylesheet_link_tag "turbo_material/tailwind.css" %>
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application" %>

Expand Down
37 changes: 20 additions & 17 deletions test/dummy/config/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
content: [
'./public/*.html',
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/views/**/*.{erb,haml,html,slim}'
],
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
content: [
// TurboMaterial::Engine raw CSS. This section is auto-generated by the turbo_material installer.
{ raw: '<div class="!flex-row !flex-wrap !grow !grow-0 !h-fit !h-full !h-max !hidden !max-h-0 !min-h-[14rem] !min-w-[36rem] !pt-8 !relative !text-white !top-6 !w-fit !w-full block capitalize fixed flex flex-col flex-row font-sans grid hidden items-center items-start justify-between max-h-64 max-w-prose mdc-notched-outline__leading mdc-notched-outline__notch mdc-notched-outline__trailing mx-auto overflow-y-auto p-2 pl-2 prose prose-2xl prose-amber prose-base prose-blue prose-cyan prose-emerald prose-fuchsia prose-gray prose-green prose-indigo prose-invert prose-lg prose-lime prose-neutral prose-orange prose-pink prose-purple prose-red prose-rose prose-sky prose-slate prose-sm prose-stone prose-teal prose-violet prose-xl prose-yellow prose-zinc px-6 py-3 rounded-none static table text-red-500 text-sm text-xs w-full"></div>', extension: 'html' },
// End of auto-generated TurboMaterial::Engine raw CSS. Version: 0.2.16
'./public/*.html',
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/views/**/*.{erb,haml,html,slim}'
],
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
},
},
},
plugins: [
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
]
plugins: [
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
]
}

0 comments on commit b674bba

Please sign in to comment.