Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 263 lines (232 sloc) 8.522 kb
0e8d85e @nene Adopted dir structure of standard Ruby project.
nene authored
1 require 'rubygems'
2 require 'rake'
3
bde3898 @nene Replaced class unit test with rspec test.
nene authored
4 $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
5
e566a00 @nene Upgraded rake task for RSpec 2.
nene authored
6 require 'rspec'
7 require 'rspec/core/rake_task'
8 RSpec::Core::RakeTask.new(:spec) do |spec|
9 spec.rspec_opts = ["--color"]
10 spec.pattern = "spec/**/*_spec.rb"
bde3898 @nene Replaced class unit test with rspec test.
nene authored
11 end
12
74f9fb0 @nene Rake tasks for building/installing gem.
nene authored
13 desc "Build gem locally"
14 task :build do
15 system "gem build jsduck.gemspec"
16 end
17
18 desc "Install gem locally"
19 task :install => :build do
20 system "gem install --user-install jsduck"
21 end
22
a85faa4 @nene Rake task for documenting the Docs app itself.
nene authored
23 def load_sdk_vars
a5a89e0 @nene Replace sdk.sh script with sdk task in Rakefile.
nene authored
24 if File.exists?("sdk-vars.rb")
25 require "sdk-vars.rb"
26 else
27 puts "Error: sdk-vars.rb not found."
28 puts
29 puts "Please create file sdk-vars.rb and define constants SDK_DIR and OUT_DIR in it."
30 puts
31 puts "For example:"
32 puts
33 puts " SDK_DIR='/path/to/SDK'"
34 puts " OUT_DIR='/path/to/ouput/dir'"
9d90663 Update to deploy file
Nick Poulden authored
35 puts " EXT_DIR='/path/to/ext/dir'"
a5a89e0 @nene Replace sdk.sh script with sdk task in Rakefile.
nene authored
36 exit 1
37 end
a85faa4 @nene Rake task for documenting the Docs app itself.
nene authored
38 end
a5a89e0 @nene Replace sdk.sh script with sdk task in Rakefile.
nene authored
39
b414e2b @nene Refactor production export rake command.
nene authored
40 def run_jsduck(extra_options)
1acca4e @nene Auto escape arguments when Rake invokes jsduck.
nene authored
41 # Pass multiple arguments to system, so we'll take advantage of the built-in escaping
42 system(*[
43 "ruby", "bin/jsduck",
a5a89e0 @nene Replace sdk.sh script with sdk task in Rakefile.
nene authored
44 # --external=Error to ignore the Error class that Ext.Error extends.
1acca4e @nene Auto escape arguments when Rake invokes jsduck.
nene authored
45 "--external", "Error",
46 "--guides", "#{SDK_DIR}/guides",
615f84a @nene Parser-side expansion of inline examples.
nene authored
47 "--examples", "#{SDK_DIR}/extjs/doc-resources",
1f01262 @nene Add --guides-order command line option.
nene authored
48 "--guides-order", "getting,class,application,layouts,data,grid,tree,drawing,forms,components,theming,direct",
6b1ed26 @nene Move categories JSON file to ExtJS SDK repo.
nene authored
49 "--categories", "#{SDK_DIR}/extjs/doc-resources/categories.json",
1acca4e @nene Auto escape arguments when Rake invokes jsduck.
nene authored
50 "--output", "#{OUT_DIR}",
51 ].concat(extra_options))
a5a89e0 @nene Replace sdk.sh script with sdk task in Rakefile.
nene authored
52
53 # Finally copy over the images that documentation links to.
54 system "cp -r #{SDK_DIR}/extjs/doc-resources #{OUT_DIR}/doc-resources"
55 system "cp -r #{SDK_DIR}/platform/doc-resources/* #{OUT_DIR}/doc-resources"
56 end
57
a85faa4 @nene Rake task for documenting the Docs app itself.
nene authored
58 desc "Run JSDuck on ExtJS SDK"
59 task :sdk do
60 load_sdk_vars
61 run_jsduck([
aee5ac5 @nene Default to using ext-all.js.
nene authored
62 "--extjs-path", "extjs/ext-debug.js",
b414e2b @nene Refactor production export rake command.
nene authored
63 # to create symbolic links to template files instead of copying them over.
64 # Useful for development. Turn off for deployment.
65 "--template-links",
a85faa4 @nene Rake task for documenting the Docs app itself.
nene authored
66 "#{SDK_DIR}/extjs/src",
67 "#{SDK_DIR}/platform/src",
68 "#{SDK_DIR}/platform/core/src",
69 ])
70 end
71
b9c4edd @nene Use ext.js as the default extjs file.
nene authored
72 def run_jsduck_export(extra_options)
2624bac @nick IE can't deal with Docs.view.class so renamed to Docs.view.cls. Also sta...
nick authored
73 load_sdk_vars
40d02e5 @nene Add configurable footer.
nene authored
74 rev = `git rev-parse HEAD`.slice(0, 7)
ee9cf91 @nene Add --head-html and --body-html options.
nene authored
75 head_html = <<-EOHTML
76 <link rel="canonical" href="http://docs.sencha.com/ext-js/4-0/" />
77 <meta name="description" content="Ext JS 4.0 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 4">
78 EOHTML
b414e2b @nene Refactor production export rake command.
nene authored
79
9d90663 Update to deploy file
Nick Poulden authored
80 run_jsduck([
665ac3c Update Rakefile to exclude ext.js from files to delete when building
Nick Poulden authored
81 "--title", "Ext JS 4.0 API Documentation",
82 "--footer", "ExtJS 4.0 Documentation from Sencha. Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{rev}",
ee9cf91 @nene Add --head-html and --body-html options.
nene authored
83 "--head-html", head_html,
9d90663 Update to deploy file
Nick Poulden authored
84 "#{SDK_DIR}/extjs/src",
85 "#{SDK_DIR}/platform/src",
86 "#{SDK_DIR}/platform/core/src",
3e12503 @nene Refactor out common code from two rake tasks.
nene authored
87 ].concat(extra_options))
9d90663 Update to deploy file
Nick Poulden authored
88
89 end
90
62a2202 @nene Make :compress part of :export and :live_docs tasks.
nene authored
91 # Use the :export task instead
92 desc "Base task for creating export"
93 task :base_export do
9d90663 Update to deploy file
Nick Poulden authored
94 load_sdk_vars
f85f53f @nene Replace Docs.live variable with hidden div.
nene authored
95 run_jsduck_export([
ee9cf91 @nene Add --head-html and --body-html options.
nene authored
96 "--body-html", <<-EOHTML
f85f53f @nene Replace Docs.live variable with hidden div.
nene authored
97 <div id="notice-text" style="display: none">
98 Use <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a> for up to date documentation and features
99 </div>
100 EOHTML
b9c4edd @nene Use ext.js as the default extjs file.
nene authored
101 ])
3e12503 @nene Refactor out common code from two rake tasks.
nene authored
102 end
9d90663 Update to deploy file
Nick Poulden authored
103
62a2202 @nene Make :compress part of :export and :live_docs tasks.
nene authored
104 # Use the :live_docs task instead
105 desc "Base task for creating live docs"
106 task :base_live_docs do
3e12503 @nene Refactor out common code from two rake tasks.
nene authored
107 load_sdk_vars
108 run_jsduck_export([
ee9cf91 @nene Add --head-html and --body-html options.
nene authored
109 "--body-html", <<-EOHTML
b414e2b @nene Refactor production export rake command.
nene authored
110 <script type="text/javascript">
111 var _gaq = _gaq || [];
112 _gaq.push(['_setAccount', 'UA-1396058-10']);
113 _gaq.push(['_trackPageview']);
114 (function() {
115 var ga = document.createElement('script');
116 ga.type = 'text/javascript';
117 ga.async = true;
118 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
119 var s = document.getElementsByTagName('script')[0];
120 s.parentNode.insertBefore(ga, s);
121 })();
3ee957e @nene Cleanup of event tracking.
nene authored
122
123 Docs.initEventTracking = function() {
124 Docs.App.getController('Classes').addListener({
125 showClass: function(cls) {
126 _gaq.push(['_trackEvent', 'Classes', 'Show', cls]);
127 },
128 showMember: function(cls, anchor) {
07e2633 Analytics fixes
Nick Poulden authored
129 _gaq.push(['_trackEvent', 'Classes', 'Member', cls + ' - ' + anchor]);
3ee957e @nene Cleanup of event tracking.
nene authored
130 },
131 showGuide: function(guide) {
132 _gaq.push(['_trackEvent', 'Guides', 'Show', guide]);
e4300da Analytics tracking on classes and guides
Nick Poulden authored
133 }
134 });
3ee957e @nene Cleanup of event tracking.
nene authored
135 }
b414e2b @nene Refactor production export rake command.
nene authored
136 </script>
137 EOHTML
b9c4edd @nene Use ext.js as the default extjs file.
nene authored
138 ])
2624bac @nick IE can't deal with Docs.view.class so renamed to Docs.view.cls. Also sta...
nick authored
139 end
140
a85faa4 @nene Rake task for documenting the Docs app itself.
nene authored
141 desc "Run JSDuck on the Docs app itself"
142 task :docs do
143 load_sdk_vars
144 run_jsduck([
b414e2b @nene Refactor production export rake command.
nene authored
145 "--template-links",
a85faa4 @nene Rake task for documenting the Docs app itself.
nene authored
146 "#{SDK_DIR}/extjs/src",
147 "#{SDK_DIR}/platform/src",
148 "#{SDK_DIR}/platform/core/src",
149 "template/app",
150 "template/app.js",
151 ])
152 end
153
17f36ee @nene Add basic Rake task for charts.
nene authored
154 desc "Run JSDuck on ExtJS charts"
155 task :charts do
156 load_sdk_vars
157 system(*[
158 "ruby", "bin/jsduck",
5bb5d9f Updates for chart title. Make example link more generic.
Jamie Avins authored
159 "--title", "Sencha Touch Charts API Documentation",
17f36ee @nene Add basic Rake task for charts.
nene authored
160 "--external", "Error",
161 "--ignore-global",
cc85bd1 @nene Change path of charts guides in Rakefile.
nene authored
162 "--guides", "#{SDK_DIR}/charts/guides",
17f36ee @nene Add basic Rake task for charts.
nene authored
163 "--output", "#{OUT_DIR}",
164 "--no-warnings",
165 "#{SDK_DIR}/charts/src",
166 ])
167
168 system "cp -r #{SDK_DIR}/platform/doc-resources #{OUT_DIR}/doc-resources"
169 end
170
171
2f4ed3b @nene Re-compress the concatenated JavaScript too.
nene authored
172 # Compress JS/CSS file in-place
173 # Using a hackish way to access yui-compressor
174 def yui_compress(fname)
175 system "java -jar $(dirname $(which sencha))/../jsbuilder/ycompressor/ycompressor.jar -o #{fname} #{fname}"
176 end
78b51a1 @nene Make compress task merge together CSS/JS files.
nene authored
177
178 # Reads in all CSS files referenced between BEGIN CSS and END CSS markers.
179 # Deletes those input CSS files and writes out concatenated CSS to
180 # resources/css/app.css
181 # Finally replaces the CSS section with <link> to that one CSS file.
182 def combine_css(html, base_dir)
183 css_section_re = /<!-- BEGIN CSS -->.*<!-- END CSS -->/m
184 css = []
185 css_section_re.match(html)[0].each_line do |line|
186 if line =~ /<link rel="stylesheet" href="(.*?)"/
187 file = $1
188 css << IO.read(base_dir + "/" + file)
189 system("rm", base_dir + "/" + file)
190 end
191 end
192
e19e9a3 @nene Compress CSS file when exporting.
nene authored
193 fname = "#{OUT_DIR}/resources/css/app.css"
194 File.open(fname, 'w') {|f| f.write(css.join("\n")) }
2f4ed3b @nene Re-compress the concatenated JavaScript too.
nene authored
195 yui_compress(fname)
78b51a1 @nene Make compress task merge together CSS/JS files.
nene authored
196 html.sub(css_section_re, '<link rel="stylesheet" href="resources/css/app.css" type="text/css" />')
197 end
198
199 # Same thing for JavaScript, result is written to: app.js
200 def combine_js(html, base_dir)
201 js_section_re = /<!-- BEGIN JS -->.*<!-- END JS -->/m
202 js = []
203 js_section_re.match(html)[0].each_line do |line|
204 if line =~ /<script .* src="(.*)">/
205 file = $1
206 js << IO.read(base_dir + "/" + file)
665ac3c Update Rakefile to exclude ext.js from files to delete when building
Nick Poulden authored
207 if file !~ /ext\.js/
208 system("rm", base_dir + "/" + file)
209 end
78b51a1 @nene Make compress task merge together CSS/JS files.
nene authored
210 elsif line =~ /<script .*>(.*)<\/script>/
211 js << $1
212 end
213 end
214
2f4ed3b @nene Re-compress the concatenated JavaScript too.
nene authored
215 fname = "#{OUT_DIR}/app.js"
216 File.open(fname, 'w') {|f| f.write(js.join("\n")) }
217 yui_compress(fname)
f3e466a @nene Typo in generated <script> tag.
nene authored
218 html.sub(js_section_re, '<script type="text/javascript" src="app.js"></script>')
78b51a1 @nene Make compress task merge together CSS/JS files.
nene authored
219 end
220
62a2202 @nene Make :compress part of :export and :live_docs tasks.
nene authored
221 # Use :export or :live_docs tasks instead of running this separately
78b51a1 @nene Make compress task merge together CSS/JS files.
nene authored
222 desc "Compresses JavaScript and CSS files in output dir"
ef763be @nene Add Rake task for compressing JavaScript files.
nene authored
223 task :compress do
224 load_sdk_vars
225 # Create JSB3 file for Docs app
226 system("sencha", "create", "jsb", "-a", "#{OUT_DIR}/index.html", "-p", "#{OUT_DIR}/app.jsb3")
227 # Concatenate files listed in JSB3 file
228 system("sencha", "build", "-p", "#{OUT_DIR}/app.jsb3", "-d", OUT_DIR)
229 # Remove intermediate build files
230 system("rm", "#{OUT_DIR}/app.jsb3")
231 system("rm", "#{OUT_DIR}/all-classes.js")
f144b0a @nene Skip the Copyright text replacement.
nene authored
232 # Replace app.js with app-all.js
233 system("mv", "#{OUT_DIR}/app-all.js", "#{OUT_DIR}/app.js")
ef763be @nene Add Rake task for compressing JavaScript files.
nene authored
234 # Remove the entire app/ dir
235 system("rm", "-r", "#{OUT_DIR}/app")
78b51a1 @nene Make compress task merge together CSS/JS files.
nene authored
236
237 # Concatenate CSS and JS files referenced in index.html file
238 html = IO.read("#{OUT_DIR}/index.html")
239 html = combine_css(html, OUT_DIR)
240 html = combine_js(html, OUT_DIR)
241 File.open("#{OUT_DIR}/index.html", 'w') {|f| f.write(html) }
b9c4edd @nene Use ext.js as the default extjs file.
nene authored
242
243 # Clean up SASS files
244 system "rm -rf #{OUT_DIR}/resources/sass"
245 system "rm -rf #{OUT_DIR}/resources/.sass-cache"
246
247 # Empty the extjs dir, leave only the main JS file, CSS and images (for inline examples)
248 system "rm -rf #{OUT_DIR}/extjs"
249 system "mkdir -p #{OUT_DIR}/extjs/resources/css"
250 system "mkdir -p #{OUT_DIR}/extjs/resources/themes/images"
251 system "cp #{EXT_DIR}/ext-all-debug.js #{OUT_DIR}/extjs"
252 system "cp #{EXT_DIR}/resources/css/ext-all.css #{OUT_DIR}/extjs/resources/css"
253 system "cp -r #{EXT_DIR}/resources/themes/images/default #{OUT_DIR}/extjs/resources/themes/images"
ef763be @nene Add Rake task for compressing JavaScript files.
nene authored
254 end
255
62a2202 @nene Make :compress part of :export and :live_docs tasks.
nene authored
256 desc "Run JSDuck on ExtJS SDK to create release version of docs app"
257 task :export => [:base_export, :compress]
258
259 desc "Run JSDuck on ExtJS SDK to create live docs app"
260 task :live_docs => [:base_live_docs, :compress]
261
ecc67dd @nene Removed Test::Unit task from Rakefile.
nene authored
262 task :default => :spec
Something went wrong with that request. Please try again.