Class: MiniYard::Generate
- Inherits:
-
Object
- Object
- MiniYard::Generate
- Defined in:
- lib/miniyard.rb
Instance Method Summary collapse
- #bootstrap_file ⇒ Object
- #bootstrap_version ⇒ Object
- #ci_path ⇒ Object
- #ensure_bootstrap_exists ⇒ Object
- #folders ⇒ Object
- #haml_render(file) ⇒ Object
- #haml_template(tpl_name) ⇒ Object
- #index_exists? ⇒ Boolean
- #index_file ⇒ Object
- #index_template ⇒ Object
-
#initialize(options) ⇒ Generate
constructor
A new instance of Generate.
- #miniyard_version ⇒ Object
- #run ⇒ Object
- #write_ci_url ⇒ Object
- #write_file(file, contents) ⇒ Object
Constructor Details
#initialize(options) ⇒ Generate
Returns a new instance of Generate.
9 10 11 12 13 |
# File 'lib/miniyard.rb', line 9 def initialize() raise 'Unable to generate MiniYard at path %s: not a directory' % path unless File.directory?([:root]) @options = @root = File.(@options[:root]) end |
Instance Method Details
#bootstrap_file ⇒ Object
71 72 73 |
# File 'lib/miniyard.rb', line 71 def bootstrap_file File.join(@root, "bootstrap.#{bootstrap_version}.min.css") end |
#bootstrap_version ⇒ Object
67 68 69 |
# File 'lib/miniyard.rb', line 67 def bootstrap_version "1.4.0" end |
#ci_path ⇒ Object
63 64 65 |
# File 'lib/miniyard.rb', line 63 def ci_path File.join(@root, @options[:name], 'ci.url') end |
#ensure_bootstrap_exists ⇒ Object
75 76 77 78 79 80 |
# File 'lib/miniyard.rb', line 75 def ensure_bootstrap_exists unless File.exist?(bootstrap_file) local_bootstrap = File.("../templates/bootstrap.#{bootstrap_version}.min.css", File.(__FILE__)) FileUtils.cp(local_bootstrap, bootstrap_file) end end |
#folders ⇒ Object
24 25 26 |
# File 'lib/miniyard.rb', line 24 def folders @folders ||= Dir[File.join(@root, '*')].sort.select{|n| File.directory?(n) }.map{|n| MiniYard::Folder.new(n) } end |
#haml_render(file) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/miniyard.rb', line 44 def haml_render(file) contents = File.read(file) Haml::Engine.new(contents, { filename: file, format: :html5, attr_wrapper: '"' }).render(self) end |
#haml_template(tpl_name) ⇒ Object
40 41 42 |
# File 'lib/miniyard.rb', line 40 def haml_template(tpl_name) File.("../templates/#{tpl_name}.haml", File.(__FILE__)) end |
#index_exists? ⇒ Boolean
36 37 38 |
# File 'lib/miniyard.rb', line 36 def index_exists? File.exist?(index_file) end |
#index_file ⇒ Object
32 33 34 |
# File 'lib/miniyard.rb', line 32 def index_file File.join(@root, 'index.html') end |
#index_template ⇒ Object
28 29 30 |
# File 'lib/miniyard.rb', line 28 def index_template haml_template("index") end |
#miniyard_version ⇒ Object
82 83 84 |
# File 'lib/miniyard.rb', line 82 def miniyard_version "v#{MiniYard::VERSION}" end |
#run ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/miniyard.rb', line 15 def run $stdout.puts('Generating miniyard at '+@root) write_ci_url if @options[:ci] FileUtils.rm(index_file) if index_exists? output = haml_render(index_template) write_file(index_file, output) ensure_bootstrap_exists end |
#write_ci_url ⇒ Object
59 60 61 |
# File 'lib/miniyard.rb', line 59 def write_ci_url File.open(ci_path, 'w'){|f| f.write(@options[:ci]) } end |
#write_file(file, contents) ⇒ Object
53 54 55 56 57 |
# File 'lib/miniyard.rb', line 53 def write_file(file, contents) File.open(file, 'w+') do |f| f.write(contents) end end |