Class: Hashup::Generator
- Inherits:
-
Thor
- Object
- Thor
- Hashup::Generator
- Includes:
- Thor::Actions
- Defined in:
- lib/hashup/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #compile(file) ⇒ Object
- #deploy ⇒ Object
- #draft(doc) ⇒ Object
- #page ⇒ Object
- #post ⇒ Object
- #preview ⇒ Object
- #setup(mysite) ⇒ Object
Class Method Details
.source_root ⇒ Object
7 8 9 |
# File 'lib/hashup/generator.rb', line 7 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#compile(file) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/hashup/generator.rb', line 23 def compile(file) fragment = Markascend.compile (File.open(file, "r").read) File.open("#{File.basename(file, ".ma")}.html", "w+") do |f| f.write(fragment) end puts "#{file} compiled" end |
#deploy ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hashup/generator.rb', line 78 def deploy site = Hashup::Site.new @configs = site.configs Dir.chdir "#{@configs["output_dir"]}" do system "git add . -f" puts "commiting site, updated at #{Time.now.utc}" = "Site updated at #{Time.now.utc}" system "git commit -m \"#{}\"" system "git push origin master --force" end end |
#draft(doc) ⇒ Object
91 92 |
# File 'lib/hashup/generator.rb', line 91 def draft(doc) end |
#page ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hashup/generator.rb', line 63 def page name = ask("the name of the page: ") description = ask("description: ").chomp! create_file(File.join("#{@configs["content_dir"]}", "#{@configs["pages_folder"]}", "#{name}.ma")) do <<META --- title: #{name} date: #{Time.new.to_s} description: #{description} --- META end if name end |
#post ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hashup/generator.rb', line 46 def post title = ask("the title of this post: ") = ask("tags(seperated by comma or space): ").strip().split(/\s|,/).to_s.gsub(/"/,"") site = Hashup::Site.new @configs = site.configs create_file(File.join("#{@configs["content_dir"]}", "#{@configs["output_dir"]}", "#{title.gsub(/\s/, "_")}.ma")) do <<META --- title: #{title} tags: #{} date: #{Time.new.to_s} --- META end if title end |
#preview ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hashup/generator.rb', line 32 def preview if root? empty_directory("output") site = Hashup::Site.new site.generate @configs = site.configs directory("#{File.dirname(__FILE__)}/templates/#{@configs["template_dir"]}/static", "#{@configs["output_dir"]}/static", :verbose => false) run_server else puts "not in the root" end end |
#setup(mysite) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/hashup/generator.rb', line 12 def setup(mysite) return if root? puts "setup #{mysite}..." directory("#{File.dirname(__FILE__)}/templates/", mysite, :exclude_pattern => /themes|contents/) %w[contents themes].each do |item| empty_directory(item) directory("#{File.dirname(__FILE__)}/templates/#{item}", "#{mysite}/#{item}", :verbose => false) end end |