Class: Middleman::HashiCorpExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-hashicorp/extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ HashiCorpExtension

Returns a new instance of HashiCorpExtension.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/middleman-hashicorp/extension.rb', line 17

def initialize(app, options_hash = {}, &block)
  super

  # Grab a reference to self so we can access it deep inside blocks
  _self = self

  # Use syntax highlighting on fenced code blocks
  # This is super hacky, but middleman does not let you activate an
  # extension on "app" outside of the "configure" block.
  require "middleman-syntax"
  syntax = Proc.new { activate :syntax }
  app.configure(:development, &syntax)
  app.configure(:build, &syntax)

  # Organize assets like Rails
  app.set :css_dir,    "assets/stylesheets"
  app.set :js_dir,     "assets/javascripts"
  app.set :images_dir, "assets/images"
  app.set :fonts_dir,  "assets/fonts"

  # Make custom assets available
  assets = Proc.new { sprockets.import_asset "ie-compat.js" }
  app.configure(:development, &assets)
  app.configure(:build, &assets)

  # Override the default Markdown settings to use our customer renderer
  # and the options we want!
  app.set :markdown_engine, :redcarpet
  app.set :markdown, Middleman::HashiCorp::RedcarpetHTML::REDCARPET_OPTIONS.merge(
    renderer: Middleman::HashiCorp::RedcarpetHTML
  )

  # Do not strip /index.html from directory indexes
  app.set :strip_index_file, false

  # Set the latest version
  app.set :latest_version, options.version

  # Do the releases dance
  app.set :product_versions, _self.product_versions

  app.set :github_slug, options.github_slug
  app.set :website_root, options.website_root

  # Configure the development-specific environment
  app.configure :development do
    # Reload the browser automatically whenever files change
    require "middleman-livereload"
    activate :livereload,
      host: "0.0.0.0"
  end

  # Configure the build-specific environment
  minify_javascript = options.minify_javascript
  app.configure :build do
    # Minify CSS on build
    activate :minify_css

    if minify_javascript
      # Minify Javascript on build
      activate :minify_javascript
    end

    # Enable cache buster
    activate :asset_hash
  end
end

Instance Method Details

#product_versionsHash

Query the API to get the real product download versions.

Returns:

  • (Hash)


215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/middleman-hashicorp/extension.rb', line 215

def product_versions
  if options.releases_enabled
    Middleman::HashiCorp::Releases.fetch(options.name, options.version)
  else
    {
      "HashiOS" => {
        "amd64" => "/0.1.0_hashios_amd64.zip",
        "i386" => "/0.1.0_hashios_i386.zip",
      }
    }
  end
end