Skip to content

Commit

Permalink
Merge pull request #15 from jfoley/fix_generate
Browse files Browse the repository at this point in the history
Fix deploy:generate task
  • Loading branch information
mustardamus committed Jul 9, 2013
2 parents 187803b + 97b067c commit 2913a97
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 99 deletions.
132 changes: 67 additions & 65 deletions app/jqapi.rb
@@ -1,82 +1,84 @@
require 'bundler'; Bundler.require require 'bundler'; Bundler.require


class Jqapi < Sinatra::Base module Jqapi
set :root, File.join(File.dirname(__FILE__), '..') ASSET_PATHS = [
set :views, File.join(root, 'app/views') 'app/assets/javascripts',
set :sprockets, Sprockets::Environment.new(root) 'app/assets/stylesheets',
set :precompile, [/\w+\.(?!js|css).+/, /bundle.(css|js)$/] 'app/assets/images',
set :assets_prefix, 'assets' 'vendor/assets/javascripts',
set :assets_path, File.join(root, 'public', assets_prefix) 'vendor/assets/stylesheets',

'vendor/assets/images'
asset_paths = [ ].freeze
'app/assets/javascripts',
'app/assets/stylesheets', class Server < Sinatra::Base
'app/assets/images', set :root, File.join(File.dirname(__FILE__), '..')
'vendor/assets/javascripts', set :views, File.join(root, 'app/views')
'vendor/assets/stylesheets', set :sprockets, Sprockets::Environment.new(root)
'vendor/assets/images' set :precompile, [/\w+\.(?!js|css).+/, /bundle.(css|js)$/]
] set :assets_prefix, 'assets'

set :assets_path, File.join(root, 'public', assets_prefix)
configure do
asset_paths.each do |path| configure do
sprockets.append_path(File.join(root, path)) ASSET_PATHS.each do |path|
sprockets.append_path(File.join(root, path))
end
end end
end


before do before do
content_type :json content_type :json
end end

get '/docs/categories.json' do
serve_file('docs', 'categories.json')
end


get '/docs/index.json' do get '/docs/categories.json' do
serve_file('docs', 'index.json') serve_file('docs', 'categories.json')
end end


get '/docs/versions.json' do get '/docs/index.json' do
serve_file('docs', 'versions.json') serve_file('docs', 'index.json')
end end


get '/docs/entries/*.json' do get '/docs/versions.json' do
serve_file('docs/entries', "#{params[:splat][0]}.json") serve_file('docs', 'versions.json')
end end


get 'resources/*.png' do get '/docs/entries/*.json' do
content_type 'image/png' serve_file('docs/entries', "#{params[:splat][0]}.json")
serve_file('docs/resources', "#{params[:splat][0]}.png") end
end


get 'resources/*.jpg' do get 'resources/*.png' do
content_type 'image/jpeg' content_type 'image/png'
serve_file('docs/resources', "#{params[:splat][0]}.jpg") serve_file('docs/resources', "#{params[:splat][0]}.png")
end end


get 'resources/*.gif' do get 'resources/*.jpg' do
content_type 'image/gif' content_type 'image/jpeg'
serve_file('docs/resources', "#{params[:splat][0]}.gif") serve_file('docs/resources', "#{params[:splat][0]}.jpg")
end end


get 'LICENSE' do get 'resources/*.gif' do
content_type 'text' content_type 'image/gif'
serve_file('', 'LICENSE') serve_file('docs/resources', "#{params[:splat][0]}.gif")
end end


get '/' do get 'LICENSE' do
content_type :html content_type 'text'
haml :index serve_file('', 'LICENSE')
end end

get '/' do
content_type :html
haml :index
end




private private
def serve_file(path, filename) def serve_file(path, filename)
filepath = File.join(settings.root, path, filename) filepath = File.join(settings.root, path, filename)


if File.exists?(filepath) if File.exists?(filepath)
File.open(filepath).read File.open(filepath).read
else else
404 404
end
end end
end end
end end
6 changes: 3 additions & 3 deletions config.ru
@@ -1,9 +1,9 @@
require "#{File.dirname(__FILE__)}/app/jqapi.rb" require "#{File.dirname(__FILE__)}/app/jqapi.rb"


map '/assets' do map '/assets' do
run Jqapi.sprockets run Jqapi::Server.sprockets
end end


map '/' do map '/' do
run Jqapi run Jqapi::Server
end end
38 changes: 13 additions & 25 deletions tasks/deploy.thor
@@ -1,31 +1,18 @@
require 'bundler'
Bundler.require

class Deploy < Thor class Deploy < Thor
desc 'generate', 'copys all documentation files and the framework, minifies css and js' desc 'generate', 'copys all documentation files and the framework, minifies css and js'

def generate def generate
sprockets = Sprockets::Environment.new('') sprockets = Sprockets::Environment.new('')
deploy_path = 'public' deploy_path = 'public'
assets_path = "#{deploy_path}/assets" assets_path = "#{deploy_path}/assets"


asset_paths = [ # todo: move that to a seperate file, dev server is unsing this too Jqapi::ASSET_PATHS.each do |path|
'app/assets/javascripts', sprockets.append_path(path)
'app/assets/stylesheets',
'app/assets/images',
'vendor/assets/javascripts',
'vendor/assets/stylesheets',
'vendor/assets/images'
]

configure do
asset_paths.each do |path|
sprockets.append_path(path)
end
end end


unless File.directory?(deploy_path) unless File.directory?(deploy_path)
Dir.mkdir(deploy_path) Dir.mkdir(deploy_path)
Dir.mkdir(assets_path) Dir.mkdir(assets_path)
end end


sprockets.find_asset('bundle.css').write_to "#{assets_path}/bundle.css" sprockets.find_asset('bundle.css').write_to "#{assets_path}/bundle.css"
Expand All @@ -35,21 +22,20 @@ class Deploy < Thor
puts "Generated (and minified) bundle.js" puts "Generated (and minified) bundle.js"


sprockets.find_asset('jquery.js').write_to "#{assets_path}/jquery.js" sprockets.find_asset('jquery.js').write_to "#{assets_path}/jquery.js"
puts "Keep a copy of jquery.js for offline demos" puts "Keep a copy of jquery.js for offline demos"


FileUtils.rm_rf "#{deploy_path}/docs" FileUtils.rm_rf "#{deploy_path}/docs"
FileUtils.cp_r 'docs', "#{deploy_path}/" FileUtils.cp_r 'docs', "#{deploy_path}/"
puts 'Copied docs directory' puts 'Copied docs directory'


FileUtils.rm_rf "#{deploy_path}/resources" FileUtils.rm_rf "#{deploy_path}/resources"
FileUtils.mv "#{deploy_path}/docs/resources", "#{deploy_path}/resources" FileUtils.mv "#{deploy_path}/docs/resources", "#{deploy_path}/resources"
puts 'Copied resources directory' # you like to juggle? puts 'Copied resources directory' # you like to juggle?


%x[cp -r app/assets/images/** #{assets_path}/] %x[cp -r app/assets/images/** #{assets_path}/]
#%x[cp -r vendor/assets/images/** #{assets_path}/]
puts 'Copied images' puts 'Copied images'


index_haml = File.read("app/views/index.haml") index_haml = File.read("app/views/index.haml")
index_markup = Haml::Engine.new(index_haml).render index_markup = Haml::Engine.new(index_haml).render


File.open("#{deploy_path}/index.html", 'w').write(index_markup) File.open("#{deploy_path}/index.html", 'w').write(index_markup)
Expand All @@ -59,21 +45,23 @@ class Deploy < Thor
puts "Copied License File" puts "Copied License File"


FileUtils.cp 'README.md', "#{deploy_path}/" FileUtils.cp 'README.md', "#{deploy_path}/"
puts "Copied Readme File" puts "Copied Readme File"
end end


desc 'pack', 'creates a .zip of the standalone version, saved to public/' desc 'pack', 'creates a .zip of the standalone version, saved to public/'

def pack def pack
FileUtils.rm_f 'public/jqapi.zip' FileUtils.rm_f 'public/jqapi.zip'
%x[cd public/ && zip -r jqapi.zip .] %x[cd public/ && zip -r jqapi.zip .]
puts "Created public/jqapi.zip" puts "Created public/jqapi.zip"
end end


desc 'air', 'builds a AIR application wrapper, saved to public/' desc 'air', 'builds a AIR application wrapper, saved to public/'

def air def air
puts "Build AIR wrapper..." puts "Build AIR wrapper..."
puts "Cert password: " puts "Cert password: "
%x[adt -package -storetype pkcs12 -keystore air/jqapi.cert -target air public/jqapi.air air/application.xml -C ./ public/assets public/docs public/resources public/index.html public/LICENSE app/assets/images air/loader.html] %x[adt -package -storetype pkcs12 -keystore air/jqapi.cert -target air public/jqapi.air air/application.xml -C ./ public/assets public/docs public/resources public/index.html public/LICENSE app/assets/images air/loader.html]
puts "Done." puts "Done."
end end
end end
7 changes: 1 addition & 6 deletions tasks/documentation.thor
@@ -1,8 +1,3 @@
require 'bundler'
Bundler.require

ROOT_DIR = File.join(File.dirname(__FILE__), '..')

class Docs < Thor class Docs < Thor
desc 'download', 'pull the official documentation from github' desc 'download', 'pull the official documentation from github'
def download def download
Expand Down Expand Up @@ -292,4 +287,4 @@ class Docs < Thor


puts 'Generated index.json' puts 'Generated index.json'
end end
end end
9 changes: 9 additions & 0 deletions tasks/requires.thor
@@ -0,0 +1,9 @@
# HORRIBLE HACK ALERT
# This file is loaded and parsed every time thor is invoked
# meaning all other .thor files are implicitly dependent on it.
# Gross, but it works.

ROOT_DIR = File.join(File.dirname(__FILE__), '..')
$LOAD_PATH.unshift(File.join(ROOT_DIR, 'app'))

require 'jqapi'

0 comments on commit 2913a97

Please sign in to comment.