Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (95 sloc) 3.649 kb
4c18e3c @plusjade version 0.0.1
plusjade authored
1 require "rubygems"
2 require 'rake'
3
9d7d4eb @plusjade reorganize rakefile
plusjade authored
4 SOURCE = "."
5 CONFIG = {
6 'themes' => File.join(SOURCE, "_includes", "themes"),
7 'layouts' => File.join(SOURCE, "_layouts"),
8 'posts' => File.join(SOURCE, "_posts"),
9 'post_ext' => "md"
10 }
6ee3125 @pradeep1288 adding the new_post task, with bugs fixed which were pointed out by @swa...
pradeep1288 authored
11
f52ff5a @plusjade Refactor new post rake task
plusjade authored
12 # Usage: rake post title="A Title"
9d7d4eb @plusjade reorganize rakefile
plusjade authored
13 desc "Begin a new post in #{CONFIG['posts']}"
f52ff5a @plusjade Refactor new post rake task
plusjade authored
14 task :post do
9d7d4eb @plusjade reorganize rakefile
plusjade authored
15 abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
f52ff5a @plusjade Refactor new post rake task
plusjade authored
16 title = ENV["title"] || "new-post"
17 slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
9d7d4eb @plusjade reorganize rakefile
plusjade authored
18 filename = File.join(CONFIG['posts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{CONFIG['post_ext']}")
6ee3125 @pradeep1288 adding the new_post task, with bugs fixed which were pointed out by @swa...
pradeep1288 authored
19 if File.exist?(filename)
20 abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
21 end
9d7d4eb @plusjade reorganize rakefile
plusjade authored
22
6ee3125 @pradeep1288 adding the new_post task, with bugs fixed which were pointed out by @swa...
pradeep1288 authored
23 puts "Creating new post: #{filename}"
24 open(filename, 'w') do |post|
25 post.puts "---"
26 post.puts "layout: post"
f52ff5a @plusjade Refactor new post rake task
plusjade authored
27 post.puts "title: \"#{title.gsub(/-/,' ')}\""
6ee3125 @pradeep1288 adding the new_post task, with bugs fixed which were pointed out by @swa...
pradeep1288 authored
28 post.puts "category: "
29 post.puts "tags: []"
30 post.puts "---"
f52ff5a @plusjade Refactor new post rake task
plusjade authored
31 post.puts "{% include JB/setup %}"
6ee3125 @pradeep1288 adding the new_post task, with bugs fixed which were pointed out by @swa...
pradeep1288 authored
32 end
f52ff5a @plusjade Refactor new post rake task
plusjade authored
33 end # task :post
6ee3125 @pradeep1288 adding the new_post task, with bugs fixed which were pointed out by @swa...
pradeep1288 authored
34
6d0e38b @plusjade Add rake task to create pages
plusjade authored
35 # Usage: rake page name="about.html"
36 # You can also specify a sub-directory path.
37 # If you don't specify a file extention we create an index.html at the path specified
38 desc "Create a new page."
39 task :page do
40 name = ENV["name"] || "new-page.md"
41 filename = File.join(SOURCE, "#{name}")
42 filename = File.join(filename, "index.html") if File.extname(filename) == ""
43 title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
44 if File.exist?(filename)
45 abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
46 end
47
48 mkdir_p File.dirname(filename)
49 puts "Creating new page: #{filename}"
50 open(filename, 'w') do |post|
51 post.puts "---"
52 post.puts "layout: page"
53 post.puts "title: \"#{title}\""
54 post.puts "---"
55 post.puts "{% include JB/setup %}"
56 end
57 end # task :page
58
4c18e3c @plusjade version 0.0.1
plusjade authored
59 desc "Switch between Jekyll-bootstrap themes."
9bd0dea @plusjade Use ENV variables for switch_theme
plusjade authored
60 task :switch_theme do
61 theme_name = ENV["name"].to_s
62 theme_path = File.join(CONFIG['themes'], theme_name)
61cdb7a @plusjade Themes can define configuration data
plusjade authored
63 settings_file = File.join(theme_path, "settings.yml")
64 non_layout_files = ["settings.yml"]
4c18e3c @plusjade version 0.0.1
plusjade authored
65
9bd0dea @plusjade Use ENV variables for switch_theme
plusjade authored
66 abort("rake aborted: name cannot be blank") if theme_name.empty?
67 abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path)
9d7d4eb @plusjade reorganize rakefile
plusjade authored
68 abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts'])
4c18e3c @plusjade version 0.0.1
plusjade authored
69
70 Dir.glob("#{theme_path}/*") do |filename|
61cdb7a @plusjade Themes can define configuration data
plusjade authored
71 next if non_layout_files.include?(File.basename(filename).downcase)
9bd0dea @plusjade Use ENV variables for switch_theme
plusjade authored
72 puts "Generating '#{theme_name}' layout: #{File.basename(filename)}"
4c18e3c @plusjade version 0.0.1
plusjade authored
73
9d7d4eb @plusjade reorganize rakefile
plusjade authored
74 open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page|
4c18e3c @plusjade version 0.0.1
plusjade authored
75 if File.basename(filename, ".html").downcase == "default"
76 page.puts "---"
61cdb7a @plusjade Themes can define configuration data
plusjade authored
77 page.puts File.read(settings_file) if File.exist?(settings_file)
4c18e3c @plusjade version 0.0.1
plusjade authored
78 page.puts "---"
79 else
80 page.puts "---"
81 page.puts "layout: default"
82 page.puts "---"
83 end
a1a7efa @plusjade Include 'JB/setup' in all posts and pages
plusjade authored
84 page.puts "{% include JB/setup %}"
9bd0dea @plusjade Use ENV variables for switch_theme
plusjade authored
85 page.puts "{% include themes/#{theme_name}/#{File.basename(filename)} %}"
4c18e3c @plusjade version 0.0.1
plusjade authored
86 end
87 end
88 end # task :switch_theme
89
223a9ca @studiomohawk add rake preview for development
studiomohawk authored
90 desc "Launch preview environment"
91 task :preview do
92 system "jekyll --auto --server"
9d7d4eb @plusjade reorganize rakefile
plusjade authored
93 end # task :preview
94
95 def ask(message, valid_options)
96 if valid_options
97 answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
98 else
99 answer = get_stdin(message)
100 end
101 answer
223a9ca @studiomohawk add rake preview for development
studiomohawk authored
102 end
9d7d4eb @plusjade reorganize rakefile
plusjade authored
103
104 def get_stdin(message)
105 print message
106 STDIN.gets.chomp
107 end
Something went wrong with that request. Please try again.