Module: ViewPrimitives::Generators::Components

Defined in:
lib/generators/view_primitives/components.rb

Constant Summary collapse

TEMPLATE_ROOT =
File.expand_path("add/templates", __dir__)
EXTRA_STIMULUS =

Stimulus controllers not colocated with the component template directory.

{
  "alert_dialog" => {source: "dialog/dialog_controller.js", name: "dialog"}
}.freeze
SETUP_NOTES =

Post-install instructions for components that require external dependencies.

{
  "chart" => <<~TEXT,
  "wysiwyg" => <<~TEXT
    WYSIWYG defaults to Trix (adapter: :trix). To use Trix, install ActionText:

      bundle add actiontext
      rails action_text:install

    To use Quill (adapter: :quill), add it to your importmap:

      # config/importmap.rb
      pin "quill", to: "https://esm.sh/quill@2"

    Also add Quill's stylesheet to your CSS entry point:

      @import url("https://esm.sh/quill@2/dist/quill.snow.css");

    Usage:

      ui :wysiwyg, name: "body"
      ui :wysiwyg, name: "body", adapter: :quill, placeholder: "Write something..."
  TEXT
}.freeze

Class Method Summary collapse

Class Method Details

.installed?(component, root) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/generators/view_primitives/components.rb', line 57

def self.installed?(component, root)
  File.exist?(File.join(root, primary_path(component)))
end

.primary_path(component) ⇒ Object



53
54
55
# File 'lib/generators/view_primitives/components.rb', line 53

def self.primary_path(component)
  "app/components/ui/#{component}_component.rb"
end

.supportedObject



49
50
51
# File 'lib/generators/view_primitives/components.rb', line 49

def self.supported
  @supported ||= Dir.children(TEMPLATE_ROOT).sort.freeze
end