-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from alphagov/new-component-docs
Add documentation and tooling for GOV.UK Components
- Loading branch information
Showing
6 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Description: | ||
Generates a new GOV.UK component | ||
|
||
Example: | ||
rails generate govuk_component [compontent_name] |
28 changes: 28 additions & 0 deletions
28
lib/generators/govuk_component/govuk_component_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'json' | ||
|
||
class GovukComponentGenerator < Rails::Generators::NamedBase | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
def copy_component_files | ||
@public_name = file_name.dasherize | ||
|
||
template 'component.html.erb', "app/views/govuk_component/#{file_name}.raw.html.erb" | ||
template '_component.scss', "app/assets/stylesheets/govuk-component/_#{@public_name}.scss" | ||
|
||
append_to_file "app/assets/stylesheets/govuk-component/_component.scss", "@import \"#{@public_name}\";\n" | ||
|
||
docs_path = 'app/views/govuk_component/docs.json' | ||
docs = JSON.parse(IO.read(docs_path)) | ||
File.open(docs_path, 'w') do |file| | ||
docs.push({ | ||
"id" => file_name, | ||
"name" => human_name, | ||
"description" => "", | ||
"fixtures" => { | ||
"default" => {} | ||
} | ||
}) | ||
file.write(JSON.pretty_generate(docs)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.govuk-<%= @public_name %> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="govuk-<%= @public_name %>"> | ||
<%= human_name %> | ||
</div> |