Skip to content

Commit

Permalink
Merge pull request #764 from mojombo/jekyll-new
Browse files Browse the repository at this point in the history
`jekyll new`: scaffold site generator
  • Loading branch information
parkr committed Mar 17, 2013
2 parents 9ae7ca0 + a15e0c8 commit e2d0697
Show file tree
Hide file tree
Showing 13 changed files with 502 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/jekyll
Expand Up @@ -30,6 +30,15 @@ def normalize_options(options)
options
end

command :new do |c|
c.syntax = 'jekyll new PATH'
c.description = 'Creates a new Jekyll site scaffold in PATH'

c.action do |args, options|
Jekyll::Commands::New.process(args)
end
end

command :build do |c|
c.syntax = 'jekyll build [options]'
c.description = 'Build your site'
Expand Down
11 changes: 11 additions & 0 deletions jekyll.gemspec
Expand Up @@ -70,6 +70,8 @@ Gem::Specification.new do |s|
lib/jekyll.rb
lib/jekyll/command.rb
lib/jekyll/commands/build.rb
lib/jekyll/commands/migrate.rb
lib/jekyll/commands/new.rb
lib/jekyll/commands/serve.rb
lib/jekyll/converter.rb
lib/jekyll/converters/identity.rb
Expand All @@ -93,6 +95,15 @@ Gem::Specification.new do |s|
lib/jekyll/tags/highlight.rb
lib/jekyll/tags/include.rb
lib/jekyll/tags/post_url.rb
lib/site_template/_config.yml
lib/site_template/_layouts/default.html
lib/site_template/_layouts/post.html
lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb
lib/site_template/css/screen.css
lib/site_template/css/syntax.css
lib/site_template/images/.gitkeep
lib/site_template/images/rss.png
lib/site_template/index.html
script/bootstrap
site/.gitignore
site/CNAME
Expand Down
46 changes: 46 additions & 0 deletions lib/jekyll/commands/new.rb
@@ -0,0 +1,46 @@
require 'erb'

module Jekyll
module Commands
class New < Command
def self.process(args)
raise ArgumentError.new('You must specify a path.') if args.empty?

new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
FileUtils.mkdir_p new_blog_path

create_sample_files new_blog_path

File.open(File.expand_path(self.initialized_post_name, new_blog_path), "w") do |f|
f.write(self.scaffold_post_content(site_template))
end
puts "New jekyll site installed in #{new_blog_path}."
end

def self.scaffold_post_content(template_site)
ERB.new(File.read(File.expand_path(scaffold_path, site_template))).result
end

# Internal: Gets the filename of the sample post to be created
#
# Returns the filename of the sample post, as a String
def self.initialized_post_name
"_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-jekyll.markdown"
end

private
def self.create_sample_files(path)
FileUtils.cp_r site_template + '/.', path
FileUtils.rm File.expand_path(scaffold_path, path)
end

def self.site_template
File.expand_path("../../site_template", File.dirname(__FILE__))
end

def self.scaffold_path
"_posts/0000-00-00-welcome-to-jekyll.markdown.erb"
end
end
end
end
2 changes: 2 additions & 0 deletions lib/site_template/_config.yml
@@ -0,0 +1,2 @@
markdown: rdiscount
pygments: true
38 changes: 38 additions & 0 deletions lib/site_template/_layouts/default.html
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>{{ page.title }}</title>
<!-- syntax highlighting CSS -->
<link rel="stylesheet" href="/css/syntax.css" type="text/css" />
<!-- Homepage CSS -->
<link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />
</head>
<body>
<div class="site">
<div class="title">
<a href="/">Your Name</a>
<a class="extra" href="/">home</a>
</div>

{{ content }}

<div class="footer">
<div class="contact">
<p>
Your Name<br />
What You Are<br />
your@email.com
</p>
</div>
<div class="contact">
<p>
<a href="http://github.com/yourusername/">github.com/yourusername</a><br />
<a href="http://twitter.com/yourusername/">twitter.com/yourusername</a><br />
</p>
</div>
</div>
</div>
<a href="http://github.com/yourusername"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub" /></a>
</body>
</html>
6 changes: 6 additions & 0 deletions lib/site_template/_layouts/post.html
@@ -0,0 +1,6 @@
---
layout: default
---
<div id="post">
{{ content }}
</div>
24 changes: 24 additions & 0 deletions lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb
@@ -0,0 +1,24 @@
---
layout: post
title: "Welcome to Jekyll!"
date: <%= Time.now.strftime('%Y-%m-%d %H:%M:%S') %>
categories: jekyll update
---

You'll find this post in your `_posts` directory - edit this post and re-build (or run with the `-w` switch) to see your changes!
To add new posts, simply add a file in the `_posts` directory that follows the convention: YYYY-MM-DD-name-of-post.ext.

Jekyll also offers powerful support for code snippets:

{% highlight ruby %}
def print_hi(name)
puts "Hi, #{name}"
end
print_hi('Tom')
#=> prints 'Hi, Tom' to STDOUT.
{% endhighlight %}

Check out the [Jekyll docs][jekyll] for more info on how to get the most out of Jekyll. File all bugs/feature requests at [Jekyll's GitHub repo][jekyll-gh].

[jekyll-gh]: https://github.com/mojombo/jekyll
[jekyll]: http://jekyllrb.com
189 changes: 189 additions & 0 deletions lib/site_template/css/screen.css
@@ -0,0 +1,189 @@
/*****************************************************************************/
/*
/* Common
/*
/*****************************************************************************/

/* Global Reset */

* {
margin: 0;
padding: 0;
}

html, body {
height: 100%;
}

body {
background-color: white;
font: 13.34px helvetica, arial, clean, sans-serif;
*font-size: small;
text-align: center;
}

h1, h2, h3, h4, h5, h6 {
font-size: 100%;
}

h1 {
margin-bottom: 1em;
}

p {
margin: 1em 0;
}

a {
color: #00a;
}

a:hover {
color: black;
}

a:visited {
color: #a0a;
}

table {
font-size: inherit;
font: 100%;
}

/*****************************************************************************/
/*
/* Home
/*
/*****************************************************************************/

ul.posts {
list-style-type: none;
margin-bottom: 2em;
}

ul.posts li {
line-height: 1.75em;
}

ul.posts span {
color: #aaa;
font-family: Monaco, "Courier New", monospace;
font-size: 80%;
}

/*****************************************************************************/
/*
/* Site
/*
/*****************************************************************************/

.site {
font-size: 110%;
text-align: justify;
width: 42em;
margin: 3em auto 2em auto;
line-height: 1.5em;
}

.title {
color: #a00;
font-weight: bold;
margin-bottom: 2em;
}

.site .title a {
color: #a00;
text-decoration: none;
}

.site .title a:hover {
color: black;
}

.site .title a.extra {
color: #aaa;
text-decoration: none;
margin-left: 1em;
}

.site .title a.extra:hover {
color: black;
}

.site .meta {
color: #aaa;
}

.site .footer {
font-size: 80%;
color: #666;
border-top: 4px solid #eee;
margin-top: 2em;
overflow: hidden;
}

.site .footer .contact {
float: left;
margin-right: 3em;
}

.site .footer .contact a {
color: #8085C1;
}

.site .footer .rss {
margin-top: 1.1em;
margin-right: -.2em;
float: right;
}

.site .footer .rss img {
border: 0;
}

/*****************************************************************************/
/*
/* Posts
/*
/*****************************************************************************/

#post {

}

/* standard */

#post pre {
border: 1px solid #ddd;
background-color: #eef;
padding: 0 .4em;
}

#post ul,
#post ol {
margin-left: 1.35em;
}

#post code {
border: 1px solid #ddd;
background-color: #eef;
font-size: 85%;
padding: 0 .2em;
}

#post pre code {
border: none;
}

/* terminal */

#post pre.terminal {
border: 1px solid black;
background-color: #333;
color: white;
}

#post pre.terminal code {
background-color: #333;
}

0 comments on commit e2d0697

Please sign in to comment.