Class: RailsTemplate18f::Generators::DapGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Base
Defined in:
lib/generators/rails_template18f/dap/dap_generator.rb

Instance Method Summary collapse

Instance Method Details

#install_js_snippetObject



28
29
30
31
32
33
34
35
36
# File 'lib/generators/rails_template18f/dap/dap_generator.rb', line 28

def install_js_snippet
  insert_into_file "app/views/layouts/application.html.erb", "\n    <% if Rails.env.production? %>\n<!-- We participate in the US government's analytics program. See the data at analytics.usa.gov. -->\n<%= javascript_include_tag \"https://dap.digitalgov.gov/Universal-Federated-Analytics-Min.js?agency=\#{options[:agency_code]}\", async: true, id:\"_fed_an_ua_tag\" %>\n    <% end %>\n", before: /^\s+<\/head>/
end

#update_boundary_diagramObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/rails_template18f/dap/dap_generator.rb', line 47

def update_boundary_diagram
  boundary_filename = "doc/compliance/apps/application.boundary.md"
  insert_into_file boundary_filename, "    System_Ext(dap, \"DAP\", \"Analytics collection\")\n", after: "Boundary(gsa_saas, \"GSA-authorized SaaS\") {\n"
  insert_into_file boundary_filename, "    Rel(browser, dap, \"reports usage\", \"https (443)\")\n    Rel(developer, dap, \"View traffic statistics\", \"https GET (443)\")\n  EOB\nend\n", before: "@enduml"

#update_content_security_policyObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/rails_template18f/dap/dap_generator.rb', line 17

def update_content_security_policy
  csp_file = "config/initializers/content_security_policy.rb"
  gsub_file csp_file, /(policy.img_src .*)$/, '\1, "https://www.google-analytics.com"'
  gsub_file csp_file, /(policy.script_src .*)$/, '\1, "https://dap.digitalgov.gov", "https://www.google-analytics.com"'
  if file_content(csp_file).match?(/policy.connect_src/)
    gsub_file csp_file, /(policy.connect_src .*)$/, '\1, "https://dap.digitalgov.gov", "https://www.google-analytics.com"'
  else
    gsub_file csp_file, /((#?)(\s+)policy.script_src .*)$/, "\\1\n\\2\\3policy.connect_src :self, \"https://dap.digitalgov.gov\", \"https://www.google-analytics.com\""
  end
end

#update_readmeObject



38
39
40
41
42
43
44
45
# File 'lib/generators/rails_template18f/dap/dap_generator.rb', line 38

def update_readme
  insertion_regex = /^## Documentation$/
  if file_content("README.md").match?(insertion_regex)
    insert_into_file "README.md", readme, before: insertion_regex
  else
    append_to_file "README.md", readme
  end
end