Sha256: 47af741d9f9f52700fa9e1282a87d37e41c3e61f0b0d515785ccb6a95c82385e

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require "fileutils"

say "Installing Stimulus...", :green

run("yarn add stimulus")

say 'Adding Stimulus to "frontend/javascript/index.js"...', :magenta

javascript_import do
  <<~JS
    import { Application } from "stimulus"
    import { definitionsFromContext } from "stimulus/webpack-helpers"
  JS
end

javascript_dir = File.join("frontend", "javascript")

append_to_file(File.join(javascript_dir, "index.js")) do
  <<~JS
    const application = Application.start()
    const context = require.context("./controllers", true, /\.js$/)
    application.load(definitionsFromContext(context))
  JS
end

controller_dir = File.join(javascript_dir, "controllers")

say "Creating a `./#{controller_dir}` directory...", :magenta
FileUtils.mkdir_p(controller_dir)

say "Creating an example Stimulus Controller for you!...", :magenta
create_file(File.join(controller_dir, "example_controller.js")) do
  <<~JS
    import { Controller } from "stimulus"
    export default class extends Controller {
      connect() {
        console.log("Hello, Stimulus!", this.element)
      }
    }
  JS
end

say "Stimulus successfully added", :green

say "To start adding controllers, visit the `./frontend/javascript/controllers/` directory", :blue
say "Make sure your controllers follow the `[name]_controller.js` convention", :blue
say 'For further reading, check out "https://stimulus.hotwire.dev/"', :blue

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0.alpha11 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha10 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha9 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha8 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha7 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha6 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha5 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.5 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha4 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha3 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha2 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-1.0.0.alpha1 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.4 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.3 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.2 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.1 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.0 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.0.beta4 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.0.beta3 lib/bridgetown-core/configurations/stimulus.rb
bridgetown-core-0.21.0.beta2 lib/bridgetown-core/configurations/stimulus.rb