Skip to content

Commit

Permalink
Add support for Rackup (.ru) config files
Browse files Browse the repository at this point in the history
This adds support for the `.ru` extension, which is idiomatically used for `config.ru` files in the Rack ruby framework. This specifically requires adding an additional element to the `head` slice for `#\` directives.

I added a test explicitly for validating the intact header is left in.
  • Loading branch information
CalebAlbers committed Aug 2, 2022
1 parent 6c3d250 commit 67d5754
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func licenseHeader(path string, tmpl *template.Template, data licenseData) ([]by
lic, err = executeTemplate(tmpl, data, "/**", " * ", " */")
case ".cc", ".cpp", ".cs", ".go", ".hcl", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv":
lic, err = executeTemplate(tmpl, data, "", "// ", "")
case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile", ".tcl", ".bzl", ".pl", ".pp":
case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile", ".ru", ".tcl", ".bzl", ".pl", ".pp":
lic, err = executeTemplate(tmpl, data, "", "# ", "")
case ".el", ".lisp":
lic, err = executeTemplate(tmpl, data, "", ";; ", "")
Expand Down Expand Up @@ -331,6 +331,7 @@ var head = []string{
"<!doctype", // HTML doctype
"# encoding:", // Ruby encoding
"# frozen_string_literal:", // Ruby interpreter instruction
"#\\", // Ruby Rack directive https://github.com/rack/rack/wiki/(tutorial)-rackup-howto
"<?php", // PHP opening tag
"# escape", // Dockerfile directive https://docs.docker.com/engine/reference/builder/#parser-directives
"# syntax", // Dockerfile directive https://docs.docker.com/engine/reference/builder/#parser-directives
Expand Down
3 changes: 2 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func TestAddLicense(t *testing.T) {
{"<!DOCTYPE HTML>\ncontent", "<!DOCTYPE HTML>\n// HYS\n\ncontent", true},
{"# encoding: UTF-8\ncontent", "# encoding: UTF-8\n// HYS\n\ncontent", true},
{"# frozen_string_literal: true\ncontent", "# frozen_string_literal: true\n// HYS\n\ncontent", true},
{"#\\ -w -p 8765\ncontent", "#\\ -w -p 8765\n// HYS\n\ncontent", true},
{"<?php\ncontent", "<?php\n// HYS\n\ncontent", true},
{"# escape: `\ncontent", "# escape: `\n// HYS\n\ncontent", true},
{"# syntax: docker/dockerfile:1.3\ncontent", "# syntax: docker/dockerfile:1.3\n// HYS\n\ncontent", true},
Expand Down Expand Up @@ -316,7 +317,7 @@ func TestLicenseHeader(t *testing.T) {
"// HYS\n\n",
},
{
[]string{"f.py", "f.sh", "f.yaml", "f.yml", "f.dockerfile", "dockerfile", "f.rb", "gemfile", "f.tcl", "f.bzl", "f.pl", "f.pp"},
[]string{"f.py", "f.sh", "f.yaml", "f.yml", "f.dockerfile", "dockerfile", "f.rb", "gemfile", ".ru", "f.tcl", "f.bzl", "f.pl", "f.pp"},
"# HYS\n\n",
},
{
Expand Down

0 comments on commit 67d5754

Please sign in to comment.