Sha256: 80bbcff038333b05842807ccb567ef5c5e6ffc26b089800c51175ddd6654f85c
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true require 'mwc' module Mwc # The compile options class CompileOptions # :nodoc: EXTRA_JS_TYPE = { library_js: '--js-library', pre_js: '--pre-js', post_js: '--post-js' }.freeze OPTIONS = %i[shell source_map extra].freeze # :nodoc: def initialize(options = {}) @options = [] options.each do |name, value| handler = "add_#{name}" send(handler, value) if respond_to?(handler) end OPTIONS.each { |name| send("setup_#{name}") } output(options[:format]) end # Setup shell file # # @since 0.2.0 # @api private def setup_shell return if Mwc.config.project.shell.nil? path = Mwc.root.join(Mwc.config.project.shell) @options.push "--shell-file #{path}" end # Setup source map # # @since 0.2.0 # @api private def setup_source_map return unless Mwc.config.project.source_map @options.push '-g4 --source-map-base /' end # Setup extra options # # @since 0.2.0 # @api private def setup_extra return unless Mwc.config.project.options.any? Mwc.config.project.options.each do |name, value| @options.push "-s #{name}=#{value}" end end # Convert options to string # # @return [String] the options def to_s @options.join(' ') end # Configure extra javacript # # @since 0.2.0 # @api private %i[library_js pre_js post_js].each do |type| define_method "add_#{type}" do |items| items.each do |path| @options.push "#{EXTRA_JS_TYPE[type]} #{path}" end end end private # Configure output format # # @param foramt [String] output format # # @since 0.1.0 # @api private def output(format) @options.push "-o dist/#{Mwc.config.project.name}.#{format}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mwc-0.2.0 | lib/mwc/compile_options.rb |