requirejs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/requirejs +11 -0
- data/lib/requirejs.rb +143 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27cf0e2b7afcbbab9771ac139f55d4a1572588be
|
4
|
+
data.tar.gz: 2a61151573941b3cf8ae4412a1622f3a438d8113
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2aa324ee9dfc4e67db7f337107fa786ac9ed298826c702c0c8ea17e63534c0ac3ee629981128a9c720cdd0d0ab1eba02e4070013bfd8687a3d38c1fde4f3d4a8
|
7
|
+
data.tar.gz: b28c4bd4fcd480ba39a4fbae47682ebde88861eea3f722645a409f44a7da72136d35621c78e75368169a8f69d3108996a0fad4fd0b6b87cb287730ebaab1a2be
|
data/bin/requirejs
ADDED
data/lib/requirejs.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
# RequireJS
|
2
|
+
#
|
3
|
+
# Details: script including files from RequireJS(.*) method
|
4
|
+
#
|
5
|
+
# Examples
|
6
|
+
#
|
7
|
+
# > requirejs.rb infile.js
|
8
|
+
# > puts minimized content for infile.js
|
9
|
+
#
|
10
|
+
# > requirejs.rb infile.js outFile.min.js
|
11
|
+
# > Write minimized content from infile.js to outFile.min.js
|
12
|
+
# Options
|
13
|
+
# --help usage info
|
14
|
+
# --compress enable line check and compression
|
15
|
+
#
|
16
|
+
require 'optparse'
|
17
|
+
require 'fileutils'
|
18
|
+
|
19
|
+
module RequireJS
|
20
|
+
module Exec
|
21
|
+
class Genetic
|
22
|
+
def initialize(args)
|
23
|
+
@args = args
|
24
|
+
@options = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Parses the command-line arguments and runs the executable.
|
28
|
+
# Calls `Kernel#exit` at the end, so it never returns.
|
29
|
+
#
|
30
|
+
# @see #parse
|
31
|
+
def parse!
|
32
|
+
begin
|
33
|
+
parse
|
34
|
+
rescue Exception => e
|
35
|
+
raise e if @options[:trace] || e.is_a?(SystemExit)
|
36
|
+
|
37
|
+
$stderr.print "#{e.class}: " unless e.class == RuntimeError
|
38
|
+
$stderr.puts "#{e.message}"
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
exit 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse
|
45
|
+
@opts = OptionParser.new(&method(:set_opts))
|
46
|
+
@opts.parse!(@args)
|
47
|
+
|
48
|
+
process_result
|
49
|
+
|
50
|
+
@options
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_result
|
54
|
+
input, output = @options[:input], @options[:output]
|
55
|
+
args = @args.dup
|
56
|
+
input ||=
|
57
|
+
begin
|
58
|
+
filename = args.shift
|
59
|
+
@options[:filename] = filename || $stdin
|
60
|
+
# open_file(args.shift, 'w') || $stdin
|
61
|
+
end
|
62
|
+
output ||=open_file(args.shift, 'w') || $stdout
|
63
|
+
@options[:input], @options[:output] = input, output
|
64
|
+
end
|
65
|
+
|
66
|
+
def open_file(filename, flag = 'r')
|
67
|
+
return if filename.nil?
|
68
|
+
flag = 'wb' if @options[:unix_newlines] && flag == 'w'
|
69
|
+
File.open(filename, flag)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# The `Render RequireJS` executable.
|
76
|
+
class Render < Genetic
|
77
|
+
attr_reader :default_syntax
|
78
|
+
|
79
|
+
# @param args [Array<String>] The command-line arguments
|
80
|
+
def initialize(args)
|
81
|
+
super
|
82
|
+
@default_syntax = :requirejs
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
# Tells optparse how to parse the arguments.
|
88
|
+
#
|
89
|
+
# @param opts [OptionParser]
|
90
|
+
|
91
|
+
def set_opts(opts)
|
92
|
+
opts.banner = <<END
|
93
|
+
Usage: requirejs [options] [INPUT] [OUTPUT]
|
94
|
+
|
95
|
+
Description:
|
96
|
+
Parsing javascript for RequireJS() function and adding to script
|
97
|
+
|
98
|
+
Options:
|
99
|
+
END
|
100
|
+
|
101
|
+
if @default_syntax == :requirejs
|
102
|
+
opts.on('--compress',
|
103
|
+
'Use the Uglify validation and compression.') do
|
104
|
+
@options[:engine] = 'compress'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Processes the options set by the command-line arguments,
|
110
|
+
# and runs the RequireJS compiler appropriately.
|
111
|
+
def process_result
|
112
|
+
# require 'requirejs'
|
113
|
+
super
|
114
|
+
# @options[:params][:filename] = @options[:filename]
|
115
|
+
|
116
|
+
begin
|
117
|
+
input = @options[:input]
|
118
|
+
output = @options[:output]
|
119
|
+
document = ''
|
120
|
+
File.open(input,'r') do |script|
|
121
|
+
script.each_line do |line|
|
122
|
+
requirejs = /RequireJS\(['|"|`](.*)['|"|`]\)(.*)/.match(line)
|
123
|
+
if ( requirejs )
|
124
|
+
include = File.join(File.dirname(input), requirejs[1])
|
125
|
+
document += File.read(include)
|
126
|
+
else
|
127
|
+
document += line
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
if (@options[:engine] == 'compress')
|
132
|
+
require 'uglifier'
|
133
|
+
document = Uglifier.compile(document)
|
134
|
+
end
|
135
|
+
input.close() if input.is_a?(File)
|
136
|
+
output.write(document)
|
137
|
+
output.close() if output.is_a? File
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: requirejs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J. Denison
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Looking for RequireJS() inside your js and including required js to document
|
14
|
+
email: jd@themondays.ca
|
15
|
+
executables:
|
16
|
+
- requirejs
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/requirejs
|
21
|
+
- lib/requirejs.rb
|
22
|
+
homepage: http://rubygems.org/gems/requirejs
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.0.14
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: RequireJS() script parser
|
46
|
+
test_files: []
|