Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc committed Feb 6, 2011
1 parent be0dff4 commit efa672d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
29 changes: 14 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
# Defs
# ---------------------------------------------------------------------------

# HTML subdir
# HTML and templates subdirectories
HTML_DIR = "html"
TEMPLATE_DIR = "templates"

# Name of the generated index file.
INDEX_HTML = File.join(HTML_DIR, "index.html")

# How many columns to generate in the index file.
INDEX_COLUMNS = 3

# HTML templates
CHEAT_SHEET_HTML_TEMPLATE = File.join(TEMPLATE_DIR, "cheat-sheet.html.erb")
INDEX_HTML_TEMPLATE = File.join(TEMPLATE_DIR, "index.html.erb")
README_HTML_TEMPLATE = File.join(TEMPLATE_DIR, 'README.html.erb')

# How many columns to generate in the index file.
INDEX_COLUMNS = 3

# The minimum number of entries (cheat sheets) for columnar index output.
# Below this number, and we don't generate columns.
INDEX_COLUMN_THRESHOLD = INDEX_COLUMNS * 3
Expand Down Expand Up @@ -58,7 +58,7 @@ file INDEX_HTML => INDEX_DEPS do |t|
end

file README_HTML => ['README.md', README_HTML_TEMPLATE] do |t|
make_html_from_md(SourceFile.new('README.md'),
make_html_from_md(CheatSheetSource.new('README.md'),
README_HTML,
README_HTML_TEMPLATE)
end
Expand All @@ -80,7 +80,7 @@ end

MD_HTML_DEPS = [html_to_md, CHEAT_SHEET_HTML_TEMPLATE, 'Rakefile']
rule /^html\/.*\.html$/ => MD_HTML_DEPS do |t|
make_html_from_md(SourceFile.new(t.source),
make_html_from_md(CheatSheetSource.new(t.source),
t.name,
CHEAT_SHEET_HTML_TEMPLATE)
end
Expand All @@ -94,7 +94,7 @@ require 'kramdown'
require 'erb'

# Contains meta-information about a Markdown cheat sheet.
class SourceFile
class CheatSheetSource
attr_accessor :file

def initialize(md_file)
Expand Down Expand Up @@ -148,6 +148,8 @@ class SourceFile
end
end

# Behaves more or less like a readonly hash. Allows h.a, as well as h[a],
# for accessing values.
class CallableHash
def initialize(h)
@hash = h
Expand All @@ -166,8 +168,8 @@ class CallableHash
end


# Map the MD_FILES into SourceFile objects.
MD_SOURCES = MD_FILES.to_a.map{|m| SourceFile.new(m)}
# Map the MD_FILES into CheatSheetSource objects.
MD_SOURCES = MD_FILES.to_a.map{|m| CheatSheetSource.new(m)}

$template_cache = {}
def load_template(name)
Expand Down Expand Up @@ -195,9 +197,6 @@ def make_html_from_md(source, target, template_name, title = nil)
end
end

def make_readme
end

def make_index

# Sort the list of sources by title.
Expand All @@ -215,9 +214,9 @@ def make_index
# safe_mode = 0 (default)
# trim_mode = '>' (suppress newlines)
erb = ERB.new(template(INDEX_HTML_TEMPLATE), 0, '>')
data = CallableHash.new({:sources => sources,
:div_class => div_class,
:title => 'Cheat Sheets'})
data = CallableHash.new(:sources => sources,
:div_class => div_class,
:title => 'Cheat Sheets')

puts("Generating #{INDEX_HTML} (via #{INDEX_HTML_TEMPLATE})")
File.open(INDEX_HTML, 'w').write(erb.result(data.get_binding))
Expand Down
4 changes: 4 additions & 0 deletions html/rake.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ <h3 id="computing-one-or-more-dependencies">Computing one or more dependencies</
end
</code></pre>

<h2 id="martin-fowlers-rake-article">Martin Fowler&rsquo;s Rake Article</h2>

<p><a href="http://martinfowler.com/articles/rake.html">http://martinfowler.com/articles/rake.html</a></p>

</div> <!-- content -->

<script type="text/javascript">
Expand Down
4 changes: 4 additions & 0 deletions rake.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ For readability, the `Proc` can be factored into a function:
rule /^html\/.*\.html$/ => [html_to_md, CHEAT_SHEET_TEMPLATE] do |t|
markdown(t.source, t.name)
end

## Martin Fowler's Rake Article

<http://martinfowler.com/articles/rake.html>

0 comments on commit efa672d

Please sign in to comment.