Class: GovukPublishingComponents::ComponentGuideController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- GovukPublishingComponents::ComponentGuideController
- Defined in:
- app/controllers/govuk_publishing_components/component_guide_controller.rb
Constant Summary collapse
- MATCH_COMPONENTS =
/(?<=govuk_publishing_components\/components\/)[\/a-zA-Z_-]+(?=['"])/
Instance Method Summary collapse
- #components_in_use_js ⇒ Object
- #components_in_use_sass ⇒ Object
- #example ⇒ Object
- #index ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
Instance Method Details
#components_in_use_js ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 58 def components_in_use_js additional_files = "//= require govuk_publishing_components/lib\n" components = find_all_partials_in(get_used_component_names) components.map { |component| "//= require govuk_publishing_components/components/#{component.gsub('_', '-')}" if component_has_js_file(component.gsub("_", "-")) }.compact.uniq.sort.join("\n").squeeze("\n").prepend(additional_files) end |
#components_in_use_sass ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 47 def components_in_use_sass additional_files = "@import 'govuk_publishing_components/govuk_frontend_support';\n" additional_files << "@import 'govuk_publishing_components/component_support';\n" components = find_all_partials_in(get_used_component_names) components.map { |component| "@import 'govuk_publishing_components/components/#{component.gsub('_', '-')}';" if component_has_sass_file(component.gsub("_", "-")) }.compact.uniq.sort.join("\n").squeeze("\n").prepend(additional_files) end |
#example ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 23 def example @component_doc = component_docs.get(params[:component]) @component_example = @component_doc.examples.find { |f| f.id == params[:example] } @guide_breadcrumbs = [ , (@component_doc, @component_example), { title: @component_example.name, }, ] end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 7 def index @application_path = Rails.root @component_gem_path = Gem.loaded_specs["govuk_publishing_components"].full_gem_path @component_docs = component_docs.all @gem_component_docs = gem_component_docs.all @used_components = used_components_names.get_component_docs @unused_components = unused_components_names.get_component_docs @components_in_use_sass = components_in_use_sass @components_in_use_js = components_in_use_js end |
#preview ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 35 def preview @component_examples = [] @component_doc = component_docs.get(params[:component]) @preview = true if params[:example].present? @component_examples.push(@component_doc.examples.find { |f| f.id == params[:example] }) else @component_examples = @component_doc.examples end end |
#show ⇒ Object
18 19 20 21 |
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 18 def show @component_doc = component_docs.get(params[:component]) @guide_breadcrumbs = [, (@component_doc)] end |