Sha256: 4afad0567dbc4b82f477d1acd707b49b65bc227001465341640090f8c1cf58d9

Contents?: true

Size: 1.15 KB

Versions: 62

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', __FILE__)

    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

62 entries across 62 versions & 1 rubygems

Version Path
govuk_publishing_components-12.11.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.10.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.9.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.9.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.8.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.7.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.7.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.6.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.5.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.4.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.3.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.2.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.1.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.0.1 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-12.0.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-11.2.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-11.1.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-11.0.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-10.2.0 lib/generators/govuk_publishing_components/component_generator.rb
govuk_publishing_components-10.1.0 lib/generators/govuk_publishing_components/component_generator.rb