tufte 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +1 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +67 -0
  8. data/README.md +50 -0
  9. data/Rakefile +9 -0
  10. data/TODO +2 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/exe/tufte +4 -0
  14. data/lib/tufte/binding.rb +25 -0
  15. data/lib/tufte/cli.rb +29 -0
  16. data/lib/tufte/helpers.rb +23 -0
  17. data/lib/tufte/markdown.rb +24 -0
  18. data/lib/tufte/post.rb +42 -0
  19. data/lib/tufte/version.rb +3 -0
  20. data/lib/tufte.rb +45 -0
  21. data/scaffold/config.ru +23 -0
  22. data/scaffold/css/et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot +0 -0
  23. data/scaffold/css/et-book/et-book-bold-line-figures/et-book-bold-line-figures.svg +243 -0
  24. data/scaffold/css/et-book/et-book-bold-line-figures/et-book-bold-line-figures.ttf +0 -0
  25. data/scaffold/css/et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff +0 -0
  26. data/scaffold/css/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot +0 -0
  27. data/scaffold/css/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.svg +244 -0
  28. data/scaffold/css/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.ttf +0 -0
  29. data/scaffold/css/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff +0 -0
  30. data/scaffold/css/et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot +0 -0
  31. data/scaffold/css/et-book/et-book-roman-line-figures/et-book-roman-line-figures.svg +244 -0
  32. data/scaffold/css/et-book/et-book-roman-line-figures/et-book-roman-line-figures.ttf +0 -0
  33. data/scaffold/css/et-book/et-book-roman-line-figures/et-book-roman-line-figures.woff +0 -0
  34. data/scaffold/css/et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot +0 -0
  35. data/scaffold/css/et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.svg +244 -0
  36. data/scaffold/css/et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.ttf +0 -0
  37. data/scaffold/css/et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.woff +0 -0
  38. data/scaffold/css/et-book/et-book-semi-bold-old-style-figures/et-book-semi-bold-old-style-figures.eot +0 -0
  39. data/scaffold/css/et-book/et-book-semi-bold-old-style-figures/et-book-semi-bold-old-style-figures.svg +243 -0
  40. data/scaffold/css/et-book/et-book-semi-bold-old-style-figures/et-book-semi-bold-old-style-figures.ttf +0 -0
  41. data/scaffold/css/et-book/et-book-semi-bold-old-style-figures/et-book-semi-bold-old-style-figures.woff +0 -0
  42. data/scaffold/css/style.css +91 -0
  43. data/scaffold/css/tufte.css +274 -0
  44. data/scaffold/posts/syntax-highlight-test.yml +35 -0
  45. data/scaffold/templates/index.html.erb +31 -0
  46. data/scaffold/templates/layout.html.erb +21 -0
  47. data/scaffold/templates/post.html.erb +12 -0
  48. data/tufte.gemspec +31 -0
  49. metadata +176 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68122151e2336b4c014579ccf9ab2173b64b2645
4
+ data.tar.gz: 95981d41c07070572fb2d210f4d73ce7c7418277
5
+ SHA512:
6
+ metadata.gz: db6e50473513677d7ebbbc9903187ac86780812d1857e0180d520b147b9887467e45f1ee72547ea2ec56b53e86723007853e7b795dd88f4fd02915a0bab6c4d9
7
+ data.tar.gz: e02d0c77adc0cbc63a81230f5c39e6c14428b3c5a41d2309097dc5a70d2ff189546dd701bd1c365c560f36011a44da324430dadc81708c9f98343f4301227598
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: ruby
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ Copyright (c) 2016 Maxwell Holder
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+
21
+ This project includes fonts from et-book
22
+ (https://github.com/edwardtufte/et-book) which is distributed with the following
23
+ license:
24
+
25
+ Copyright (c) 2015 Dmitry Krasny, Bonnie Scranton, Edward Tufte.
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
28
+ this software and associated documentation files (the "Software"), to deal in
29
+ the Software without restriction, including without limitation the rights to
30
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31
+ the Software, and to permit persons to whom the Software is furnished to do so,
32
+ subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all
35
+ copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
39
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
40
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
41
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
42
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43
+
44
+
45
+ This project includes CSS from tufte-css
46
+ (https://github.com/edwardtufte/tufte-css) which is distributed with the
47
+ following license:
48
+
49
+ Copyright (c) 2014 Dave Liepmann
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining a copy
52
+ of this software and associated documentation files (the "Software"), to deal
53
+ in the Software without restriction, including without limitation the rights
54
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55
+ copies of the Software, and to permit persons to whom the Software is
56
+ furnished to do so, subject to the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be included in all
59
+ copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # tufte
2
+
3
+ [![Build Status](https://travis-ci.org/mxhold/tufte.svg?branch=master)](https://travis-ci.org/mxhold/tufte)
4
+
5
+ tufte is a minimal static site generator ideal for getting a blog running
6
+ quickly with:
7
+
8
+ - [tufte-css](https://github.com/edwardtufte/tufte-css) for style
9
+ - [redcarpet](https://github.com/vmg/redcarpet) for Markdown rendering
10
+ - [rouge](https://github.com/jneen/rouge) for syntax highlighting
11
+
12
+ See it in action at <https://maxwellholder.com>.
13
+
14
+ ## Getting started
15
+
16
+ You'll need [Ruby](https://www.ruby-lang.org) and [Bundler](http://bundler.io/)
17
+ installed first.
18
+
19
+ Make a new directory for your blog and `cd` to it:
20
+
21
+ mkdir blog/
22
+ cd blog/
23
+
24
+ Add a `Gemfile` for the current version of tufte (make sure to commit this along
25
+ with your `Gemfile.lock` for reproducable builds).
26
+
27
+ echo 'source "https://rubygems.org"\n\ngem "tufte", "~> 1.0"' > Gemfile
28
+ bundle install
29
+
30
+ Add binstubs so you don't have to prefix commands with `bundle exec`:
31
+
32
+ bundle binstubs tufte
33
+
34
+ Initialize a new blog and create scaffold files in the current directory:
35
+
36
+ bin/tufte init
37
+
38
+ Generate HTML pages from the templates:
39
+
40
+ bin/tufte build
41
+
42
+ Run a local server to view your blog at <http://localhost:9292> (this is a
43
+ simple wrapper around `rackup` so you can pass any options you normally use for
44
+ [Rack](https://github.com/rack/rack) such as `-p 4000` to run on port 4000):
45
+
46
+ bin/tufte serve
47
+
48
+ At this point you can edit the files in `templates/` and `posts/` to your
49
+ liking, running `bin/tufte build` after each change until you are satisfied with
50
+ your new blog.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
8
+ rescue LoadError
9
+ end
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ - Extract helpers to scaffolded file so users can add their own helpers
2
+ - Add pages/ for general static pages
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tufte"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/tufte ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "tufte"
3
+
4
+ Tufte::CLI.run(ARGV.shift)
@@ -0,0 +1,25 @@
1
+ module Tufte
2
+ module Binding
3
+ def self.new(instance_variables:, mod:)
4
+ BindingFactory.new(
5
+ instance_variables: instance_variables,
6
+ mod: mod,
7
+ ).get_binding
8
+ end
9
+
10
+ class BindingFactory
11
+ def initialize(instance_variables:, mod:)
12
+ instance_variables.each do |name, value|
13
+ instance_variable_set(name, value)
14
+ end
15
+ mod.singleton_methods.each do |name|
16
+ define_singleton_method(name, &mod.singleton_method(name))
17
+ end
18
+ end
19
+
20
+ def get_binding
21
+ binding
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/tufte/cli.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "optparse"
2
+
3
+ module Tufte
4
+ module CLI
5
+ def self.run(command)
6
+ case command
7
+ when "init"
8
+ Tufte.init
9
+ when "build"
10
+ Tufte.build
11
+ when "serve"
12
+ require "rack"
13
+ Rack::Server.start
14
+ when "version", "-v", "--version"
15
+ puts Tufte::VERSION
16
+ else
17
+ puts <<-USAGE
18
+ Usage: tufte [command]
19
+ Commands:
20
+ init Scaffold a new blog in the current directory
21
+ build Generate HTML pages based on the templates
22
+ serve Start a development server to host your files locally
23
+ version Print the current version
24
+ help Print this message
25
+ USAGE
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module Tufte
2
+ module Helpers
3
+ def self.sidenote(id, note)
4
+ <<-HTML.chomp
5
+ <label for="#{id}" class="margin-toggle sidenote-number"></label>
6
+ <input type="checkbox" id="#{id}" class="margin-toggle"/>
7
+ <span class="sidenote">
8
+ #{note}
9
+ </span>
10
+ HTML
11
+ end
12
+
13
+ def self.marginnote(id, note)
14
+ <<-HTML.chomp
15
+ <label for="#{id}" class="margin-toggle">&#8853;</label>
16
+ <input type="checkbox" id="#{id}" class="margin-toggle"/>
17
+ <span class="marginnote">
18
+ #{note}
19
+ </span>
20
+ HTML
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require "redcarpet"
2
+ require "rouge"
3
+ require "rouge/plugins/redcarpet"
4
+
5
+ module Tufte
6
+ class HTML < Redcarpet::Render::HTML
7
+ include Rouge::Plugins::Redcarpet
8
+
9
+ def self.renderer
10
+ @renderer ||= Redcarpet::Markdown.new(self, fenced_code_blocks: true)
11
+ end
12
+ end
13
+
14
+ class Markdown
15
+ def initialize(markdown, renderer: HTML.renderer)
16
+ @markdown = markdown
17
+ @renderer = renderer
18
+ end
19
+
20
+ def to_html
21
+ @renderer.render(@markdown)
22
+ end
23
+ end
24
+ end
data/lib/tufte/post.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "yaml"
2
+
3
+ module Tufte
4
+ class Post
5
+ attr_reader :title, :slug
6
+
7
+ def initialize(date:, title:, slug:, raw_body:)
8
+ @date = date
9
+ @slug = slug
10
+ @title = title
11
+ @raw_body = raw_body
12
+ end
13
+
14
+ def body
15
+ Markdown.new(@raw_body).to_html
16
+ end
17
+
18
+ def date
19
+ @date.strftime("%Y %b %-d")
20
+ end
21
+
22
+ def output_directory
23
+ File.join(@date.year.to_s, @date.month.to_s, @date.day.to_s, slug)
24
+ end
25
+
26
+ def output_filename
27
+ File.join(output_directory, "index.html")
28
+ end
29
+
30
+ def self.load(filename)
31
+ file_contents = File.read(filename)
32
+ metadata = YAML.load(file_contents)
33
+
34
+ new(
35
+ date: metadata.fetch("date"),
36
+ title: metadata.fetch("title"),
37
+ slug: File.basename(filename, ".yml"),
38
+ raw_body: file_contents.split("---\n", 3).last,
39
+ )
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Tufte
2
+ VERSION = "1.0.0"
3
+ end
data/lib/tufte.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "tufte/version"
2
+ require "tufte/binding"
3
+ require "tufte/post"
4
+ require "tufte/markdown"
5
+ require "tufte/cli"
6
+ require "tufte/helpers"
7
+ require "fileutils"
8
+ require "erb"
9
+
10
+ module Tufte
11
+ def self.render(erb, instance_variables, helpers = Helpers)
12
+ binding = Binding.new(instance_variables: instance_variables, mod: helpers)
13
+ ERB.new(erb).result(binding)
14
+ end
15
+
16
+ def self.init
17
+ scaffold_path = File.expand_path(File.join("..", "scaffold"), __dir__)
18
+ FileUtils.cp_r(File.join(scaffold_path, "."), ".")
19
+ end
20
+
21
+ def self.build
22
+ layout_template = File.read("templates/layout.html.erb")
23
+ post_template = File.read("templates/post.html.erb")
24
+ index_template = File.read("templates/index.html.erb")
25
+
26
+ posts = Dir.glob("posts/*").map do |filename|
27
+ Post.load(filename)
28
+ end
29
+
30
+ posts.each do |post|
31
+ FileUtils.mkdir_p(post.output_directory)
32
+ File.open(post.output_filename, "w") do |file|
33
+ rendered_post = render(post_template, :@post => post)
34
+ file.write(render(layout_template, :@content => rendered_post))
35
+ end
36
+ puts "Generated #{post.output_filename}"
37
+ end
38
+
39
+ File.open("index.html", "w") do |file|
40
+ rendered_index = render(index_template, :@posts => posts)
41
+ file.write(render(layout_template, :@content => rendered_index))
42
+ end
43
+ puts "Generated index.html"
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ class DirectoryIndex
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ def call(env)
7
+ index_path = File.join(
8
+ ".",
9
+ Rack::Request.new(env).path.split('/'),
10
+ "index.html"
11
+ )
12
+
13
+ if File.exists?(index_path)
14
+ [200, {"Content-Type" => "text/html"}, [File.read(index_path)]]
15
+ else
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+
21
+ use DirectoryIndex
22
+
23
+ run Rack::Directory.new(".")