1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

more tweaks, rdoc

This commit is contained in:
tdreyno 2009-10-06 13:56:24 -07:00
parent 7426243824
commit d40111d67e
9 changed files with 120 additions and 21 deletions

View file

@ -47,15 +47,32 @@ task :spec => :check_dependencies
task :default => :spec
require 'rake/rdoctask'
require 'sdoc'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION')
version = File.read('VERSION')
else
version = ""
end
# rdoc.template = 'direct'
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "middleman #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc "Build and publish documentation using GitHub Pages."
task :pages do
if !`git status`.include?('nothing to commit')
abort "dirty index - not publishing!"
end
Rake::Task[:rerdoc].invoke
`git checkout gh-pages`
`ls -1 | grep -v rdoc | xargs rm -rf; mv rdoc/* .; rm -rf rdoc`
`git commit -a -m "update docs"; git push origin gh-pages`
`git checkout master`
end

View file

@ -54,10 +54,30 @@ module Generators
end
# Monkey-patch to use a dynamic renderer
class Templater::Actions::File
def identical?
if exists?
return true if File.mtime(source) < File.mtime(destination)
::FileUtils.identical?(source, destination)
else
false
end
end
end
class Templater::Actions::Template
def render
::Middleman::Builder.render_file(source, destination)
end
def identical?
if ::File.exists?(destination)
return true if File.mtime(source) < File.mtime(destination)
::File.read(destination) == render
else
false
end
end
end
Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV))

View file

@ -8,9 +8,10 @@ module Generators
class NewSite < Templater::Generator
desc "Creates a new staticmatic scaffold."
first_argument :location, :required => true, :desc => "Project location"
# css_dir
# images_dir
option :css_dir, :desc => 'The path to the css files'
option :js_dir, :desc => 'The path to the javascript files'
option :images_dir, :desc => 'The path to the image files'
def destination_root
File.expand_path(location)
@ -20,12 +21,13 @@ module Generators
File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'template')
end
file :init, "init.rb"
template :init, "init.rb"
glob! :views
glob! :public
empty_directory :stylesheets, "public/stylesheets"
empty_directory :javascripts, "public/javascripts"
empty_directory :images, "public/images"
empty_directory :stylesheets, File.join("public", css_dir)
empty_directory :javascripts, File.join("public", js_dir)
empty_directory :images, File.join("public", images_dir)
end
add :setup, NewSite

View file

@ -15,8 +15,8 @@ module Middleman
set :app_file, __FILE__
set :root, Dir.pwd
set :environment, ENV['MM_ENV'] || :development
set :supported_formats, []
set :index_file, 'index.html'
set :supported_formats, ["erb"]
set :index_file, "index.html"
set :js_dir, "javascripts"
set :css_dir, "stylesheets"
set :images_dir, "images"
@ -36,6 +36,7 @@ module Middleman
disable :relative_assets
disable :markaby
disable :maruku
disable :smush_pngs
# Default build features
configure :build do

View file

@ -5,7 +5,7 @@ require 'rack/test'
module Middleman
class Builder
# The default render just requests the page over Rack and writes the response
def self.render_file(source, destination)
def self.render_file(source, destination)
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
browser.get(request_path)

View file

@ -1,17 +1,14 @@
class Middleman::Base
alias_method :pre_cache_buster_asset_url, :asset_url
helpers do
alias_method :pre_cache_buster_asset_url, :asset_url
def asset_url(path, prefix="")
path = pre_cache_buster_asset_url(path, prefix)
if path.include?("://")
path
http_path = pre_cache_buster_asset_url(path, prefix)
if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
http_path
else
real_path = File.join(options.public, path)
if File.readable?(real_path)
path << "?" + File.mtime(real_path).strftime("%s")
else
$stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
end
real_path = File.join(self.class.environment == "build" ? options.build_dir : options.public, prefix, path)
http_path << "?" + File.mtime(real_path).strftime("%s") if File.readable?(real_path)
http_path
end
end
end

View file

@ -72,7 +72,7 @@ module Middleman
static_version = options.public + request.path_info
send_file(static_version) if File.exists? static_version
location_of_sass_file = options.environment == "build" ? "build" : "public"
location_of_sass_file = options.environment == "build" ? File.join(options.build_dir, options.css_dir) : "public"
css_filename = File.join(Dir.pwd, location_of_sass_file) + request.path_info
sass(path.to_sym, Compass.sass_engine_options.merge({ :css_filename => css_filename }))
rescue Exception => e

View file

@ -0,0 +1,58 @@
require 'json'
require 'open-uri'
begin
require 'httpclient'
rescue LoadError
puts "httpclient not available. Install it with: gem install httpclient"
end
module Middleman
module SmushPngs
def self.included(base)
base.supported_formats << "png"
end
def render_path(file)
if File.extname(file) == ".png"
file = File.join(options.public, file)
optimized = optimized_image_data_for(file)
begin
raise "Error: got larger" if size(file) < optimized.size
raise "Error: empty file downloaded" if optimized.size < 20
optimized
rescue
File.read(file)
end
else
super
end
end
protected
def size(file)
File.exist?(file) ? File.size(file) : 0
end
def optimized_image_data_for(file)
# I leave these urls here, just in case it stops working again...
# url = "http://smush.it/ws.php" # original, redirects to somewhere else..
url = 'http://ws1.adq.ac4.yahoo.com/ysmush.it/ws.php'
# url = "http://developer.yahoo.com/yslow/smushit/ws.php" # official but does not work
# url = "http://smushit.com/ysmush.it/ws.php" # used at the new page but does not hande uploads
# url = "http://smushit.eperf.vip.ac4.yahoo.com/ysmush.it/ws.php" # used at the new page but does not hande uploads
response = HTTPClient.post url, { 'files[]' => File.new(file) }
response = JSON.parse(response.body.content)
raise "smush.it: #{response['error']}" if response['error']
image_url = response['dest']
raise "no dest path found" unless image_url
open(image_url) { |source| source.read() }
end
end
class Base
include Middleman::SmushPngs
end
end

View file

@ -1,3 +1,7 @@
<% if css_dir %>set :css_dir, "<%= css_dir -%>"<% end %>
<% if js_dir %>set :js_dir, "<%= js_dir -%>"<% end %>
<% if images_dir %>set :images_dir, "<%= images_dir -%>"<% end %>
# Helpers
helpers do
end