sinatra-tailwind 0.1.0 β 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +107 -17
- data/exe/tailwind +6 -0
- data/lib/sinatra/tailwind/cli.rb +113 -0
- data/lib/sinatra/tailwind/setup.rb +164 -0
- data/lib/sinatra/tailwind/version.rb +1 -1
- data/lib/sinatra/tailwind.rb +15 -2
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c92a01438e966f40aa88e8c1131137f1c29f1b4e7b3bf1f2bd251c642138544c
|
4
|
+
data.tar.gz: 764a3fb4462ff4b8b5ab4479614cdea4aa3776ae085876fafab437221a9c5516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b85386eda60128a27bcd65a0fa5734c3a2cff37de854f3ad599c9328a40fcb2c12599e98fe3ca299eb151034e53ec0a8a6d384a86c35dde6d799474d0eb1e43f
|
7
|
+
data.tar.gz: e647693b10642fdfbf2dcaddb8bb4a131dc97948c455e1252ce8ba78326ab43d28a331e13819d16abfa41975cdb37711c9a931f36c511de2ed99c2e0ae48aa96
|
data/README.md
CHANGED
@@ -1,43 +1,133 @@
|
|
1
1
|
# Sinatra::Tailwind
|
2
2
|
|
3
|
-
|
3
|
+
Simple TailwindCSS integration for Sinatra applications.
|
4
4
|
|
5
|
-
|
5
|
+
## Overview
|
6
6
|
|
7
|
-
|
7
|
+
Sinatra::Tailwind provides zero-configuration TailwindCSS setup for Sinatra applications. This gem offers:
|
8
8
|
|
9
|
-
|
9
|
+
- π Instant setup with smart defaults
|
10
|
+
- π Automatic CSS reloading
|
11
|
+
- π Production-ready builds
|
12
|
+
- π¦ Zero configuration
|
13
|
+
- π¨ Full TailwindCSS features
|
10
14
|
|
11
|
-
|
15
|
+
## Installation
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
Add to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'sinatra-tailwind'
|
15
21
|
```
|
16
22
|
|
17
|
-
|
23
|
+
Then run:
|
18
24
|
|
19
25
|
```bash
|
20
|
-
|
26
|
+
bundle install
|
27
|
+
bundle exec tailwind install
|
21
28
|
```
|
22
29
|
|
23
30
|
## Usage
|
24
31
|
|
25
|
-
|
32
|
+
1. Add the stylesheet to your layout:
|
33
|
+
|
34
|
+
```erb
|
35
|
+
<!-- views/layout.erb -->
|
36
|
+
<link rel="stylesheet" href="/css/application.min.css">
|
37
|
+
```
|
38
|
+
|
39
|
+
2. Use TailwindCSS in your views:
|
40
|
+
|
41
|
+
```erb
|
42
|
+
<div class="container mx-auto p-4">
|
43
|
+
<h1 class="text-3xl font-bold">Hello World</h1>
|
44
|
+
</div>
|
45
|
+
```
|
26
46
|
|
27
47
|
## Development
|
28
48
|
|
29
|
-
|
49
|
+
Start the development server:
|
30
50
|
|
31
|
-
|
51
|
+
```bash
|
52
|
+
./bin/dev
|
53
|
+
```
|
54
|
+
|
55
|
+
Or manually:
|
56
|
+
|
57
|
+
```bash
|
58
|
+
bundle exec tailwind watch # Watch CSS changes
|
59
|
+
bundle exec ruby app.rb # Run Sinatra server
|
60
|
+
```
|
61
|
+
|
62
|
+
## Commands
|
63
|
+
|
64
|
+
```bash
|
65
|
+
tailwind install # Install TailwindCSS
|
66
|
+
tailwind watch # Watch for changes
|
67
|
+
tailwind build # Build for production
|
68
|
+
tailwind setup # Configure development
|
69
|
+
```
|
70
|
+
|
71
|
+
## Project Structure
|
72
|
+
|
73
|
+
```
|
74
|
+
my-app/
|
75
|
+
βββ app.rb
|
76
|
+
βββ Procfile.dev
|
77
|
+
βββ bin/
|
78
|
+
β βββ dev
|
79
|
+
βββ views/
|
80
|
+
β βββ layout.erb
|
81
|
+
βββ public/
|
82
|
+
βββ css/
|
83
|
+
βββ application.css
|
84
|
+
βββ application.min.css
|
85
|
+
```
|
86
|
+
|
87
|
+
## Configuration
|
88
|
+
|
89
|
+
TailwindCSS configuration is available in `tailwind.config.js`:
|
90
|
+
|
91
|
+
```js
|
92
|
+
module.exports = {
|
93
|
+
content: [
|
94
|
+
'./views/**/*.{erb,haml,slim}',
|
95
|
+
'./public/**/*.{html,js}'
|
96
|
+
],
|
97
|
+
theme: {
|
98
|
+
extend: {},
|
99
|
+
},
|
100
|
+
plugins: [],
|
101
|
+
}
|
102
|
+
```
|
103
|
+
|
104
|
+
## Example Application
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
# app.rb
|
108
|
+
require 'sinatra'
|
109
|
+
require 'sinatra/tailwind'
|
110
|
+
|
111
|
+
class MyApp < Sinatra::Base
|
112
|
+
register Sinatra::Tailwind
|
113
|
+
|
114
|
+
get '/' do
|
115
|
+
erb :index
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
## Support
|
121
|
+
|
122
|
+
- π [Documentation](https://github.com/aristotelesbr/sinatra-tailwind/wiki)
|
123
|
+
- π [Issue Tracker](https://github.com/aristotelesbr/sinatra-tailwind/issues)
|
124
|
+
- π¬ [Discussions](https://github.com/aristotelesbr/sinatra-tailwind/discussions)
|
32
125
|
|
33
126
|
## Contributing
|
34
127
|
|
35
|
-
Bug reports and pull requests are welcome
|
128
|
+
Bug reports and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
36
129
|
|
37
130
|
## License
|
38
131
|
|
39
|
-
|
40
|
-
|
41
|
-
## Code of Conduct
|
132
|
+
[MIT License](LICENSE)
|
42
133
|
|
43
|
-
Everyone interacting in the Sinatra::Tailwind project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sinatra-tailwind/blob/master/CODE_OF_CONDUCT.md).
|
data/exe/tailwind
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "sinatra/tailwind/setup"
|
3
|
+
require "tty-prompt"
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
module Tailwind
|
7
|
+
class CLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
include Sinatra::Tailwind::Setup
|
10
|
+
|
11
|
+
map %w[--version -v] => :version
|
12
|
+
|
13
|
+
desc "version", "Show sinatra-tailwind version"
|
14
|
+
def version
|
15
|
+
require "sinatra/tailwind/version"
|
16
|
+
say "sinatra-tailwind version #{Sinatra::Tailwind::VERSION}"
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "install", "Install TailwindCSS in your Sinatra application"
|
20
|
+
def install
|
21
|
+
say "\nπ¨ Installing TailwindCSS for your Sinatra application...", :blue
|
22
|
+
|
23
|
+
check_npm_installation
|
24
|
+
install_tailwind_dependencies
|
25
|
+
create_tailwind_config
|
26
|
+
create_css_file
|
27
|
+
setup_build_process
|
28
|
+
|
29
|
+
if ask_setup_procfile?
|
30
|
+
invoke :setup
|
31
|
+
end
|
32
|
+
|
33
|
+
say "\n⨠TailwindCSS installation completed successfully!", :green
|
34
|
+
say "\nπ You can now run:", :blue
|
35
|
+
say " bundle exec tailwind build - To build your CSS", :cyan
|
36
|
+
say " bundle exec tailwind watch - To watch for CSS changes", :cyan
|
37
|
+
say " bundle exec tailwind setup - To setup Procfile.dev", :cyan if !File.exist?("Procfile.dev")
|
38
|
+
rescue Error => e
|
39
|
+
say "\nβ Error: #{e.message}", :red
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "build", "Build TailwindCSS files"
|
44
|
+
def build
|
45
|
+
if system("which npm > /dev/null 2>&1")
|
46
|
+
say "\nπ¨ Building CSS files...", :blue
|
47
|
+
if system("npm run build:css")
|
48
|
+
say "β¨ CSS build completed successfully!", :green
|
49
|
+
else
|
50
|
+
say "\nβ Error: Failed to build CSS", :red
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
else
|
54
|
+
say "\nβ Error: NPM is not installed", :red
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "watch", "Watch for CSS changes and rebuild"
|
60
|
+
def watch
|
61
|
+
if system("which npm > /dev/null 2>&1")
|
62
|
+
say "\nπ Watching for changes...", :blue
|
63
|
+
exec("npx tailwindcss -i ./public/css/application.css -o ./public/css/application.min.css --watch")
|
64
|
+
else
|
65
|
+
say "\nβ Error: NPM is not installed", :red
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "setup", "Setup Procfile.dev for development"
|
71
|
+
def setup
|
72
|
+
if File.exist?("Procfile.dev")
|
73
|
+
if yes?("\nβ οΈ Procfile.dev already exists. Do you want to override it?", :yellow)
|
74
|
+
create_procfile
|
75
|
+
create_dev_script
|
76
|
+
end
|
77
|
+
else
|
78
|
+
create_procfile
|
79
|
+
create_dev_script
|
80
|
+
end
|
81
|
+
|
82
|
+
say "\n⨠Development environment setup completed!", :green
|
83
|
+
say "\nπ To start your development server, run:", :blue
|
84
|
+
say " ./bin/dev", :cyan
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def ask_setup_procfile?
|
90
|
+
prompt = TTY::Prompt.new(enable_color: true)
|
91
|
+
prompt.yes?("\nπ€ Would you like to setup a Procfile.dev for development? (y/n)", default: true)
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_procfile
|
95
|
+
say "\nπ Creating Procfile.dev...", :blue
|
96
|
+
|
97
|
+
content = <<~PROCFILE
|
98
|
+
web: bundle exec rackup -p ${PORT:-9292}
|
99
|
+
css: bundle exec tailwind watch
|
100
|
+
PROCFILE
|
101
|
+
|
102
|
+
create_file "Procfile.dev", content
|
103
|
+
|
104
|
+
if !system("which foreman > /dev/null 2>&1")
|
105
|
+
say "\nβ οΈ Note: You need to install foreman to use Procfile.dev", :yellow
|
106
|
+
say " Run: gem install foreman", :cyan
|
107
|
+
end
|
108
|
+
|
109
|
+
say "β¨ Procfile.dev created successfully!", :green
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "json"
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
module Tailwind
|
7
|
+
module Setup
|
8
|
+
def check_npm_installation
|
9
|
+
unless system("which npm > /dev/null 2>&1")
|
10
|
+
raise Error, "NPM is not installed. Please install Node.js and NPM first."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def install_tailwind_dependencies
|
15
|
+
if !File.exist?("package.json")
|
16
|
+
log_info "π¦ Initializing new Node.js project..."
|
17
|
+
|
18
|
+
package_json = {
|
19
|
+
"name" => "tailwind-app",
|
20
|
+
"version" => "1.0.0",
|
21
|
+
"private" => true,
|
22
|
+
"dependencies" => {},
|
23
|
+
"devDependencies" => {}
|
24
|
+
}
|
25
|
+
|
26
|
+
File.write("package.json", JSON.pretty_generate(package_json))
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
package_json = JSON.parse(File.read("package.json"))
|
31
|
+
|
32
|
+
if !package_json.dig("dependencies", "tailwindcss")
|
33
|
+
log_info "π¦ Installing TailwindCSS..."
|
34
|
+
if !system("npm install tailwindcss@latest --save --legacy-peer-deps")
|
35
|
+
raise Error, "Failed to install TailwindCSS"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
dev_dependencies = package_json["devDependencies"] || {}
|
40
|
+
needed_dev_deps = ["postcss", "autoprefixer"] - dev_dependencies.keys
|
41
|
+
|
42
|
+
if !needed_dev_deps.empty?
|
43
|
+
log_info "π¦ Installing development dependencies..."
|
44
|
+
if !system("npm install #{needed_dev_deps.join(" ")} --save-dev --legacy-peer-deps")
|
45
|
+
raise Error, "Failed to install development dependencies"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
package_json = JSON.parse(File.read("package.json"))
|
50
|
+
|
51
|
+
clean_deps = {"tailwindcss" => package_json.dig("dependencies", "tailwindcss")}
|
52
|
+
package_json["dependencies"] = clean_deps
|
53
|
+
|
54
|
+
dev_deps = package_json["devDependencies"] || {}
|
55
|
+
clean_dev_deps = {
|
56
|
+
"postcss" => dev_deps["postcss"],
|
57
|
+
"autoprefixer" => dev_deps["autoprefixer"]
|
58
|
+
}.compact
|
59
|
+
package_json["devDependencies"] = clean_dev_deps
|
60
|
+
|
61
|
+
File.write("package.json", JSON.pretty_generate(package_json))
|
62
|
+
|
63
|
+
if !system("npm install --legacy-peer-deps")
|
64
|
+
raise Error, "Failed to reinstall dependencies"
|
65
|
+
end
|
66
|
+
rescue JSON::ParserError => e
|
67
|
+
raise Error, "Failed to parse package.json: #{e.message}"
|
68
|
+
rescue => e
|
69
|
+
raise Error, "An error occurred during dependency installation: #{e.message}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_tailwind_config
|
74
|
+
return if File.exist?("tailwind.config.js")
|
75
|
+
|
76
|
+
log_info "π§ Creating Tailwind configuration..."
|
77
|
+
config_content = <<~JS
|
78
|
+
module.exports = {
|
79
|
+
content: [
|
80
|
+
'./views/**/*.{erb,haml,slim}',
|
81
|
+
'./public/**/*.{html,js}'
|
82
|
+
],
|
83
|
+
theme: {
|
84
|
+
extend: {},
|
85
|
+
},
|
86
|
+
plugins: [],
|
87
|
+
}
|
88
|
+
JS
|
89
|
+
|
90
|
+
File.write("tailwind.config.js", config_content)
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_css_file
|
94
|
+
css_dir = "public/css"
|
95
|
+
css_file = "#{css_dir}/application.css"
|
96
|
+
return if File.exist?(css_file)
|
97
|
+
|
98
|
+
log_info "π¨ Creating CSS file..."
|
99
|
+
FileUtils.mkdir_p(css_dir)
|
100
|
+
css_content = <<~CSS
|
101
|
+
@tailwind base;
|
102
|
+
@tailwind components;
|
103
|
+
@tailwind utilities;
|
104
|
+
CSS
|
105
|
+
|
106
|
+
File.write(css_file, css_content)
|
107
|
+
end
|
108
|
+
|
109
|
+
def setup_build_process
|
110
|
+
package_json = File.exist?("package.json") ? JSON.parse(File.read("package.json")) : {}
|
111
|
+
package_json["scripts"] ||= {}
|
112
|
+
package_json["scripts"]["build:css"] = "tailwindcss -i ./public/css/application.css -o ./public/css/application.min.css --minify"
|
113
|
+
|
114
|
+
File.write("package.json", JSON.pretty_generate(package_json))
|
115
|
+
log_info "βοΈ Added build script to package.json"
|
116
|
+
end
|
117
|
+
|
118
|
+
def create_dev_script
|
119
|
+
bin_dir = "bin"
|
120
|
+
dev_script = "#{bin_dir}/dev"
|
121
|
+
|
122
|
+
FileUtils.mkdir_p(bin_dir)
|
123
|
+
|
124
|
+
content = <<~BASH
|
125
|
+
#!/usr/bin/env bash
|
126
|
+
|
127
|
+
if ! command -v foreman &> /dev/null; then
|
128
|
+
echo "Installing foreman..."
|
129
|
+
gem install foreman
|
130
|
+
fi
|
131
|
+
|
132
|
+
if ! command -v npm &> /dev/null; then
|
133
|
+
echo "Error: NPM is required but not installed."
|
134
|
+
echo "Please install Node.js and NPM first."
|
135
|
+
exit 1
|
136
|
+
fi
|
137
|
+
|
138
|
+
if [ ! -f "Procfile.dev" ]; then
|
139
|
+
echo "Error: Procfile.dev not found."
|
140
|
+
echo "Please run 'bundle exec tailwind setup' first."
|
141
|
+
exit 1
|
142
|
+
fi
|
143
|
+
|
144
|
+
foreman start -f Procfile.dev "$@"
|
145
|
+
BASH
|
146
|
+
|
147
|
+
File.write(dev_script, content)
|
148
|
+
FileUtils.chmod(0o755, dev_script)
|
149
|
+
|
150
|
+
log_info "π Created bin/dev script"
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
def log_info(message)
|
156
|
+
logger.info(message)
|
157
|
+
end
|
158
|
+
|
159
|
+
def logger
|
160
|
+
@logger ||= Logger.new($stdout)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
data/lib/sinatra/tailwind.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
|
-
|
2
|
-
require "
|
1
|
+
require "sinatra/base"
|
2
|
+
require "json"
|
3
|
+
require "fileutils"
|
4
|
+
require "sinatra/tailwind/version"
|
5
|
+
require "sinatra/tailwind/setup"
|
6
|
+
require "sinatra/tailwind/cli"
|
3
7
|
|
4
8
|
module Sinatra
|
5
9
|
module Tailwind
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def registered(app)
|
14
|
+
app.helpers Sinatra::Tailwind::Setup
|
15
|
+
end
|
16
|
+
end
|
6
17
|
end
|
18
|
+
|
19
|
+
register Tailwind
|
7
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-tailwind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AristΓ³teles
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-prompt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.23.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.23.1
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,7 +124,8 @@ dependencies:
|
|
96
124
|
version: '1.3'
|
97
125
|
description: Integrate TailwindCSS in a Sinatra project
|
98
126
|
email:
|
99
|
-
executables:
|
127
|
+
executables:
|
128
|
+
- tailwind
|
100
129
|
extensions: []
|
101
130
|
extra_rdoc_files: []
|
102
131
|
files:
|
@@ -104,7 +133,10 @@ files:
|
|
104
133
|
- README.md
|
105
134
|
- bin/console
|
106
135
|
- bin/setup
|
136
|
+
- exe/tailwind
|
107
137
|
- lib/sinatra/tailwind.rb
|
138
|
+
- lib/sinatra/tailwind/cli.rb
|
139
|
+
- lib/sinatra/tailwind/setup.rb
|
108
140
|
- lib/sinatra/tailwind/version.rb
|
109
141
|
homepage: https://github.com/aristotelesbr/sinatra-tailwind
|
110
142
|
licenses:
|
@@ -132,5 +164,5 @@ requirements: []
|
|
132
164
|
rubygems_version: 3.5.23
|
133
165
|
signing_key:
|
134
166
|
specification_version: 4
|
135
|
-
summary:
|
167
|
+
summary: Zero-config TailwindCSS for Sinatra applications
|
136
168
|
test_files: []
|