Sha256: b3212a13bd412a85e6844bae1ed627599891ee37d312f465e1ed38d0bd0f5695

Contents?: true

Size: 1.89 KB

Versions: 21

Compression:

Stored size: 1.89 KB

Contents

require "rails/generators"

module ReactOnRails
  module Generators
    class ReactWithReduxGenerator < Rails::Generators::Base
      Rails::Generators.hide_namespace(namespace)
      source_root(File.expand_path("../templates", __FILE__))

      # --server-rendering
      class_option :server_rendering,
                   type: :boolean,
                   default: false,
                   desc: "Configure for server-side rendering of webpack JavaScript",
                   aliases: "-S"

      def create_redux_directories
        dirs = %w(actions constants reducers store)
        dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }

        empty_directory("client/app/lib/middlewares")
      end

      def copy_base_redux_files
        base_path = "redux/base/"
        %w(client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
           client/app/bundles/HelloWorld/containers/HelloWorld.jsx
           client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
           client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
           client/app/bundles/HelloWorld/reducers/index.jsx
           client/app/bundles/HelloWorld/store/helloWorldStore.jsx
           client/app/lib/middlewares/loggerMiddleware.js).each do |file|
             copy_file(base_path + file, file)
           end
      end

      def copy_server_rendering_redux_files
        return unless options.server_rendering?
        base_path = "redux/server_rendering/"
        file = "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
        copy_file(base_path + file, file)
      end

      def template_appropriate_version_of_hello_world_app_client
        filename = "HelloWorldAppClient.jsx"
        location = "client/app/bundles/HelloWorld/startup"
        template("redux/base/#{location}/HelloWorldAppClient.jsx.tt", "#{location}/#{filename}")
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
react_on_rails-5.2.0 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-5.1.1 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-5.1.0 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-5.0.0 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-5.0.0.rc.1 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.3 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.2 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.1 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.0 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.0.beta.3 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.0.beta.2 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-4.0.0.beta.1 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-3.0.6 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-3.0.5 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-3.0.4 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-3.0.3 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-3.0.2 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-2.0.1 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-2.0.0 lib/generators/react_on_rails/react_with_redux_generator.rb
react_on_rails-2.0.0.rc.4 lib/generators/react_on_rails/react_with_redux_generator.rb