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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2adf0d518dcafc6441d65f9c586c2a17a839ce442ca88b5088551788fd8d5c67
4
- data.tar.gz: 741f619b7ddee2dbc3e47844af9658d26447c18ff1bae3040afa7ab278c3b0aa
3
+ metadata.gz: c92a01438e966f40aa88e8c1131137f1c29f1b4e7b3bf1f2bd251c642138544c
4
+ data.tar.gz: 764a3fb4462ff4b8b5ab4479614cdea4aa3776ae085876fafab437221a9c5516
5
5
  SHA512:
6
- metadata.gz: 66b945fec628f24efad692692c3618f82d8ee41a211c5a4c3358c6de753bbfb9be1a2cdeaa61d9c5e0703a3320ac4d5907480401d47a469735934dcd25f7a09e
7
- data.tar.gz: 615224da5d977707657a6932b2ac4e8fb0825606cf1fafe8f8b6e929e9fc787e77106bd3c9aee7cc62e6c37320ee454c8dadf6e4a11dff9a297fae36ff532519
6
+ metadata.gz: b85386eda60128a27bcd65a0fa5734c3a2cff37de854f3ad599c9328a40fcb2c12599e98fe3ca299eb151034e53ec0a8a6d384a86c35dde6d799474d0eb1e43f
7
+ data.tar.gz: e647693b10642fdfbf2dcaddb8bb4a131dc97948c455e1252ce8ba78326ab43d28a331e13819d16abfa41975cdb37711c9a931f36c511de2ed99c2e0ae48aa96
data/README.md CHANGED
@@ -1,43 +1,133 @@
1
1
  # Sinatra::Tailwind
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Simple TailwindCSS integration for Sinatra applications.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sinatra/tailwind`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Overview
6
6
 
7
- ## Installation
7
+ Sinatra::Tailwind provides zero-configuration TailwindCSS setup for Sinatra applications. This gem offers:
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ - πŸš€ Instant setup with smart defaults
10
+ - πŸ”„ Automatic CSS reloading
11
+ - πŸ›  Production-ready builds
12
+ - πŸ“¦ Zero configuration
13
+ - 🎨 Full TailwindCSS features
10
14
 
11
- Install the gem and add to the application's Gemfile by executing:
15
+ ## Installation
12
16
 
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ Add to your Gemfile:
18
+
19
+ ```ruby
20
+ gem 'sinatra-tailwind'
15
21
  ```
16
22
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
23
+ Then run:
18
24
 
19
25
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
26
+ bundle install
27
+ bundle exec tailwind install
21
28
  ```
22
29
 
23
30
  ## Usage
24
31
 
25
- TODO: Write usage instructions here
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+ Start the development server:
30
50
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 on GitHub at https://github.com/[USERNAME]/sinatra-tailwind. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sinatra-tailwind/blob/master/CODE_OF_CONDUCT.md).
128
+ Bug reports and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
36
129
 
37
130
  ## License
38
131
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sinatra/tailwind/cli"
5
+
6
+ Sinatra::Tailwind::CLI.start(ARGV)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Tailwind
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,7 +1,20 @@
1
- require_relative "tailwind/version"
2
- require "sinatra/tailwind"
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.1.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-29 00:00:00.000000000 Z
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: Automated TailwindCSS integration for Sinatra applications
167
+ summary: Zero-config TailwindCSS for Sinatra applications
136
168
  test_files: []