Class: GovukPublishingComponents::ComponentGuideController

Inherits:
ApplicationController
  • Object
show all
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

Instance Method Details

#components_in_use_jsObject



57
58
59
60
61
62
63
64
65
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 57

def components_in_use_js
  additional_files = "//= require govuk_publishing_components/lib\n"

  components = find_all_partials_in(components_in_use)

  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_sassObject



46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 46

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(components_in_use)

  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

#exampleObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 22

def example
  @component_doc = component_docs.get(params[:component])
  @component_example = @component_doc.examples.find { |f| f.id == params[:example] }
  @guide_breadcrumbs = [
    index_breadcrumb,
    component_breadcrumb(@component_doc, @component_example),
    {
      title: @component_example.name,
    },
  ]
end

#indexObject



7
8
9
10
11
12
13
14
15
# 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
  @components_in_use_docs = components_in_use_docs.used_in_this_app
  @components_in_use_sass = components_in_use_sass
  @components_in_use_js = components_in_use_js
end

#previewObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 34

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

#showObject



17
18
19
20
# File 'app/controllers/govuk_publishing_components/component_guide_controller.rb', line 17

def show
  @component_doc = component_docs.get(params[:component])
  @guide_breadcrumbs = [index_breadcrumb, component_breadcrumb(@component_doc)]
end