Module: QuikStart

Defined in:
lib/quik_start.rb,
lib/quik_start/version.rb

Constant Summary collapse

VERSION =
"0.0.11"

Class Method Summary collapse

Class Method Details

.analyze(to_install) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/quik_start.rb', line 111

def self.analyze(to_install)
  assets = {}
  to_install.each do |lib_name|
    if assets[lib_name] == nil
      QuikStart.install(lib_name).each do |installed|
        assets[installed] = true
      end
    end
  end
  assets
end

.asset_path(platform) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/quik_start.rb', line 85

def self.asset_path(platform)
  if platform == :rails
    '/app/assets' 
  elsif platform == :node
    '/public' 
  end
end

.check_dependencies(lib_name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/quik_start.rb', line 17

def self.check_dependencies(lib_name)
  if libraries[lib_name] != nil && libraries[lib_name][:dependencies]
    libraries[lib_name][:dependencies].each do |d|
      install(d) 
    end
  end
end

.check_listing(lib_name) ⇒ Object



13
14
15
# File 'lib/quik_start.rb', line 13

def self.check_listing(lib_name)
  puts "  --> "+lib_name.to_s + " not in QuikStart" if libraries[lib_name].nil?
end

.download_all(platform, libs) ⇒ Object



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
# File 'lib/quik_start.rb', line 37

def self.download_all(platform, libs)
  puts '  downloading...'
  to_install = []
  libs.keys.each do |l|
    lib = QuikStart.libraries[l][:development]
    to_install << lib if lib != nil
  end
  
  libs.keys.each do |l|
    lib = QuikStart.libraries[l][:package]
    to_install << lib if lib != nil
  end
  
  responses = {}
  requests = to_install.uniq
  m = Curl::Multi.new
  requests.each do |url|
    responses[url] = ""
    c = Curl::Easy.new(url) do|curl|
      curl.follow_location = true
      curl.on_body{|data| responses[url] << data; data.size }
      curl.on_success {|easy|  }
    end
    m.add(c)
  end

  m.perform do
    # puts "."
  end

  
  libs.keys.each do |l|
    file_name = QuikStart.libraries[l][:target]
    if QuikStart.libraries[l][:development]
      File.open(File.expand_path('.') + QuikStart.asset_path(platform) + file_name, 'w') do |f2|
        f2.puts responses[QuikStart.libraries[l][:development]]
      end
    else
      File.open(File.expand_path('.') + QuikStart.asset_path(platform)+ file_name, 'w') do |f2|
        f2.puts responses[QuikStart.libraries[l][:package]]
      end
      unzip(platform, File.expand_path('.') + QuikStart.asset_path(platform) + file_name)
    end
  end
  puts
  write_asset_files(platform, libs.keys)
end

.install(lib_name) ⇒ Object



7
8
9
10
11
# File 'lib/quik_start.rb', line 7

def self.install(lib_name)
  @installed = [] if @installed == nil
  resolve(lib_name) unless @installed.include?(lib_name)
  @installed
end

.librariesObject



150
151
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/quik_start.rb', line 150

def self.libraries
  {
    :backbone => { 
      :development => 'http://backbonejs.org/backbone.js', 
      :production => 'http://backbonejs.org/backbone-min.js',
      :dependencies => [:underscore, :json2],
      :target => '/javascripts/backbone.js'
    },
    :bootstrap => {
      :package => 'http://twitter.github.com/bootstrap/assets/bootstrap.zip',
      :dependencies => [:jquery],
      :extraction_method => :extract_bootstrap,
      :target => '/javascripts/bootstrap.zip'
    },
    :underscore => {
      :development => 'http://underscorejs.org/underscore.js', 
      :production => 'http://underscorejs.org/underscore-min.js',
      :target => '/javascripts/underscore.js'
    },
    :json2 => {
      :development => 'https://raw.github.com/douglascrockford/JSON-js/master/json2.js', 
      :production => 'https://raw.github.com/douglascrockford/JSON-js/master/json2.js',
      :target => '/javascripts/json2.js'
    },
    :jqueryui => {
      :production => 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js',
      :development => 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.js',
      :dependencies => [:jquery],
      :target => '/javascripts/jquery-ui.js'
    },
    :jquery => {
      :production => 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
      :development => 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js',
      :target => '/javascripts/jquery.js'
    },
    :angular => {
      :development => 'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js',
      :production => 'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js',
      :target => '/javascripts/angular.js'
    },
    :d3 => {
      :production => 'https://raw.github.com/mbostock/d3/master/d3.min.js',
      :development => 'https://raw.github.com/mbostock/d3/master/d3.js',
      :target => '/javascripts/d3.js'
    },
    :taffy => {
      :production => 'https://raw.github.com/typicaljoe/taffydb/master/taffy-min.js',
      :development => 'https://raw.github.com/typicaljoe/taffydb/master/taffy.js',
      :target => '/javascripts/taffy.js'
    },
    :wysihtml5 => {
      :development => 'https://raw.github.com/xing/wysihtml5/master/dist/wysihtml5-0.3.0.js',
      :production => 'https://raw.github.com/xing/wysihtml5/master/dist/wysihtml5-0.3.0.min.js',
      :target => '/javascripts/wysihtml5.js'
    },
    :zepto => {
      :development => 'http://zeptojs.com/zepto.js',
      :production => 'http://zeptojs.com/zepto.min.js',
      :target => '/javascripts/zepto.js'
    },
    :lunr => {
      :development => 'https://raw.github.com/olivernn/lunr.js/master/lunr.js',
      :production => 'https://raw.github.com/olivernn/lunr.js/master/lunr.min.js',
      :target => '/javascripts/lunr.js'
    },
    :augment => {
      :development => 'https://raw.github.com/olivernn/augment.js/master/augment.js',
      :production => 'https://raw.github.com/olivernn/augment.js/master/augment.min.js',
      :target => '/javascripts/augment.js'
    }
  }
end

.log_duration(start_time) ⇒ Object



32
33
34
35
# File 'lib/quik_start.rb', line 32

def self.log_duration(start_time)
  duration = Time.now - start_time
  puts "  "+duration.to_s + ' seconds'
end

.resolve(lib_name) ⇒ Object



25
26
27
28
29
30
# File 'lib/quik_start.rb', line 25

def self.resolve(lib_name)
  check_listing(lib_name)
  check_dependencies(lib_name)
  @installed << lib_name
  puts '  resolving ' + lib_name.to_s unless libraries[lib_name].nil?
end

.unzip(platform, file) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/quik_start.rb', line 93

def self.unzip(platform, file)
  Zip::ZipFile.open(file) do |zipfile|
    zipfile.each do |entry|
      if File.extname(entry.name) == '.js'
        File.open(File.expand_path('.') + QuikStart.asset_path(platform) + '/javascripts/' + File.basename(entry.name), 'w') do |f2|
          f2.puts entry.get_input_stream.read
        end
      end
      if File.extname(entry.name) == '.css'
        File.open(File.expand_path('.') + QuikStart.asset_path(platform) + '/stylesheets/' + File.basename(entry.name), 'w') do |f2|
          f2.puts entry.get_input_stream.read
        end
      end
    end
  end
  File.delete(file)
end

.write_asset_files(platform, installed = []) ⇒ Object



123
124
125
126
# File 'lib/quik_start.rb', line 123

def self.write_asset_files(platform, installed=[])
  write_css_file(platform, installed)
  write_js_file(platform, installed)
end

.write_css_file(platform, installed) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/quik_start.rb', line 128

def self.write_css_file(platform, installed)
  if platform == :rails
    puts
    if installed.include?(:bootstrap)
      puts 'puts the following in your application.css file: '
      puts ' *= require "bootstrap" '
      puts
    end
  end
end

.write_js_file(platform, installed) ⇒ Object



139
140
141
142
143
144
145
146
147
148
# File 'lib/quik_start.rb', line 139

def self.write_js_file(platform, installed)
  if platform == :rails
    puts
    puts 'puts the following in your application.js file: '
    installed.each do |i|
      puts ' //= require '+ i.to_s
    end
    puts
  end
end