Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions lib/generators/ruby_ui/component_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require_relative "javascript_utils"
module RubyUI
module Generators
class ComponentGenerator < Rails::Generators::Base
include RubyUI::Generators::JavascriptUtils
Comment on lines +1 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♥️


namespace "ruby_ui:component"

source_root File.expand_path("../../ruby_ui", __dir__)
Expand Down Expand Up @@ -92,29 +95,6 @@ def install_js_packages(js_packages)
end
end

def install_js_package(package)
if using_importmap?
pin_with_importmap(package)
elsif using_yarn?
run "yarn add #{package}"
elsif using_npm?
run "npm install #{package}"
else
say "Could not detect the package manager, you need to install '#{package}' manually", :red
end
end

def pin_with_importmap(package)
case package
when "motion"
pin_motion
when "tippy.js"
pin_tippy_js
else
run "bin/importmap pin #{package}"
end
end

def pin_motion
say <<~TEXT
WARNING: Installing motion from CDN because `bin/importmap pin motion` doesn't download the correct file.
Expand All @@ -141,14 +121,6 @@ def dependencies

@dependencies[component_folder_name]
end

def using_importmap?
File.exist?(Rails.root.join("config/importmap.rb")) && File.exist?(Rails.root.join("bin/importmap"))
end

def using_npm? = File.exist?(Rails.root.join("package-lock.json"))

def using_yarn? = File.exist?(Rails.root.join("yarn.lock"))
end
end
end
9 changes: 9 additions & 0 deletions lib/generators/ruby_ui/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require "rails/generators"
require_relative "../javascript_utils"

module RubyUI
module Generators
class InstallGenerator < Rails::Generators::Base
include RubyUI::Generators::JavascriptUtils

namespace "ruby_ui:install"

source_root File.expand_path("templates", __dir__)
Expand Down Expand Up @@ -66,6 +69,12 @@ def add_tailwind_config
end
end

def install_tailwind_animate
say "Installing tailwindcss-animate plugin"

install_js_package("tailwindcss-animate")
end

def add_ruby_ui_base
say "Adding RubyUI::Base component"
template "../../../../ruby_ui/base.rb", Rails.root.join("app/components/ruby_ui/base.rb")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ module.exports = {
},
},
},
plugins: [
require("tailwindcss-animate"),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ module.exports = {
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
require("../vendor/javascript/tailwindcss-animate")
]
}
36 changes: 36 additions & 0 deletions lib/generators/ruby_ui/javascript_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module RubyUI
module Generators
module JavascriptUtils
def install_js_package(package)
if using_importmap?
pin_with_importmap(package)
elsif using_yarn?
run "yarn add #{package}"
elsif using_npm?
run "npm install #{package}"
else
say "Could not detect the package manager, you need to install '#{package}' manually", :red
end
end

def pin_with_importmap(package)
case package
when "motion"
pin_motion
when "tippy.js"
pin_tippy_js
else
run "bin/importmap pin #{package}"
end
end

def using_importmap?
File.exist?(Rails.root.join("config/importmap.rb")) && File.exist?(Rails.root.join("bin/importmap"))
end

def using_npm? = File.exist?(Rails.root.join("package-lock.json"))

def using_yarn? = File.exist?(Rails.root.join("yarn.lock"))
end
end
end