From 512ec2e99fcb7d8b722c8f22fe34beaaa387f668 Mon Sep 17 00:00:00 2001 From: Seth Horsley Date: Tue, 27 Aug 2024 01:02:12 -0400 Subject: [PATCH 1/3] install generator working --- .gitignore | 1 + lib/generators/rbui/base_generator.rb | 15 ++ .../rbui/install/install_generator.rb | 128 ++++++++++++++++++ lib/generators/rbui/install/templates/.keep | 0 .../templates/application.tailwind.css.tt | 60 ++++++++ .../rbui/install/templates/index_view.rb.tt | 29 ++++ .../install/templates/tailwind.config.js.tt | 77 +++++++++++ .../templates/base_store_initializer.rb.tt | 9 ++ lib/phlex_ui.rb | 13 ++ lib/rbui/railtie.rb | 25 ++++ phlex_ui.gemspec | 1 + test/test_helper.rb | 6 + 12 files changed, 364 insertions(+) create mode 100644 lib/generators/rbui/base_generator.rb create mode 100644 lib/generators/rbui/install/install_generator.rb create mode 100644 lib/generators/rbui/install/templates/.keep create mode 100644 lib/generators/rbui/install/templates/application.tailwind.css.tt create mode 100644 lib/generators/rbui/install/templates/index_view.rb.tt create mode 100644 lib/generators/rbui/install/templates/tailwind.config.js.tt create mode 100644 lib/generators/rbui/templates/base_store_initializer.rb.tt create mode 100644 lib/rbui/railtie.rb diff --git a/.gitignore b/.gitignore index 9daa824..7948b66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store node_modules +/app/assets/builds/* diff --git a/lib/generators/rbui/base_generator.rb b/lib/generators/rbui/base_generator.rb new file mode 100644 index 0000000..1d2a63b --- /dev/null +++ b/lib/generators/rbui/base_generator.rb @@ -0,0 +1,15 @@ +require "rails/generators" + +module RBUI + module Generators + class BaseGenerator < defined?(Rails::Generators::Base) ? Rails::Generators::Base : Object + namespace "rbui:base" + + source_root File.join(__dir__, "templates") + + def copy_templates + template "base_store_initializer.rb", "config/initializers/rbui.rb" + end + end + end +end diff --git a/lib/generators/rbui/install/install_generator.rb b/lib/generators/rbui/install/install_generator.rb new file mode 100644 index 0000000..c5db2a0 --- /dev/null +++ b/lib/generators/rbui/install/install_generator.rb @@ -0,0 +1,128 @@ +module RBUI + module Generators + class InstallGenerator < defined?(Rails::Generators::Base) ? Rails::Generators::Base : Object + namespace "rbui:install" + + if defined?(Rails::Generators::Base) + source_root File.expand_path("templates", __dir__) + + def add_phlex_rails + say "Checking for Phlex Rails" + if gem_installed?("phlex-rails") + say "Phlex Rails is already installed", :green + else + say "Adding Phlex Rails" + run "bundle add phlex-rails" + end + + if yes?("Do you want to run the Phlex installer? (y/n)") + say "Run Phlex install" + run "bin/rails generate phlex:install" + end + end + + def install_stuff + if yes?("Do you want to set up the dev test data? (y/n)") + say "Add index controller" + run "bin/rails generate controller static index --no-helper --no-assets --no-test-framework --no-jbuilder" + + say "Add index view" + run "bin/rails g phlex:view Static::Index" + + append_to_file "app/controllers/static_controller.rb", after: " def index" do + "\n render Static::IndexView" + end + + template "index_view.rb", "app/views/static/index_view.rb", force: true + + say "Add index route" + append_to_file "config/routes.rb", after: "Rails.application.routes.draw do" do + "\n root to: \"static#index\"\n" + end + end + + say "Checking for Tailwind CSS" + if gem_installed?("tailwindcss-rails") + say "Tailwind CSS is already installed", :green + + if yes?("Do you want to run the Tailwind installer? (y/n)") + say "Run Tailwind install" + run "./bin/rails tailwindcss:install" + end + elsif yes?("Do you want us to install Tailwind CSS? (y/n)") + say "Adding Tailwind CSS" + run "./bin/bundle add tailwindcss-rails" + + say "Run Tailwind install" + run "./bin/rails tailwindcss:install" + end + + say "Add tailwind animate" + run "yarn add tailwindcss-animate" + + say "update tailwind.config.js" + template "tailwind.config.js", "config/tailwind.config.js", force: true + + say "Add CSS variables" + template "application.tailwind.css", "app/assets/stylesheets/application.tailwind.css", force: true + end + + def pin_rbui_js + importmap_binstub = Rails.root.join("bin/importmap") + importmap_config_path = Rails.root.join("config/importmap.rb") + stimulus_path = Rails.root.join("app/javascript/application.js") + + if importmap_binstub.exist? + say "Pin rbui-js" + append_to_file importmap_config_path do + %(pin "rbui-js", to: "rbui-js.js"\n) + end + else + say "Add rbui-js package" + # run "yarn add rbui-js" + run "yarn add ../phlex_ui" + run "yarn add phlex_ui" + end + + if stimulus_path.exist? + say "Add RBUI Stimulus controllers" + append_to_file stimulus_path do + "\nimport \"rbui-js\";\nimport \"phlex_ui\";\n" + end + run "yarn build" + else + say "Default Stimulus location is missing: app/javascript/controllers/index.js", :red + say " Add to your Stimulus index.js:" + say " import \"rbui-js\"" + end + end + + def include_rbui + say "Add RBUI to your global component layout" + insert_into_file "app/views/application_view.rb", after: "class ApplicationView < ApplicationComponent\n" do + " include RBUI\n include PhlexUI\n" + end + end + + else + def self.source_root + File.expand_path("templates", __dir__) + end + + def add_stylesheet_link + puts "This generator can only be run in a Rails environment." + end + + def revoke + puts "This generator can only be run in a Rails environment." + end + end + + private + + def gem_installed?(name) + Gem::Specification.find_all_by_name(name).any? + end + end + end +end diff --git a/lib/generators/rbui/install/templates/.keep b/lib/generators/rbui/install/templates/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/generators/rbui/install/templates/application.tailwind.css.tt b/lib/generators/rbui/install/templates/application.tailwind.css.tt new file mode 100644 index 0000000..f9bcc35 --- /dev/null +++ b/lib/generators/rbui/install/templates/application.tailwind.css.tt @@ -0,0 +1,60 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer base { + :root { + --background: 0 0% 100%; + --foreground: 0 0% 3.9%; + --primary: 0 0% 9%; + --primary-foreground: 0 0% 98%; + --secondary: 0 0% 96.1%; + --secondary-foreground: 0 0% 9%; + --muted: 0 0% 96.1%; + --muted-foreground: 0 0% 45.1%; + --accent: 0 0% 96.1%; + --accent-foreground: 0 0% 9%; + --destructive: 350 89% 60%; + --destructive-foreground: 0 0% 100%; + --warning: 38 92% 50%; + --warning-foreground: 0 0% 100%; + --success: 87 100% 37%; + --success-foreground: 0 0% 100%; + --border: 0 0% 89.8%; + --input: 0 0% 89.8%; + --ring: 0 0% 3.9%; + --radius: 0.5rem; + } + + .dark { + --background: 0 0% 3.9%; + --foreground: 0 0% 98%; + --primary: 0 0% 98%; + --primary-foreground: 0 0% 9%; + --secondary: 0 0% 14.9%; + --secondary-foreground: 0 0% 98%; + --muted: 0 0% 14.9%; + --muted-foreground: 0 0% 63.9%; + --accent: 0 0% 14.9%; + --accent-foreground: 0 0% 98%; + --destructive: 350 89% 60%; + --destructive-foreground: 0 0% 100%; + --warning: 38 92% 50%; + --warning-foreground: 0 0% 100%; + --success: 84 81% 44%; + --success-foreground: 0 0% 100%; + --border: 0 0% 14.9%; + --input: 0 0% 14.9%; + --ring: 0 0% 83.1%; + } +} + +@layer base { + * { + @apply border-border; + } + body { + @apply bg-background text-foreground; + font-feature-settings: "rlig" 1, "calt" 1; + } +} diff --git a/lib/generators/rbui/install/templates/index_view.rb.tt b/lib/generators/rbui/install/templates/index_view.rb.tt new file mode 100644 index 0000000..a5a8cd7 --- /dev/null +++ b/lib/generators/rbui/install/templates/index_view.rb.tt @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class Static::IndexView < ApplicationView + def template + render PhlexUI::Button.new { "click me" } + br {} + + # UI.Button { "click me" } + + AlertDialog do + AlertDialogTrigger do + Button { "Show dialog" } + end + AlertDialogContent do + AlertDialogHeader do + AlertDialogTitle { "Are you absolutely sure?" } + AlertDialogDescription { "This action cannot be undone. This will permanently delete your account and remove your data from our servers." } + end + AlertDialogFooter do + AlertDialogCancel { "Cancel" } + AlertDialogAction { "Continue" } # Will probably be a link to a controller action (e.g. delete account) + end + end + end + h1 { "Static::Index" } + p { "Find me in app/views/static/index_view.rb" } + end +end + diff --git a/lib/generators/rbui/install/templates/tailwind.config.js.tt b/lib/generators/rbui/install/templates/tailwind.config.js.tt new file mode 100644 index 0000000..43549ae --- /dev/null +++ b/lib/generators/rbui/install/templates/tailwind.config.js.tt @@ -0,0 +1,77 @@ +// For importing tailwind styles from phlex_ui/phlex_ui_pro gem +const execSync = require('child_process').execSync; + +// Import phlex_ui gem path (To make sure Tailwind loads classes used by phlex_ui gem) +const outputPhlexUI = execSync('bundle show phlex_ui', { encoding: 'utf-8' }); +const phlex_ui_path = outputPhlexUI.trim() + '/**/*.rb'; + +const defaultTheme = require('tailwindcss/defaultTheme') + +module.exports = { + darkMode: ["class"], + content: [ + './app/views/**/*.{erb,haml,html,slim,rb}', + './app/helpers/**/*.rb', + './app/assets/stylesheets/**/*.css', + './app/javascript/**/*.js', + phlex_ui_path + ], + theme: { + container: { + center: true, + padding: "2rem", + screens: { + "2xl": "1400px", + }, + }, + extend: { + colors: { + border: "hsl(var(--border))", + input: "hsl(var(--input))", + ring: "hsl(var(--ring))", + background: "hsl(var(--background))", + foreground: "hsl(var(--foreground))", + primary: { + DEFAULT: "hsl(var(--primary))", + foreground: "hsl(var(--primary-foreground))", + }, + secondary: { + DEFAULT: "hsl(var(--secondary))", + foreground: "hsl(var(--secondary-foreground))", + }, + destructive: { + DEFAULT: "hsl(var(--destructive))", + foreground: "hsl(var(--destructive-foreground))", + }, + warning: { + DEFAULT: "hsl(var(--warning))", + foreground: "hsl(var(--warning-foreground))", + }, + success: { + DEFAULT: "hsl(var(--success))", + foreground: "hsl(var(--success-foreground))", + }, + muted: { + DEFAULT: "hsl(var(--muted))", + foreground: "hsl(var(--muted-foreground))", + }, + accent: { + DEFAULT: "hsl(var(--accent))", + foreground: "hsl(var(--accent-foreground))", + }, + }, + borderRadius: { + lg: `var(--radius)`, + md: `calc(var(--radius) - 2px)`, + sm: "calc(var(--radius) - 4px)", + }, + fontFamily: { + sans: defaultTheme.fontFamily.sans, + }, + }, + }, + plugins: [ + require("tailwindcss-animate"), + ], +} + diff --git a/lib/generators/rbui/templates/base_store_initializer.rb.tt b/lib/generators/rbui/templates/base_store_initializer.rb.tt new file mode 100644 index 0000000..e88f39a --- /dev/null +++ b/lib/generators/rbui/templates/base_store_initializer.rb.tt @@ -0,0 +1,9 @@ +PhlexUI.setup do |config| + # Setting a namespace allows you to access PhlexUI components through this namespace. + # For example, with namespace set to "UI", you can use: + # UI::Button.new instead of PhlexUI::Button.new + # UI::Card.new instead of PhlexUI::Card.new + # This can help avoid naming conflicts and allows for cleaner, more concise code. + # If you prefer to use PhlexUI components directly, you can leave this unset. + config.namespace = "UI" +end diff --git a/lib/phlex_ui.rb b/lib/phlex_ui.rb index 4719c3e..0fa3fb9 100644 --- a/lib/phlex_ui.rb +++ b/lib/phlex_ui.rb @@ -1,6 +1,14 @@ require "json" require "phlex" +if defined?(ActiveSupport::Inflector) + require "active_support/inflector" + ActiveSupport::Inflector.inflections(:en) do |inflect| + inflect.acronym "PhlexUI" + inflect.acronym "UI" + end +end + module RBUI extend Phlex::Kit end @@ -46,3 +54,8 @@ def self.create_namespace_module # Manually require all the files Dir.glob(File.join(__dir__, "phlex_ui", "**", "*.rb")).sort.each { |file| require file } Dir.glob(File.join(__dir__, "rbui", "**", "*.rb")).sort.each { |file| require file } + +# If you need to require generators (assuming they're needed) +if defined?(Rails::Generators) + require_relative "generators/rbui/install/install_generator" +end diff --git a/lib/rbui/railtie.rb b/lib/rbui/railtie.rb new file mode 100644 index 0000000..8f5d9fe --- /dev/null +++ b/lib/rbui/railtie.rb @@ -0,0 +1,25 @@ +module RBUI + if defined?(Rails) + class Railtie < ::Rails::Railtie + generators do + require_relative "../generators/rbui/install/install_generator" + + config.app_generators do |g| + g.templates.unshift File.expand_path("../templates", __FILE__) + end + + initializer "rbui.set_generator_namespace" do + Rails::Generators.namespace(RBUI::Generators, as: "rbui") + end + end + + # Add Zeitwerk configuration + initializer "rbui.configure_zeitwerk" do + Rails.autoloaders.main.inflector.inflect( + "phlex_ui" => "PhlexUI", + "phlexui" => "PhlexUI" + ) + end + end + end +end diff --git a/phlex_ui.gemspec b/phlex_ui.gemspec index d7c4bb1..06de048 100644 --- a/phlex_ui.gemspec +++ b/phlex_ui.gemspec @@ -8,6 +8,7 @@ Gem::Specification.new do |s| s.authors = ["George Kettle"] s.email = "george.kettle@icloud.com" s.files = Dir["lib/**/*.rb", "tasks/**/*.rake"] + s.require_path = "lib" s.homepage = "https://rubygems.org/gems/phlex_ui" s.license = "MIT" diff --git a/test/test_helper.rb b/test/test_helper.rb index c4e7c96..d516fc7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,3 +17,9 @@ def view_template(&) def phlex_context(&) render TestContext.new, & end + +# this is a tracepoint that will output the path of all files loaded that contain the string "phlex" +# trace = TracePoint.new(:class) do |tp| +# puts "Loaded: #{tp.path}" if tp.path.include?("phlex") +# end +# trace.enable From 5d98a7cf4b867a1e88be8c55ee77e334541e101f Mon Sep 17 00:00:00 2001 From: Seth Horsley Date: Wed, 4 Sep 2024 08:36:18 -0400 Subject: [PATCH 2/3] =?UTF-8?q?fix=20a=20few=20thangs=20=F0=9F=A6=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/application.tailwind.css.tt | 68 ++++++++++++------- .../install/templates/tailwind.config.js.tt | 36 ++++++---- lib/rbui/railtie.rb | 8 --- 3 files changed, 64 insertions(+), 48 deletions(-) diff --git a/lib/generators/rbui/install/templates/application.tailwind.css.tt b/lib/generators/rbui/install/templates/application.tailwind.css.tt index f9bcc35..26fa13a 100644 --- a/lib/generators/rbui/install/templates/application.tailwind.css.tt +++ b/lib/generators/rbui/install/templates/application.tailwind.css.tt @@ -5,47 +5,59 @@ @layer base { :root { --background: 0 0% 100%; - --foreground: 0 0% 3.9%; - --primary: 0 0% 9%; + --foreground: 240 10% 3.9%; + --card: 0 0% 100%; + --card-foreground: 240 10% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 240 10% 3.9%; + --primary: 240 5.9% 10%; --primary-foreground: 0 0% 98%; - --secondary: 0 0% 96.1%; - --secondary-foreground: 0 0% 9%; - --muted: 0 0% 96.1%; - --muted-foreground: 0 0% 45.1%; - --accent: 0 0% 96.1%; - --accent-foreground: 0 0% 9%; - --destructive: 350 89% 60%; - --destructive-foreground: 0 0% 100%; + --secondary: 240 4.8% 95.9%; + --secondary-foreground: 240 5.9% 10%; + --muted: 240 4.8% 95.9%; + --muted-foreground: 240 3.8% 46.1%; + --accent: 240 4.8% 95.9%; + --accent-foreground: 240 5.9% 10%; + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 0 0% 98%; + --border: 240 5.9% 90%; + --input: 240 5.9% 90%; + --ring: 240 5.9% 10%; + --radius: 0.5rem; + + /* rbui especific */ --warning: 38 92% 50%; --warning-foreground: 0 0% 100%; --success: 87 100% 37%; --success-foreground: 0 0% 100%; - --border: 0 0% 89.8%; - --input: 0 0% 89.8%; - --ring: 0 0% 3.9%; - --radius: 0.5rem; } - + .dark { - --background: 0 0% 3.9%; + --background: 240 10% 3.9%; --foreground: 0 0% 98%; + --card: 240 10% 3.9%; + --card-foreground: 0 0% 98%; + --popover: 240 10% 3.9%; + --popover-foreground: 0 0% 98%; --primary: 0 0% 98%; - --primary-foreground: 0 0% 9%; - --secondary: 0 0% 14.9%; + --primary-foreground: 240 5.9% 10%; + --secondary: 240 3.7% 15.9%; --secondary-foreground: 0 0% 98%; - --muted: 0 0% 14.9%; - --muted-foreground: 0 0% 63.9%; - --accent: 0 0% 14.9%; + --muted: 240 3.7% 15.9%; + --muted-foreground: 240 5% 64.9%; + --accent: 240 3.7% 15.9%; --accent-foreground: 0 0% 98%; - --destructive: 350 89% 60%; - --destructive-foreground: 0 0% 100%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 0% 98%; + --border: 240 3.7% 15.9%; + --input: 240 3.7% 15.9%; + --ring: 240 4.9% 83.9%; + + /* rbui especific */ --warning: 38 92% 50%; --warning-foreground: 0 0% 100%; --success: 84 81% 44%; --success-foreground: 0 0% 100%; - --border: 0 0% 14.9%; - --input: 0 0% 14.9%; - --ring: 0 0% 83.1%; } } @@ -56,5 +68,9 @@ body { @apply bg-background text-foreground; font-feature-settings: "rlig" 1, "calt" 1; + + /* docs specific */ + /* https://css-tricks.com/snippets/css/system-font-stack/ */ + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; } } diff --git a/lib/generators/rbui/install/templates/tailwind.config.js.tt b/lib/generators/rbui/install/templates/tailwind.config.js.tt index 43549ae..9e42536 100644 --- a/lib/generators/rbui/install/templates/tailwind.config.js.tt +++ b/lib/generators/rbui/install/templates/tailwind.config.js.tt @@ -1,9 +1,9 @@ // For importing tailwind styles from phlex_ui/phlex_ui_pro gem const execSync = require('child_process').execSync; -// Import phlex_ui gem path (To make sure Tailwind loads classes used by phlex_ui gem) -const outputPhlexUI = execSync('bundle show phlex_ui', { encoding: 'utf-8' }); -const phlex_ui_path = outputPhlexUI.trim() + '/**/*.rb'; +// Import rbui gem path +const outputRBUI = execSync('bundle show phlex_ui', { encoding: 'utf-8' }); +const rbui_path = outputRBUI.trim() + '/**/*.rb'; const defaultTheme = require('tailwindcss/defaultTheme') @@ -14,7 +14,7 @@ module.exports = { './app/helpers/**/*.rb', './app/assets/stylesheets/**/*.css', './app/javascript/**/*.js', - phlex_ui_path + rbui_path ], theme: { container: { @@ -43,14 +43,6 @@ module.exports = { DEFAULT: "hsl(var(--destructive))", foreground: "hsl(var(--destructive-foreground))", }, - warning: { - DEFAULT: "hsl(var(--warning))", - foreground: "hsl(var(--warning-foreground))", - }, - success: { - DEFAULT: "hsl(var(--success))", - foreground: "hsl(var(--success-foreground))", - }, muted: { DEFAULT: "hsl(var(--muted))", foreground: "hsl(var(--muted-foreground))", @@ -59,6 +51,23 @@ module.exports = { DEFAULT: "hsl(var(--accent))", foreground: "hsl(var(--accent-foreground))", }, + popover: { + DEFAULT: "hsl(var(--popover))", + foreground: "hsl(var(--popover-foreground))", + }, + card: { + DEFAULT: "hsl(var(--card))", + foreground: "hsl(var(--card-foreground))", + }, + /* rbui especific */ + warning: { + DEFAULT: "hsl(var(--warning))", + foreground: "hsl(var(--warning-foreground))", + }, + success: { + DEFAULT: "hsl(var(--success))", + foreground: "hsl(var(--success-foreground))", + }, }, borderRadius: { lg: `var(--radius)`, @@ -66,7 +75,7 @@ module.exports = { sm: "calc(var(--radius) - 4px)", }, fontFamily: { - sans: defaultTheme.fontFamily.sans, + sans: ["var(--font-sans)", ...defaultTheme.fontFamily.sans], }, }, }, @@ -74,4 +83,3 @@ module.exports = { require("tailwindcss-animate"), ], } - diff --git a/lib/rbui/railtie.rb b/lib/rbui/railtie.rb index 8f5d9fe..39288f7 100644 --- a/lib/rbui/railtie.rb +++ b/lib/rbui/railtie.rb @@ -12,14 +12,6 @@ class Railtie < ::Rails::Railtie Rails::Generators.namespace(RBUI::Generators, as: "rbui") end end - - # Add Zeitwerk configuration - initializer "rbui.configure_zeitwerk" do - Rails.autoloaders.main.inflector.inflect( - "phlex_ui" => "PhlexUI", - "phlexui" => "PhlexUI" - ) - end end end end From 5e2e091f0c1517fc66ffd12c399d9e079f4b612a Mon Sep 17 00:00:00 2001 From: Seth Horsley Date: Mon, 16 Sep 2024 13:37:47 +0200 Subject: [PATCH 3/3] final commit --- LICENSE.txt | 2 +- lib/generators/rbui/install/install_generator.rb | 16 ++++++++-------- .../rbui/install/templates/index_view.rb.tt | 2 +- .../rbui/install/templates/tailwind.config.js.tt | 4 ++-- .../rbui/templates/base_store_initializer.rb.tt | 10 +++++----- lib/rbui.rb | 8 -------- 6 files changed, 17 insertions(+), 25 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index e860eef..89c27dd 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2024 PhlexUI +Copyright (c) 2024 RBUI Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/generators/rbui/install/install_generator.rb b/lib/generators/rbui/install/install_generator.rb index c5db2a0..945f8d8 100644 --- a/lib/generators/rbui/install/install_generator.rb +++ b/lib/generators/rbui/install/install_generator.rb @@ -71,36 +71,36 @@ def pin_rbui_js importmap_binstub = Rails.root.join("bin/importmap") importmap_config_path = Rails.root.join("config/importmap.rb") stimulus_path = Rails.root.join("app/javascript/application.js") + package_name = "rbui-js" if importmap_binstub.exist? - say "Pin rbui-js" + say "Pin #{package_name}" append_to_file importmap_config_path do - %(pin "rbui-js", to: "rbui-js.js"\n) + # %(pin "rbui-js", to: "rbui-js.js"\n) + %(pin #{package_name}, to: "rbui-js.js"\n) end else say "Add rbui-js package" - # run "yarn add rbui-js" - run "yarn add ../phlex_ui" - run "yarn add phlex_ui" + run "yarn add #{package_name}" end if stimulus_path.exist? say "Add RBUI Stimulus controllers" append_to_file stimulus_path do - "\nimport \"rbui-js\";\nimport \"phlex_ui\";\n" + "\nimport \"#{package_name}\";\n" end run "yarn build" else say "Default Stimulus location is missing: app/javascript/controllers/index.js", :red say " Add to your Stimulus index.js:" - say " import \"rbui-js\"" + say " import \"#{package_name}\"" end end def include_rbui say "Add RBUI to your global component layout" insert_into_file "app/views/application_view.rb", after: "class ApplicationView < ApplicationComponent\n" do - " include RBUI\n include PhlexUI\n" + " include RBUI\n" end end diff --git a/lib/generators/rbui/install/templates/index_view.rb.tt b/lib/generators/rbui/install/templates/index_view.rb.tt index a5a8cd7..963dc8d 100644 --- a/lib/generators/rbui/install/templates/index_view.rb.tt +++ b/lib/generators/rbui/install/templates/index_view.rb.tt @@ -2,7 +2,7 @@ class Static::IndexView < ApplicationView def template - render PhlexUI::Button.new { "click me" } + render RBUI::Button.new { "click me" } br {} # UI.Button { "click me" } diff --git a/lib/generators/rbui/install/templates/tailwind.config.js.tt b/lib/generators/rbui/install/templates/tailwind.config.js.tt index 9e42536..58ad8ce 100644 --- a/lib/generators/rbui/install/templates/tailwind.config.js.tt +++ b/lib/generators/rbui/install/templates/tailwind.config.js.tt @@ -1,8 +1,8 @@ -// For importing tailwind styles from phlex_ui/phlex_ui_pro gem +// For importing tailwind styles from rbui gem const execSync = require('child_process').execSync; // Import rbui gem path -const outputRBUI = execSync('bundle show phlex_ui', { encoding: 'utf-8' }); +const outputRBUI = execSync('bundle show rbui', { encoding: 'utf-8' }); const rbui_path = outputRBUI.trim() + '/**/*.rb'; const defaultTheme = require('tailwindcss/defaultTheme') diff --git a/lib/generators/rbui/templates/base_store_initializer.rb.tt b/lib/generators/rbui/templates/base_store_initializer.rb.tt index e88f39a..c07b3f6 100644 --- a/lib/generators/rbui/templates/base_store_initializer.rb.tt +++ b/lib/generators/rbui/templates/base_store_initializer.rb.tt @@ -1,9 +1,9 @@ -PhlexUI.setup do |config| - # Setting a namespace allows you to access PhlexUI components through this namespace. +RBUI.setup do |config| + # Setting a namespace allows you to access RBUI components through this namespace. # For example, with namespace set to "UI", you can use: - # UI::Button.new instead of PhlexUI::Button.new - # UI::Card.new instead of PhlexUI::Card.new + # UI::Button.new instead of RBUI::Button.new + # UI::Card.new instead of RBUI::Card.new # This can help avoid naming conflicts and allows for cleaner, more concise code. - # If you prefer to use PhlexUI components directly, you can leave this unset. + # If you prefer to use RBUI components directly, you can leave this unset. config.namespace = "UI" end diff --git a/lib/rbui.rb b/lib/rbui.rb index 1816157..d1f6f2c 100644 --- a/lib/rbui.rb +++ b/lib/rbui.rb @@ -3,14 +3,6 @@ require "json" require "phlex" -if defined?(ActiveSupport::Inflector) - require "active_support/inflector" - ActiveSupport::Inflector.inflections(:en) do |inflect| - inflect.acronym "PhlexUI" - inflect.acronym "UI" - end -end - module RBUI extend Phlex::Kit