class Khaleesi::CLI::Construction
Attributes
directory_name[R]
Public Class Methods
desc()
click to toggle source
# File lib/khaleesi/cli.rb, line 177 def self.desc 'create a site directory with whole structure at present working directory(pwd)' end
doc() { |'usage: khaleesi construction <directory_name>'| ... }
click to toggle source
# File lib/khaleesi/cli.rb, line 181 def self.doc return enum_for(:doc) unless block_given? yield 'usage: khaleesi construction <directory_name>' yield '' yield '<directory_name> specify a directory name of site' end
new(opts={})
click to toggle source
# File lib/khaleesi/cli.rb, line 203 def initialize(opts={}) @directory_name = opts[:directory_name] end
parse(argv)
click to toggle source
# File lib/khaleesi/cli.rb, line 189 def self.parse(argv) opts = {:directory_name => nil} until argv.empty? opts[:directory_name] = argv.shift end puts 'unspecific directory name' unless opts[:directory_name] new(opts) end
Public Instance Methods
run()
click to toggle source
# File lib/khaleesi/cli.rb, line 207 def run return unless @directory_name root_dir = "#{Dir.pwd}/#{@directory_name}" gen_site = "#{root_dir}/gen_site" execute_script = create_file_p(root_dir, @directory_name, '') open(execute_script, 'w') do |f| f.puts '#!/bin/bash' f.puts '' f.puts "src_dir=#{root_dir}" f.puts "dest_dir=#{gen_site}" f.puts 'line_numbers="false"' f.puts 'css_class="highlight"' f.puts 'time_pattern="%Y-%m-%d %H:%M"' f.puts 'date_pattern="%F"' f.puts 'highlighter=""' f.puts '# highlighter="pygments"' f.puts 'toc_selection="h1,h2,h3"' f.puts '# toc_selection="h1,h2,h3[unique]"' f.puts '' f.puts 'if [[ "$1" == "generate" ]]; then' f.puts ' diff=$([ "$2" == \'diff\' ] && echo "true" || echo "false")' f.puts ' khaleesi generate --src-dir "$src_dir" --dest-dir "$dest_dir" --line-numbers $line_numbers \\' f.puts ' --css-class $css_class --time-pattern "$time_pattern" --date-pattern "$date_pattern" \\' f.puts ' --diff-plus "$diff" --highlighter "$highlighter" --toc-selection "$toc_selection"' f.puts '' f.puts 'elif [[ "$1" == "build" ]]; then' f.puts ' temperary_dest_dir=~/tmp_site' f.puts ' mkdir $temperary_dest_dir' f.puts '' f.puts ' cd $src_dir' f.puts '' f.puts ' git checkout master' f.puts '' f.puts ' khaleesi build --src-dir "$src_dir" --dest-dir "$dest_dir" --line-numbers $line_numbers \\' f.puts ' --css-class $css_class --time-pattern "$time_pattern" --date-pattern "$date_pattern" \\' f.puts ' --highlighter "$highlighter" --toc-selection "$toc_selection"' f.puts '' f.puts ' git checkout gh-pages' f.puts '' f.puts ' rsync -acv $temperary_dest_dir/ .' f.puts '' f.puts ' rm -fr $temperary_dest_dir' f.puts '' f.puts 'elif [[ "$1" == "serve" ]]; then' f.puts ' ruby -run -e httpd $dest_dir -p 9090' f.puts '' f.puts 'fi' end File.chmod(0755, execute_script) FileUtils.mkdir_p(gen_site) css_dir = "#{root_dir}/_raw/css" css_file = create_file_p(css_dir, 'site', 'css') open(css_file, 'w') do |f| f.puts '* {margin:0; padding:0;}' f.puts 'body {margin:40px auto; width:940px; line-height:1.8em;}' f.puts 'a {color:#149ad4; text-decoration:none;}' f.puts 'a:hover {text-decoration:underline;}' f.puts '.header { font-size: 18px; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid #ddd; box-shadow: 0 1px 0 rgba(255,255,255,0.5);}' f.puts '.content { font-size: 20px; padding-bottom: 10px; }' f.puts '.content .primary .post_list {' f.puts ' list-style-type: none;' f.puts '}' f.puts '.content .primary .post_list li {' f.puts ' border: 1px solid #ddd;' f.puts ' margin-bottom: 10px;' f.puts ' padding: 10px;' f.puts '}' f.puts '.content .primary .post_list li p {' f.puts ' color: #5c5855;' f.puts ' font-size: 16px;' f.puts '}' f.puts '.content .primary .post_list li span {' f.puts ' color: #60E;' f.puts ' font-size: 12px;' f.puts '}' f.puts '.content .post_title {' f.puts ' margin: 10px 0;' f.puts ' font-size: 32px;' f.puts ' text-align: center;' f.puts '}' f.puts '.footer {' f.puts ' width: 100%;' f.puts ' margin: 0 auto;' f.puts ' border-top: 2px solid #d5d5d5;' f.puts ' font-size: 13px;' f.puts ' color: #666;' f.puts ' padding-top: 10px;' f.puts ' padding-bottom: 60px;' f.puts ' line-height: 1.8em;' f.puts '}' f.puts '.footer .left {' f.puts ' float: left;' f.puts '}' f.puts '.footer .right {' f.puts ' float: right;' f.puts '}' f.puts '.footer .right div {' f.puts ' text-align: right;' f.puts '}' end FileUtils.mkdir_p("#{root_dir}/_raw/images") decorators_dir = "#{root_dir}/_decorators" decorator_file = create_file_p(decorators_dir, 'basic', 'html') open(decorator_file, 'w') do |f| f.puts '<!DOCTYPE html>' f.puts '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">' f.puts ' <head>' f.puts ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' f.puts ' <link rel="stylesheet" href="/css/site.css" type="text/css" media="screen">' f.puts ' <title>${variable:title}</title>' f.puts ' </head>' f.puts ' <body>' f.puts ' <div class="header">' f.puts ' A khaleesi demonstration site' f.puts ' </div>' f.puts ' <div class="content">' f.puts ' ${decorator:content}' f.puts ' </div>' f.puts ' <div class="footer">' f.puts ' <div class="left">' f.puts ' <div>Licensed under the <a href="http://choosealicense.com/licenses/mit/">MIT License</a></div>' f.puts ' </div>' f.puts ' <div class="right">' f.puts ' <div>A pure-ruby static site generator</div>' f.puts ' <div>Find <a href="https://github.com/vince-styling/khaleesi">khaleesi</a> in github</div>' f.puts ' </div>' f.puts ' </div>' f.puts ' </body>' f.puts '</html>' end decorator_file = create_file_p(decorators_dir, 'post', 'html') open(decorator_file, 'w') do |f| f.puts 'decorator: basic' f.puts '‡‡‡‡‡‡‡‡‡‡‡‡‡‡' f.puts '<h1 class="post_title">${variable:title}</h1>' f.puts '<div class="post-thumb">' f.puts ' ${decorator:content}' f.puts '</div>' end pages_dir = "#{root_dir}/_pages" index_file = create_file_p(pages_dir, 'index', 'html') open(index_file, 'w') do |f| f.puts 'title: Khaleesi Index' f.puts 'decorator: basic' f.puts 'slug: index.html' f.puts '‡‡‡‡‡‡‡‡‡‡‡‡‡‡' f.puts '<div class="primary">' f.puts ' <ul class="post_list">' f.puts ' #foreach ($post : $posts)' f.puts ' <li title="${post:title}">' f.puts ' <a href="${post:link}">${post:title}</a>' f.puts ' <span>(${post:createtime})</span>' f.puts ' <p>${post:description}</p>' f.puts ' </li>' f.puts ' #end' f.puts ' </ul>' f.puts '</div>' end pages_dir << '/posts' post_file = create_file_p("#{pages_dir}/2014", 'khaleesi-introduction', 'md') open(post_file, 'w') do |f| f.puts 'title: khaleesi\'s introduction' f.puts 'decorator: post' f.puts 'description: Khaleesi is a static site generator that write by ruby.' f.puts '‡‡‡‡‡‡‡‡‡‡‡‡‡‡' f.puts '' f.puts 'Khaleesi is a static site generator that write by ruby, supported markdown parser, multiple decorators inheritance, simple page programming, page including, page dataset configurable etc.' f.puts '' f.puts 'please check [this](http://khaleesi.vincestyling.com/) for more details.' end post_file = create_file_p("#{pages_dir}/2013", 'netroid-introduction', 'md') open(post_file, 'w') do |f| f.puts 'title: netroid\'s introduction' f.puts 'decorator: post' f.puts 'description: Netroid is a Http Framework for Android that based on Volley.' f.puts '‡‡‡‡‡‡‡‡‡‡‡‡‡‡' f.puts '' f.puts 'Netroid library for Android' f.puts '---------------------------' f.puts '' f.puts 'Netroid is a http library for Android that based on Volley, That purpose is make your android development easier than before, provide fast, handly, useful way to do async http operation by background thread.' f.puts '' f.puts 'please check [this](https://github.com/vince-styling/Netroid) for more details.' end puts "A sample site of Khaleesi was built in #{root_dir}." end