Module: Tufte

Defined in:
lib/tufte.rb,
lib/tufte/cli.rb,
lib/tufte/post.rb,
lib/tufte/binding.rb,
lib/tufte/helpers.rb,
lib/tufte/version.rb,
lib/tufte/markdown.rb

Defined Under Namespace

Modules: Binding, CLI, Helpers Classes: HTML, Markdown, Post

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.buildObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tufte.rb', line 21

def self.build
  layout_template = File.read("templates/layout.html.erb")
  post_template = File.read("templates/post.html.erb")
  index_template = File.read("templates/index.html.erb")

  posts = Dir.glob("posts/*").map do |filename|
    Post.load(filename)
  end

  posts.each do |post|
    FileUtils.mkdir_p(post.output_directory)
    File.open(post.output_filename, "w") do |file|
      rendered_post = render(post_template, :@post => post)
      file.write(render(layout_template, :@content => rendered_post))
    end
    puts "Generated #{post.output_filename}"
  end

  File.open("index.html", "w") do |file|
    rendered_index = render(index_template, :@posts => posts)
    file.write(render(layout_template, :@content => rendered_index))
  end
  puts "Generated index.html"
end

.initObject



16
17
18
19
# File 'lib/tufte.rb', line 16

def self.init
  scaffold_path = File.expand_path(File.join("..", "scaffold"), __dir__)
  FileUtils.cp_r(File.join(scaffold_path, "."), ".")
end

.render(erb, instance_variables, helpers = Helpers) ⇒ Object



11
12
13
14
# File 'lib/tufte.rb', line 11

def self.render(erb, instance_variables, helpers = Helpers)
  binding = Binding.new(instance_variables: instance_variables, mod: helpers)
  ERB.new(erb).result(binding)
end