public
Description: Prototype UI
Homepage: http://prototype-ui.com
Clone URL: git://github.com/xilinus/prototypeui.git
sgruhier (author)
Sun Jul 20 04:32:44 -0700 2008
commit  bd14194a011bdc60796135e583045fea5ba7eb6f
tree    978cf45382051436454133cd10968027a50a2d9a
parent  43637ab7afca0f7e43dd3818a084df5b1f2bbaf3
prototypeui / Rakefile
100644 154 lines (122 sloc) 4.678 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'rake'
require 'rake/packagetask'
require 'rbconfig'
 
PUI_NAME = 'prototype-ui'
PUI_VERSION = 'trunk'
 
PUI_DEPENDENCIES = {
  :core => nil,
  :window => [ :"util/iframe_shim.js", :"util/drag.js", :shadow ],
  :carousel => nil,
  :dock => nil,
  :shadow => :util,
  :util => nil,
  :context_menu => [ :shadow, :"util/iframe_shim.js"],
  :auto_complete => [ :shadow, :"util/iframe_shim.js"],
  :calendar => :"util/date.js"
}
 
PUI_COMPONENTS = PUI_DEPENDENCIES.keys
 
PUI_ROOT = File.expand_path(File.dirname(__FILE__))
PUI_SRC_DIR = File.join(PUI_ROOT, 'src')
PUI_DIST_DIR = File.join(PUI_ROOT, 'dist')
PUI_DIST_FILE = File.join(PUI_DIST_DIR, "#{PUI_NAME}.js")
PUI_DIST_FILE_PACKED =
                File.join(PUI_DIST_DIR, "#{PUI_NAME}.packed.js")
 
PUI_PKG_DIR = File.join(PUI_ROOT, 'pkg')
PUI_LIB_DIR = File.join(PUI_ROOT, 'lib')
PUI_DOC_DIR = File.join(PUI_ROOT, 'doc')
 
$:.unshift File.join(PUI_ROOT, 'lib')
$:.unshift File.join(PUI_ROOT, 'lib', 'coderay', 'lib')
 
def windows?
  Config::CONFIG['host'].include?('mswin')
end
 
NATURAL_DOCS = File.join(PUI_LIB_DIR, 'naturaldocs', "NaturalDocs")
NATURAL_DOCS << '.bat' if windows?
 
task :default => [ :dist, :"dist:compress", :doc ]
 
desc "Generates dist/prototype-ui.js with either all components or COMPONENTS"
task :dist do
  require 'distrib'
  FileUtils.mkdir_p PUI_DIST_DIR
  components = ENV['COMPONENTS'] ? ENV['COMPONENTS'].split(',').collect { |c| c.strip } : PUI_COMPONENTS
  
  Distrib.new(*components).write
end
 
namespace :dist do
  desc "Generate dist/[component].js with each component and its dependencies"
  task :each_component do
    require 'distrib'
    
    PUI_COMPONENTS.each do |component|
      Distrib.new(component).write(File.join(PUI_DIST_DIR, "#{component}.js"))
    end
  end
  
  desc "Preferred name for dist:each_component"
  task :each => :each_component
  
  desc "Compress all JS in dist directory with PackR"
  task :compress => [:dist, :each] do
    require 'packr/packr'
    FileUtils.rm_f Dir["#{PUI_DIST_DIR}/*.packed.js"]
    
    Dir["#{PUI_DIST_DIR}/*.js"].each do |file|
      packed_file = file.gsub(".js", ".packed.js")
      open(packed_file, 'w') do |packed|
        packed << Packr.new.pack(File.read(file), :base62 => true, :shrink_vars => true)
      end
    end
  end
end
 
Rake::PackageTask.new(PUI_NAME, PUI_VERSION) do |package|
  package.need_tar_gz = true
  package.package_dir = PUI_PKG_DIR
  package.package_files.include(
    '[A-Z]*',
    'dist/*',
    'doc/**',
    'lib/**',
    'src/**',
    'test/**',
    'themes/**'
  )
end
 
task :test => [ "dist:each_component", :test_units ]
 
require 'test/lib/jstest'
 
desc "Runs all the JavaScript unit tests and collects the results"
JavaScriptTestTask.new(:test_units) do |t|
  testcases = ENV['TESTCASES']
  tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
  browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
  
  t.mount("/lib")
  t.mount("/dist")
  t.mount("/src")
  t.mount("/test")
  
  Dir["test/unit/*_test.html"].sort.each do |test_file|
    tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
    test_filename = test_file[/.*\/(.+?)\.html/, 1]
    t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
  end
  
  %w( safari firefox ie konqueror opera ).each do |browser|
    t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
  end
end
     
 
desc "Create HTML documentation using NaturalDocs"
task :doc do
  require 'rubygems'
  require 'hpricot'
  require 'coderay'
  require 'cgi'
  
  def add_syntax_highlight(doc_files_dir)
    Dir.glob(File.join(doc_files_dir, '**', '*.html')).each do |fn|
      doc = Hpricot(File.read(fn))
      
      doc.search('.CCode').each do |node|
        source = CGI.unescapeHTML(node.innerHTML.gsub('<br />', "\n"))
        node.innerHTML = CodeRay.scan(source, :javascript).html
      end
      
      File.open(fn, 'w') { |f| f << doc }
    end
  end
  
  doc_dir = File.expand_path(ENV['PUI_DOC_DIR'] || PUI_DOC_DIR)
  mkdir_p(doc_dir)
  
  chdir(doc_dir) do
    `#{doc_dir}/config/set_version.sh` if File.exists?("#{doc_dir}/config/set_version.sh")
    
    src = File.directory?("#{doc_dir}/src") ? "#{doc_dir}/src" : PUI_SRC_DIR
    `#{NATURAL_DOCS} -r -i #{src} -o HTML . -p #{doc_dir}/config -cs 'UTF-8' -s 'Default ../styles/prototype-ui ../styles/syntax'`
    ## Update revision in doc
    add_syntax_highlight(doc_dir)
  end
end