sinatra-tailwind 0.1.0 β†’ 0.2.1

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: 8d4c186251862ccdf9139c2e1f2d72c01de6e22e9a068546eec9e2369a68440c
4
+ data.tar.gz: f9488d0ea31bc5db3c11076b2e5ef902fbf251fcadcb802213238664481a343c
5
5
  SHA512:
6
- metadata.gz: 66b945fec628f24efad692692c3618f82d8ee41a211c5a4c3358c6de753bbfb9be1a2cdeaa61d9c5e0703a3320ac4d5907480401d47a469735934dcd25f7a09e
7
- data.tar.gz: 615224da5d977707657a6932b2ac4e8fb0825606cf1fafe8f8b6e929e9fc787e77106bd3c9aee7cc62e6c37320ee454c8dadf6e4a11dff9a297fae36ff532519
6
+ metadata.gz: 10f12ce04545bc268b685068c804a2f3968dbfaf9d6ceab7749a9645fca81c8921e26af6905f6bf0f7c3e8edb5ab9294e7afc5df2c8071121a316c2c7f65fba0
7
+ data.tar.gz: e2022308dfde3ec4078e041561d277e295beee72d2d24a18e4a7f1adb58cad710d4dd6f9cc75b56fed6096f09a557c15b5287652d422497dcfadd1d9acb9262c
data/README.md CHANGED
@@ -1,43 +1,132 @@
1
- # Sinatra::Tailwind
1
+ <div align="center">
2
+ <h1>Sinatra::Tailwind</h1>
3
+ <p>Simple TailwindCSS integration for Sinatra applications.</p>
2
4
 
3
- TODO: Delete this and the text below, and describe your gem
5
+ <img src="logo.png" alt="Sinatra Tailwind" width="400">
6
+ </div>
4
7
 
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.
8
+ ## Overview
6
9
 
7
- ## Installation
10
+ Sinatra::Tailwind provides zero-configuration TailwindCSS setup for Sinatra applications. This gem offers:
8
11
 
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.
12
+ - πŸš€ Instant setup with smart defaults
13
+ - πŸ”„ Automatic CSS reloading
14
+ - πŸ›  Production-ready builds
15
+ - πŸ“¦ Zero configuration
16
+ - 🎨 Full TailwindCSS features
10
17
 
11
- Install the gem and add to the application's Gemfile by executing:
18
+ ## Installation
12
19
 
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
20
+ Add to your Gemfile:
21
+
22
+ ```ruby
23
+ gem 'sinatra-tailwind'
15
24
  ```
16
25
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
26
+ Then run:
18
27
 
19
28
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
29
+ bundle install
30
+ bundle exec tailwind install
21
31
  ```
22
32
 
23
33
  ## Usage
24
34
 
25
- TODO: Write usage instructions here
35
+ 1. Add the stylesheet to your layout:
36
+
37
+ ```erb
38
+ <!-- views/layout.erb -->
39
+ <link rel="stylesheet" href="/css/application.min.css">
40
+ ```
41
+
42
+ 2. Use TailwindCSS in your views:
43
+
44
+ ```erb
45
+ <div class="container mx-auto p-4">
46
+ <h1 class="text-3xl font-bold">Hello World</h1>
47
+ </div>
48
+ ```
26
49
 
27
50
  ## Development
28
51
 
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.
52
+ Start the development server:
30
53
 
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).
54
+ ```bash
55
+ ./bin/dev
56
+ ```
32
57
 
33
- ## Contributing
58
+ Or manually:
34
59
 
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).
60
+ ```bash
61
+ bundle exec tailwind watch # Watch CSS changes
62
+ bundle exec ruby app.rb # Run Sinatra server
63
+ ```
36
64
 
37
- ## License
65
+ ## Commands
66
+
67
+ ```bash
68
+ tailwind install # Install TailwindCSS
69
+ tailwind watch # Watch for changes
70
+ tailwind build # Build for production
71
+ tailwind setup # Configure development
72
+ ```
38
73
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+ ## Project Structure
40
75
 
41
- ## Code of Conduct
76
+ ```
77
+ my-app/
78
+ β”œβ”€β”€ app.rb
79
+ β”œβ”€β”€ Procfile.dev
80
+ β”œβ”€β”€ bin/
81
+ β”‚ └── dev
82
+ β”œβ”€β”€ views/
83
+ β”‚ └── layout.erb
84
+ └── public/
85
+ └── css/
86
+ β”œβ”€β”€ application.css
87
+ └── application.min.css
88
+ ```
89
+
90
+ ## Configuration
91
+
92
+ TailwindCSS configuration is available in `tailwind.config.js`:
93
+
94
+ ```js
95
+ module.exports = {
96
+ content: ['./views/**/*.{erb,haml,slim}', './public/**/*.{html,js}'],
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)
125
+
126
+ ## Contributing
127
+
128
+ Bug reports and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
129
+
130
+ ## License
42
131
 
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).
132
+ [MIT License](LICENSE)
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.1"
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.1
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-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -16,56 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: 4.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: 4.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.6'
33
+ version: '2.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.6'
40
+ version: '2.9'
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.3.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.3.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
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '2.0'
75
+ version: '2.6'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '2.0'
82
+ version: '2.6'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '13.0'
89
+ version: '13.2'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '13.0'
96
+ version: '13.2'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rspec
71
99
  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: []