Class: Middleman::ExtensionLessHelper::Extension

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

Constant Summary collapse

EXTENSION_MAP =
{
  '.erb' => '.html'
}

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Extension.



11
12
13
14
15
16
17
18
19
# File 'lib/middleman-extensionless-helper/extension.rb', line 11

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

  require 'digest/sha2'
  require 'fileutils'
  require 'ostruct'

  @target = create_target(options.target)
end

Instance Method Details

#after_build(builder) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/middleman-extensionless-helper/extension.rb', line 56

def after_build(builder)

  # Rename target files in the build directory as we expect.
  #  e.g. build/foo.html -> build/foo
  @target.each do |target|
    rename_build_file(target.build, target.expect)

  # SHOULD do after above the process, because a build path in a target object is referred.
    present_status(builder, target)

  end

end

#after_configurationObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/middleman-extensionless-helper/extension.rb', line 28

def after_configuration

  # Avoid applying a layout to target files.
  # #page requires a URL having a absolute path from the root that is not the source directory
  # but the web site. Besides, because it's the URL, a file name in it must be the same as MM
  # names in a build process. Hence the URL looks like "/foo.html"(the original file is "foo").
  @target.each do |target|
    app.page File.join('', target.build), :layout => false
  end

end

#before_build(builder) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/middleman-extensionless-helper/extension.rb', line 40

def before_build(builder)

  # Rename target files in the build directory for avoiding a "create" message by MM.
  #  e.g. build/foo -> build/foo.html
  # Because target files are renamed by this extension in a previous build process, MM cannot 
  # find them and assumes that they are newly created and displays a "create" message.
  # So, restore a name of target files to one which MM names in a build process.
  @target.each do |target|
    rename_build_file(target.expect, target.build)
  end

  # SHOULD do after above the process, because a build path in a target object is referred.
  inject_target_state

end