Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created June 14, 2011 06:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/1024417 to your computer and use it in GitHub Desktop.
Save hitode909/1024417 to your computer and use it in GitHub Desktop.
HTMLとよく使うJSのテンプレート
create project foo
builder.rb foo
run server
python -m SimpleHTTPServer 3001
setup
bundle install
run guard
bundle xec guard
$ ->
alert 1
body {
color: red;
}
#! /usr/bin/env ruby
require 'fileutils'
require 'erb'
include ERB::Util
def self_file
if File.symlink?(__FILE__)
require 'pathname'
Pathname.new(__FILE__).realpath
else
__FILE__
end
end
def process_file(path)
ERB.new(open(path).read, nil, '-').result(binding)
end
$application_name = ARGV.shift
raise "USAGE: #{$0} $application_name" unless $application_name
Dir.mkdir $application_name
open(File.join($application_name, "index.html"), "w"){ |f|
f.write process_file(File.join(File.dirname(self_file), "index.erb"))
}
Dir.glob(File.dirname(self_file) + "/statics/*").each{ |file|
FileUtils.cp(file, File.join($application_name, File.basename(file)))
}
['less', 'coffee', ].each{ |type|
FileUtils.cp(File.join(File.dirname(self_file), "a.#{type}"), File.join($application_name, "#{$application_name}.#{type}"))
}
system "cat #{ File.dirname(self_file) }/README"
source 'https://rubygems.org'
gem 'guard'
gem 'guard-less'
gem 'guard-coffeescript'
gem 'growl_notify'
notification :growl
guard 'less', :all_on_start => true, :all_after_change => true do
watch(%r{^.+\.less$})
end
guard 'coffeescript', :all_on_start => true do
watch(%r{^.+\.coffee$})
end
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title><%=h $application_name %></title>
<script language="javascript" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script language="javascript" type="text/javascript" src="<%=h $application_name %>.js"></script>
<link rel="stylesheet" type="text/css" href="<%=h $application_name %>.css" />
</head>
<body>
<h1>It works!</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment