middleman-hashicorp 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +21 -0
  6. data/Makefile +21 -0
  7. data/README.md +183 -0
  8. data/Rakefile +11 -0
  9. data/assets/fonts/glyphicons-halflings-regular.eot +0 -0
  10. data/assets/fonts/glyphicons-halflings-regular.svg +229 -0
  11. data/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
  12. data/assets/fonts/glyphicons-halflings-regular.woff +0 -0
  13. data/assets/images/fastly_logo.png +0 -0
  14. data/assets/images/icons/icon_centos.png +0 -0
  15. data/assets/images/icons/icon_darwin.png +0 -0
  16. data/assets/images/icons/icon_debian.png +0 -0
  17. data/assets/images/icons/icon_freebsd.png +0 -0
  18. data/assets/images/icons/icon_hashios.png +0 -0
  19. data/assets/images/icons/icon_linux.png +0 -0
  20. data/assets/images/icons/icon_macosx.png +0 -0
  21. data/assets/images/icons/icon_netbsd.png +0 -0
  22. data/assets/images/icons/icon_openbsd.png +0 -0
  23. data/assets/images/icons/icon_rpm.png +0 -0
  24. data/assets/images/icons/icon_solaris.png +0 -0
  25. data/assets/images/icons/icon_windows.png +0 -0
  26. data/assets/javascripts/bootstrap.js +2114 -0
  27. data/assets/javascripts/ie-compat.js +1 -0
  28. data/assets/javascripts/ie-compat/html5shiv-printshiv.js +520 -0
  29. data/assets/javascripts/ie-compat/html5shiv.js +322 -0
  30. data/assets/javascripts/ie-compat/respond.js +353 -0
  31. data/assets/javascripts/jquery.js +9190 -0
  32. data/docker/Dockerfile +22 -0
  33. data/lib/middleman-hashicorp.rb +6 -0
  34. data/lib/middleman-hashicorp/bintray.rb +98 -0
  35. data/lib/middleman-hashicorp/extension.rb +237 -0
  36. data/lib/middleman-hashicorp/redcarpet.rb +134 -0
  37. data/lib/middleman-hashicorp/releases.rb +32 -0
  38. data/lib/middleman-hashicorp/rouge.rb +16 -0
  39. data/lib/middleman-hashicorp/version.rb +5 -0
  40. data/lib/middleman_extension.rb +1 -0
  41. data/middleman-hashicorp.gemspec +48 -0
  42. data/spec/spec_helper.rb +34 -0
  43. data/spec/unit/helper_spec.rb +71 -0
  44. data/spec/unit/markdown_spec.rb +206 -0
  45. data/spec/unit/releases_spec.rb +34 -0
  46. metadata +330 -0
@@ -0,0 +1,32 @@
1
+ require "open-uri"
2
+
3
+ class Middleman::HashiCorp::Releases
4
+ RELEASES_URL = "https://releases.hashicorp.com".freeze
5
+
6
+ class Build < Struct.new(:name, :version, :os, :arch, :url); end
7
+
8
+ def self.fetch(product, version)
9
+ url = "#{RELEASES_URL}/#{product}/#{version}/index.json"
10
+ r = JSON.parse(open(url).string,
11
+ create_additions: false,
12
+ symbolize_names: true,
13
+ )
14
+
15
+ # Convert the builds into the following format:
16
+ #
17
+ # {
18
+ # "os" => {
19
+ # "arch" => "https://download.url"
20
+ # }
21
+ # }
22
+ #
23
+ {}.tap do |h|
24
+ r[:builds].each do |b|
25
+ build = Build.new(*b.values_at(*Build.members))
26
+
27
+ h[build.os] ||= {}
28
+ h[build.os][build.arch] = build.url
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ require "rouge"
2
+ require "rouge/lexers/javascript"
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class HCL < Ruby
7
+ title "HCL"
8
+ desc "HashiCorp Configuration Language"
9
+
10
+ tag "hcl"
11
+ aliases "nomad", "terraform", "tf"
12
+ filenames "*.hcl", "*.nomad", "*.tf"
13
+ mimetypes "application/hcl", "text/plain"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module HashiCorp
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "middleman-hashicorp"
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-hashicorp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'middleman-hashicorp'
8
+ spec.version = Middleman::HashiCorp::VERSION
9
+ spec.authors = ['Seth Vargo']
10
+ spec.email = ['sethvargo@gmail.com']
11
+ spec.summary = 'A series of helpers for consistency among HashiCorp\'s middleman sites'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/hashicorp/middleman-hashicorp'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+
23
+ # Middleman
24
+ spec.add_dependency 'middleman', '~> 3.4'
25
+ spec.add_dependency 'middleman-minify-html', '~> 3.4'
26
+ spec.add_dependency 'middleman-livereload', '~> 3.4'
27
+ spec.add_dependency 'middleman-syntax', '~> 3.0'
28
+
29
+ # Assets
30
+ spec.add_dependency 'bootstrap-sass', '~> 3.3'
31
+ spec.add_dependency 'builder', '~> 3.2'
32
+ spec.add_dependency 'less', '~> 2.6'
33
+ spec.add_dependency 'redcarpet', '~> 3.2'
34
+ spec.add_dependency 'therubyracer', '~> 0.12'
35
+
36
+ # Server
37
+ spec.add_dependency 'rack-contrib', '~> 1.2'
38
+ spec.add_dependency 'rack-protection', '~> 1.5'
39
+ spec.add_dependency 'rack-rewrite', '~> 1.5'
40
+ spec.add_dependency 'thin', '~> 1.6'
41
+ spec.add_dependency 'rack-ssl-enforcer', '~> 0.2'
42
+
43
+ # Development dependencies
44
+ spec.add_development_dependency 'rspec', '~> 3.2'
45
+
46
+ spec.add_development_dependency 'bundler', '~> 1.7'
47
+ spec.add_development_dependency 'rake', '~> 10.4'
48
+ end
@@ -0,0 +1,34 @@
1
+ require "rspec"
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = :expect
6
+ end
7
+
8
+ config.filter_run focus: true
9
+ config.run_all_when_everything_filtered = true
10
+ end
11
+
12
+ RSpec::Matchers.define :render_html do |html|
13
+ diffable
14
+
15
+ match do |markdown|
16
+ @expected = html.strip
17
+
18
+ instance = Middleman::HashiCorp::RedcarpetHTML.new
19
+ instance.middleman_app = middleman_app
20
+
21
+ options = Middleman::HashiCorp::RedcarpetHTML::REDCARPET_OPTIONS
22
+ parser = Redcarpet::Markdown.new(instance, options)
23
+ @actual = parser.render(markdown).strip
24
+
25
+ @expected == @actual
26
+ end
27
+ end
28
+
29
+ # The default middleman application server.
30
+ #
31
+ # @return [Middleman::Application]
32
+ def middleman_app
33
+ @app ||= Middleman::Application.server.inst
34
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+ require "middleman-hashicorp/extension"
3
+
4
+ class Middleman::HashiCorpExtension
5
+ describe "#github_url" do
6
+ before(:all) do
7
+ app = middleman_app
8
+ @instance = Middleman::HashiCorpExtension.new(
9
+ app,
10
+ bintray_enabled: false,
11
+ name: "consul",
12
+ version: "0.1.0",
13
+ github_slug: "hashicorp/this_project",
14
+ )
15
+ @instance.app = app # unclear why this needs to be set after, but it must
16
+ end
17
+
18
+ it "returns the project's GitHub URL if no argument is supplied" do
19
+ expect(@instance.app.github_url).to match("https://github.com/hashicorp/this_project")
20
+ end
21
+
22
+ it "returns false if github_slug has not been set" do
23
+ slugless_app = Middleman::Application.server.inst
24
+ slugless_instance = Middleman::HashiCorpExtension.new(
25
+ slugless_app,
26
+ name: "consul",
27
+ version: "0.1.0",
28
+ bintray_enabled: false,
29
+ )
30
+ slugless_instance.app = slugless_app
31
+ expect(slugless_instance.app.github_url).to eq(false)
32
+ end
33
+ end
34
+
35
+ describe "#path_in_repository" do
36
+ before(:each) do
37
+ app = middleman_app
38
+ @instance = Middleman::HashiCorpExtension.new(
39
+ app,
40
+ bintray_enabled: false,
41
+ name: "consul",
42
+ version: "0.1.0",
43
+ github_slug: "hashicorp/this_project",
44
+ website_root: "website",
45
+ )
46
+ @instance.app = app
47
+ end
48
+
49
+ context "when a resource's path string is not within its source_file string" do
50
+ it "returns a resource's path relative to its source repository's root directory" do
51
+ current_page = Middleman::Sitemap::Resource.new(
52
+ @instance.app.sitemap,
53
+ "intro/examples/cross-provider.html",
54
+ "/some/bunch/of/directories/intro/examples/cross-provider.markdown")
55
+ path_in_repository = @instance.app.path_in_repository(current_page)
56
+ expect(path_in_repository).to match("website/source/intro/examples/cross-provider.markdown")
57
+ end
58
+ end
59
+
60
+ context "when a resource's path string lies within its source_file string" do
61
+ it "returns a resource's path relative to its source repository's root directory" do
62
+ current_page = Middleman::Sitemap::Resource.new(
63
+ @instance.app.sitemap,
64
+ "docs/index.html",
65
+ "/some/bunch/of/directories/website/source/docs/index.html.markdown")
66
+ path_in_repository = @instance.app.path_in_repository(current_page)
67
+ expect(path_in_repository).to match("website/source/docs/index.html.markdown")
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,206 @@
1
+ require "spec_helper"
2
+ require "middleman-hashicorp/extension"
3
+
4
+ module Middleman::HashiCorp
5
+ describe RedcarpetHTML do
6
+ it "adds links to code list elements" do
7
+ markdown = <<-EOH.gsub(/^ {8}/, "")
8
+ This is a list:
9
+
10
+ - `one`
11
+ - `two` has some `code` inside
12
+ - `three has ^ and spaces` with text
13
+ - four
14
+ EOH
15
+ output = <<-EOH.gsub(/^ {8}/, "")
16
+ <p>This is a list:</p>
17
+
18
+ <ul>
19
+ <li><a name="one" /><a href="#one"><code>one</code></a>
20
+ </li>
21
+ <li><a name="two" /><a href="#two"><code>two</code></a> has some <code>code</code> inside
22
+ </li>
23
+ <li><a name="three_has_and_spaces" /><a href="#three_has_and_spaces"><code>three has ^ and spaces</code></a> with text
24
+ </li>
25
+ <li>four
26
+ </li>
27
+ </ul>
28
+ EOH
29
+
30
+ expect(markdown).to render_html(output)
31
+ end
32
+
33
+ it "adds links to code list elements when they have newlines" do
34
+ markdown = <<-EOH.gsub(/^ {8}/, "")
35
+ This is a list:
36
+
37
+ - `one`
38
+
39
+ - `two` has some `code` inside
40
+
41
+ - `three has ^ and spaces` with text
42
+
43
+ - four
44
+ EOH
45
+ output = <<-EOH.gsub(/^ {8}/, "")
46
+ <p>This is a list:</p>
47
+
48
+ <ul>
49
+ <li><p><a name="one" /><a href="#one"><code>one</code></a></p>
50
+ </li>
51
+ <li><p><a name="two" /><a href="#two"><code>two</code></a> has some <code>code</code> inside</p>
52
+ </li>
53
+ <li><p><a name="three_has_and_spaces" /><a href="#three_has_and_spaces"><code>three has ^ and spaces</code></a> with text</p>
54
+ </li>
55
+ <li><p>four</p>
56
+ </li>
57
+ </ul>
58
+ EOH
59
+
60
+ expect(markdown).to render_html(output)
61
+ end
62
+
63
+ it "does not add links if they already exist" do
64
+ markdown = <<-EOH.gsub(/^ {8}/, "")
65
+ - [`/one`](#link_one): Some text
66
+ - [`/two`](#link_two)
67
+ - `three` is a regular auto-link
68
+ - [`/four`](#link_four) - Same as one but with a -
69
+ EOH
70
+ output = <<-EOH.gsub(/^ {8}/, "")
71
+ <ul>
72
+ <li><a href="#link_one"><code>/one</code></a>: Some text
73
+ </li>
74
+ <li><a href="#link_two"><code>/two</code></a>
75
+ </li>
76
+ <li><a name="three" /><a href="#three"><code>three</code></a> is a regular auto-link
77
+ </li>
78
+ <li><a href="#link_four"><code>/four</code></a> - Same as one but with a -
79
+ </li>
80
+ </ul>
81
+ EOH
82
+
83
+ expect(markdown).to render_html(output)
84
+ end
85
+
86
+ it "adds links to unordered lists with unrelated content links" do
87
+ markdown = <<-EOH.gsub(/^ {8}/, "")
88
+ - `one`
89
+
90
+ - `two` - has a [link_two](#link_two) inside
91
+
92
+ - `three`: is regular but with a colon
93
+ EOH
94
+ output = <<-EOH.gsub(/^ {8}/, "")
95
+ <ul>
96
+ <li><p><a name="one" /><a href="#one"><code>one</code></a></p>
97
+ </li>
98
+ <li><p><a name="two" /><a href="#two"><code>two</code></a> - has a <a href="#link_two">link_two</a> inside</p>
99
+ </li>
100
+ <li><p><a name="three" /><a href="#three"><code>three</code></a>: is regular but with a colon</p>
101
+ </li>
102
+ </ul>
103
+ EOH
104
+
105
+ expect(markdown).to render_html(output)
106
+ end
107
+
108
+ it "supports markdown inside HTML" do
109
+ markdown = <<-EOH.gsub(/^ {8}/, "")
110
+ This is some markdown
111
+
112
+ <div class="center">
113
+ **Here** is some _html_ though! ;)
114
+ </div>
115
+ EOH
116
+ output = <<-EOH.gsub(/^ {8}/, "")
117
+ <p>This is some markdown</p>
118
+ <div class="center">
119
+ <p><strong>Here</strong> is some <em>html</em> though! ;)</p>
120
+ </div>
121
+ EOH
122
+
123
+ expect(markdown).to render_html(output)
124
+ end
125
+
126
+ it "uses the proper options for recursive markdown" do
127
+ markdown = <<-EOH.gsub(/^ {8}/, "")
128
+ This is some markdown
129
+
130
+ <div class="center">
131
+ **Here** is some _html_ though! ;)
132
+
133
+ no_intra_emphasis still applies, as does ~~strikethrough~~.
134
+ </div>
135
+ EOH
136
+ output = <<-EOH.gsub(/^ {8}/, "")
137
+ <p>This is some markdown</p>
138
+ <div class="center">
139
+ <p><strong>Here</strong> is some <em>html</em> though! ;)</p>
140
+ <p>no_intra_emphasis still applies, as does <del>strikethrough</del>.</p>
141
+ </div>
142
+ EOH
143
+
144
+ expect(markdown).to render_html(output)
145
+ end
146
+
147
+ it "supports alert boxes" do
148
+ markdown = <<-EOH.gsub(/^ {8}/, "")
149
+ => This is a success note
150
+
151
+ -> This is an info note
152
+
153
+ ~> This is a _warning_ note
154
+
155
+ !> This is a danger note
156
+
157
+ And this is a regular paragraph!
158
+ EOH
159
+ output = <<-EOH.gsub(/^ {8}/, "")
160
+ <div class="alert alert-success" role="alert">
161
+ <p>This is a success note</p>
162
+ </div>
163
+ <div class="alert alert-info" role="alert">
164
+ <p>This is an info note</p>
165
+ </div>
166
+ <div class="alert alert-warning" role="alert">
167
+ <p>This is a <em>warning</em> note</p>
168
+ </div>
169
+ <div class="alert alert-danger" role="alert">
170
+ <p>This is a danger note</p>
171
+ </div>
172
+ <p>And this is a regular paragraph!</p>
173
+ EOH
174
+
175
+ expect(markdown).to render_html(output)
176
+ end
177
+
178
+ it "supports TOC data" do
179
+ markdown = <<-EOH.gsub(/^ {8}/, "")
180
+ # Hello World
181
+ ## Subpath
182
+ EOH
183
+ output = <<-EOH.gsub(/^ {8}/, "")
184
+ <h1 id="hello-world">Hello World</h1>
185
+
186
+ <h2 id="subpath">Subpath</h2>
187
+ EOH
188
+
189
+ expect(markdown).to render_html(output)
190
+ end
191
+
192
+ it "supports fenced code blocks" do
193
+ markdown = <<-EOH.gsub(/^ {8}/, "")
194
+ ```ruby
195
+ puts "hi"
196
+ ```
197
+ EOH
198
+ output = <<-EOH.gsub(/^ {8}/, "")
199
+ <pre><code class="ruby">puts &quot;hi&quot;
200
+ </code></pre>
201
+ EOH
202
+
203
+ expect(markdown).to render_html(output)
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+ require "middleman-hashicorp/releases"
3
+
4
+ describe Middleman::HashiCorp::Releases do
5
+ context "when the product does not exist" do
6
+ it "returns an error" do
7
+ expect {
8
+ described_class.fetch("nope", "")
9
+ }.to raise_error(OpenURI::HTTPError)
10
+ end
11
+ end
12
+
13
+ context "when the version does not exist" do
14
+ it "returns an error" do
15
+ expect {
16
+ described_class.fetch("vagrant", "0.0.0")
17
+ }.to raise_error(OpenURI::HTTPError)
18
+ end
19
+ end
20
+
21
+ it "returns the JSON representation of the version" do
22
+ r = described_class.fetch("consul", "0.1.0")
23
+ expect(r["darwin"]).to eq(
24
+ "amd64" => "https://releases.hashicorp.com/consul/0.1.0/consul_0.1.0_darwin_amd64.zip",
25
+ )
26
+ expect(r["linux"]).to eq(
27
+ "386" => "https://releases.hashicorp.com/consul/0.1.0/consul_0.1.0_linux_386.zip",
28
+ "amd64" => "https://releases.hashicorp.com/consul/0.1.0/consul_0.1.0_linux_amd64.zip",
29
+ )
30
+ expect(r["windows"]).to eq(
31
+ "386" => "https://releases.hashicorp.com/consul/0.1.0/consul_0.1.0_windows_386.zip",
32
+ )
33
+ end
34
+ end