class RequireJS::Exec::Render

The ‘Render RequireJS` executable.

Attributes

default_syntax[R]

Public Class Methods

new(args) click to toggle source

@param args [Array<String>] The command-line arguments

Calls superclass method RequireJS::Exec::Genetic::new
# File lib/requirejs.rb, line 80
def initialize(args)
        super
        @default_syntax = :requirejs
end

Protected Instance Methods

process_result() click to toggle source

Processes the options set by the command-line arguments, and runs the RequireJS compiler appropriately.

Calls superclass method RequireJS::Exec::Genetic#process_result
# File lib/requirejs.rb, line 111
def process_result
        # require 'requirejs'
        super
        # @options[:params][:filename] = @options[:filename]

        begin
                input = @options[:input]
                output = @options[:output]
                document = ''
                File.open(input,'r') do |script|
                        script.each_line do |line|
                                requirejs = /RequireJS\(['|"|`](.*)['|"|`]\)(.*)/.match(line)
                                if ( requirejs )
                                        include = File.join(File.dirname(input), requirejs[1])
                                        document += File.read(include)
                                else
                                        document += line
                                end
                        end
                end
                if (@options[:engine] == 'compress')
                        require 'uglifier'
                        document = Uglifier.compile(document)
                end
                input.close() if input.is_a?(File)
                output.write(document)
                output.close() if output.is_a? File
        end
end
set_opts(opts) click to toggle source

Tells optparse how to parse the arguments.

@param opts [OptionParser]

# File lib/requirejs.rb, line 91
                        def set_opts(opts)
                                opts.banner = <<END
Usage: requirejs [options] [INPUT] [OUTPUT]

Description:
Parsing javascript for RequireJS() function and adding to script

Options:
END

                                if @default_syntax == :requirejs
                                        opts.on('--compress',
                                                                        'Use the Uglify validation and compression.') do
                                                @options[:engine] = 'compress'
                                        end
                                end
                        end