Class: Mxrb::Compiler::PageBundleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/compiler/page_bundle_builder.rb

Overview

Writes one page entry module per source page and an auditable support manifest. rubocop:disable Metrics

Instance Method Summary collapse

Constructor Details

#initialize(source, web_root) ⇒ PageBundleBuilder

Returns a new instance of PageBundleBuilder.



11
12
13
14
# File 'lib/mxrb/compiler/page_bundle_builder.rb', line 11

def initialize(source, web_root)
  @source = source
  @web_root = web_root
end

Instance Method Details

#buildObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mxrb/compiler/page_bundle_builder.rb', line 16

def build
  destination = File.join(@web_root, 'pages')
  FileUtils.mkdir_p(destination)
  Dir.glob(File.join(destination, '**', '*.js')).each { FileUtils.rm_f(_1) }
  bundles = @source.units_of('Forms$Page').select { web_page?(_1) }
                   .map { PageBundleCompiler.new(@source).compile(_1) }
  bundles.each { write_bundle(destination, _1) }
  layout_bundles = build_layouts
  write_manifest(bundles)
  bundles + layout_bundles
end