Newer
Older
require 'rubygems'
require 'rake'
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ["--color"]
spec.pattern = "spec/**/*_spec.rb"
desc "Build gem locally"
task :build do
system "gem build jsduck.gemspec"
end
desc "Install gem locally"
task :install => :build do
system "gem install --user-install jsduck"
end
if File.exists?("sdk-vars.rb")
require "sdk-vars.rb"
else
puts "Error: sdk-vars.rb not found."
puts
puts "Please create file sdk-vars.rb and define constants SDK_DIR and OUT_DIR in it."
puts
puts "For example:"
puts
puts " SDK_DIR='/path/to/SDK'"
puts " OUT_DIR='/path/to/ouput/dir'"
# Pass multiple arguments to system, so we'll take advantage of the built-in escaping
system(*[
"ruby", "bin/jsduck",
# --external=Error to ignore the Error class that Ext.Error extends.
"--external", "Error",
"--guides", "#{SDK_DIR}/guides",
"--examples", "#{SDK_DIR}/extjs/doc-resources",
"--guides-order", "getting,class,application,layouts,data,grid,tree,drawing,forms,components,theming,direct",
"--categories", "#{SDK_DIR}/extjs/doc-resources/categories.json",
"--output", "#{OUT_DIR}",
].concat(extra_options))
# Finally copy over the images that documentation links to.
system "cp -r #{SDK_DIR}/extjs/doc-resources #{OUT_DIR}/doc-resources"
system "cp -r #{SDK_DIR}/platform/doc-resources/* #{OUT_DIR}/doc-resources"
end
desc "Run JSDuck on ExtJS SDK"
task :sdk do
load_sdk_vars
run_jsduck([
# to create symbolic links to template files instead of copying them over.
# Useful for development. Turn off for deployment.
"--template-links",
"#{SDK_DIR}/extjs/src",
"#{SDK_DIR}/platform/src",
"#{SDK_DIR}/platform/core/src",
])
end
def run_jsduck_export(extra_options)
Nick Poulden
committed
load_sdk_vars
head_html = <<-EOHTML
<link rel="canonical" href="http://docs.sencha.com/ext-js/4-0/" />
<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">
EOHTML
"--footer", "ExtJS 4.0.2a Documentation from Sencha. Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{rev}",
"#{SDK_DIR}/extjs/src",
"#{SDK_DIR}/platform/src",
"#{SDK_DIR}/platform/core/src",
desc "Run JSDuck on ExtJS SDK to create release version of docs app"
task :export do
<div id="notice-text" style="display: none">
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
</div>
EOHTML
desc "Run JSDuck on ExtJS SDK to create live docs app"
task :live_docs do
load_sdk_vars
run_jsduck_export([
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1396058-10']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
Docs.initEventTracking = function() {
Docs.App.getController('Classes').addListener({
showClass: function(cls) {
_gaq.push(['_trackEvent', 'Classes', 'Show', cls]);
},
showMember: function(cls, anchor) {
_gaq.push(['_trackEvent', 'Classes', 'Member', cls + ' - ' + anchor]);
},
showGuide: function(guide) {
_gaq.push(['_trackEvent', 'Guides', 'Show', guide]);
Nick Poulden
committed
end
desc "Run JSDuck on the Docs app itself"
task :docs do
load_sdk_vars
run_jsduck([
"#{SDK_DIR}/extjs/src",
"#{SDK_DIR}/platform/src",
"#{SDK_DIR}/platform/core/src",
"template/app",
"template/app.js",
])
end
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Reads in all CSS files referenced between BEGIN CSS and END CSS markers.
# Deletes those input CSS files and writes out concatenated CSS to
# resources/css/app.css
# Finally replaces the CSS section with <link> to that one CSS file.
def combine_css(html, base_dir)
css_section_re = /<!-- BEGIN CSS -->.*<!-- END CSS -->/m
css = []
css_section_re.match(html)[0].each_line do |line|
if line =~ /<link rel="stylesheet" href="(.*?)"/
file = $1
css << IO.read(base_dir + "/" + file)
system("rm", base_dir + "/" + file)
end
end
File.open("#{OUT_DIR}/resources/css/app.css", 'w') {|f| f.write(css.join("\n")) }
html.sub(css_section_re, '<link rel="stylesheet" href="resources/css/app.css" type="text/css" />')
end
# Same thing for JavaScript, result is written to: app.js
def combine_js(html, base_dir)
js_section_re = /<!-- BEGIN JS -->.*<!-- END JS -->/m
js = []
js_section_re.match(html)[0].each_line do |line|
if line =~ /<script .* src="(.*)">/
file = $1
js << IO.read(base_dir + "/" + file)
system("rm", base_dir + "/" + file)
elsif line =~ /<script .*>(.*)<\/script>/
js << $1
end
end
File.open("#{OUT_DIR}/app.js", 'w') {|f| f.write(js.join("\n")) }
html.sub(js_section_re, '<script type="text/javascript" src="app.js""></script>')
end
# Note: This should be run *after* running the :export or :live_docs task
desc "Compresses JavaScript and CSS files in output dir"
task :compress do
load_sdk_vars
# Create JSB3 file for Docs app
system("sencha", "create", "jsb", "-a", "#{OUT_DIR}/index.html", "-p", "#{OUT_DIR}/app.jsb3")
# Concatenate files listed in JSB3 file
system("sencha", "build", "-p", "#{OUT_DIR}/app.jsb3", "-d", OUT_DIR)
# Replace Copyright information in compressed file, writing new version to original app.js
copy = 'Generated by JSDuck: https:\/\/github.com\/senchalabs\/jsduck'
system("sed 's/^Copyright.*Company Name$/#{copy}/' #{OUT_DIR}/app-all.js > #{OUT_DIR}/app.js")
# Remove intermediate build files
system("rm", "#{OUT_DIR}/app.jsb3")
system("rm", "#{OUT_DIR}/all-classes.js")
system("rm", "#{OUT_DIR}/app-all.js")
# Remove the entire app/ dir
system("rm", "-r", "#{OUT_DIR}/app")
# Concatenate CSS and JS files referenced in index.html file
html = IO.read("#{OUT_DIR}/index.html")
html = combine_css(html, OUT_DIR)
html = combine_js(html, OUT_DIR)
File.open("#{OUT_DIR}/index.html", 'w') {|f| f.write(html) }
# Clean up SASS files
system "rm -rf #{OUT_DIR}/resources/sass"
system "rm -rf #{OUT_DIR}/resources/.sass-cache"
# Empty the extjs dir, leave only the main JS file, CSS and images (for inline examples)
system "rm -rf #{OUT_DIR}/extjs"
system "mkdir -p #{OUT_DIR}/extjs/resources/css"
system "mkdir -p #{OUT_DIR}/extjs/resources/themes/images"
system "cp #{EXT_DIR}/ext-all-debug.js #{OUT_DIR}/extjs"
system "cp #{EXT_DIR}/resources/css/ext-all.css #{OUT_DIR}/extjs/resources/css"
system "cp -r #{EXT_DIR}/resources/themes/images/default #{OUT_DIR}/extjs/resources/themes/images"