Sha256: 1d632385eb6f76870ef289661ea97394e4c6d02155ea874e5d78e4fd941d0216

Contents?: true

Size: 1.15 KB

Versions: 166

Compression:

Stored size: 1.15 KB

Contents

require 'rails/generators'
require 'fileutils'

module GovukPublishingComponents
  class ComponentGenerator < ::Rails::Generators::NamedBase
    source_root File.expand_path('templates', __dir__)

    def copy_component_files
      @public_name = file_name.dasherize
      @component_prefix = 'app-c-'
      component_directory_name = GovukPublishingComponents::Config.component_directory_name

      template_dir = "app/views/#{component_directory_name}/"
      docs_dir = "app/views/#{component_directory_name}/docs/"
      scss_dir = "app/assets/stylesheets/#{component_directory_name.dasherize}/"

      create_directory_if_not_exists(template_dir)
      create_directory_if_not_exists(docs_dir)
      create_directory_if_not_exists(scss_dir)

      template '_component.html.erb', "#{template_dir}_#{@public_name}.html.erb"
      template 'component.yml.erb', "#{docs_dir}#{@public_name}.yml"
      template '_component.scss', "#{scss_dir}_#{@public_name}.scss"
    end

  private

    def create_directory_if_not_exists(dir)
      if not File.directory?(dir)
        puts("Directory #{dir} not found, creating")
        FileUtils::mkdir_p dir
      end
    end
  end
end

Version data entries

166 entries across 166 versions & 1 rubygems

Version Path
govuk_publishing_components-21.27.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.27.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.26.2 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.26.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.26.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.25.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.24.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.23.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.23.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.22.2 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.22.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.22.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.21.3 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.21.2 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.21.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.21.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.20.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.19.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.19.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-21.18.0 lib/generators/govuk_publishing_components/component_generator.rb