lithograph 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +20 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/lithograph.rb +105 -0
- data/lib/lithograph/publishers.rb +58 -0
- data/lib/lithograph/version.rb +3 -0
- data/lithograph.gemspec +27 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dfb41b87ae38556a302e209035c2a99fe2989b84
|
4
|
+
data.tar.gz: 082e969aee4807c59da1e286b7435f4eac4058b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 527a4f6e4ea98cb3fd1b1aba9e66a3ae0b64edf4a6e61ef73eb54a9c05a8ac189e591b28987f37eed8e72805ea7aedfe116f2f2d873031ebe74cb9ec9f339d98
|
7
|
+
data.tar.gz: f72e597ed6a7b58e58f1c4051669fa9cb77c101a3251d6df8819965ad9aab48b1074bb3df2d6d44e9088c412bc9ef7a25b1b6fd08bb2d1225ca7e0f5553c0913
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Lithograph
|
2
|
+
|
3
|
+
Lithograph is a small static site generator in Ruby.
|
4
|
+
|
5
|
+
## A static API example
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'lithograph'
|
9
|
+
|
10
|
+
site = Lithograph::Site.new
|
11
|
+
site.publisher :s3
|
12
|
+
|
13
|
+
site.route "/time.json" do
|
14
|
+
json time: Time.now
|
15
|
+
end
|
16
|
+
|
17
|
+
site.publish!
|
18
|
+
```
|
19
|
+
|
20
|
+
## A static API example
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lithograph"
|
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
data/lib/lithograph.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require "lithograph/version"
|
2
|
+
require "lithograph/publishers"
|
3
|
+
|
4
|
+
module Lithograph
|
5
|
+
|
6
|
+
class Site
|
7
|
+
|
8
|
+
PUBLISHERS = {
|
9
|
+
:test => Lithograph::Publishers::TestPublisher,
|
10
|
+
:s3 => Lithograph::Publishers::S3Publisher
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_accessor :routes,
|
14
|
+
:publishers,
|
15
|
+
:templates,
|
16
|
+
:layout
|
17
|
+
|
18
|
+
def initialize options = {}
|
19
|
+
@routes = {}
|
20
|
+
@templates = {}
|
21
|
+
@publishers = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def route route, options = {}, &block
|
25
|
+
@routes[route] = Route.new route, self, options, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def template name, &block
|
29
|
+
@templates[name] = Template.new &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def layout(&block)
|
33
|
+
if block
|
34
|
+
@layout = Template.new(&block)
|
35
|
+
else
|
36
|
+
@layout
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def publisher type, options = {}
|
41
|
+
publisher = PUBLISHERS[type.to_sym].new(options)
|
42
|
+
@publishers << publisher
|
43
|
+
publisher
|
44
|
+
end
|
45
|
+
|
46
|
+
def publish!
|
47
|
+
@routes.values.each do |route|
|
48
|
+
@publishers.each do |publisher|
|
49
|
+
publisher.write_path route.route, route.render
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Route
|
56
|
+
|
57
|
+
attr_reader :route
|
58
|
+
|
59
|
+
def initialize route, site, options = {}, &block
|
60
|
+
@route = route
|
61
|
+
@site = site
|
62
|
+
@options = options
|
63
|
+
@block = block
|
64
|
+
end
|
65
|
+
|
66
|
+
def render options = {}
|
67
|
+
instance_exec @options.merge(options), &@block
|
68
|
+
end
|
69
|
+
|
70
|
+
def json content
|
71
|
+
content.to_json
|
72
|
+
end
|
73
|
+
|
74
|
+
def template name, locals
|
75
|
+
html_template = @site.templates[name.to_sym]
|
76
|
+
if @site.layout
|
77
|
+
content = html_template.partial(locals)
|
78
|
+
content = @site.layout.render(locals.merge(content: content))
|
79
|
+
else
|
80
|
+
content = temp.render(locals)
|
81
|
+
end
|
82
|
+
content
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Template
|
87
|
+
def initialize &block
|
88
|
+
@block = block
|
89
|
+
end
|
90
|
+
|
91
|
+
def render locals = {}
|
92
|
+
@builder = Nokogiri::HTML::Builder.new
|
93
|
+
@block.call(@builder, locals)
|
94
|
+
@builder.to_html
|
95
|
+
end
|
96
|
+
|
97
|
+
def partial locals
|
98
|
+
@fragment = Nokogiri::HTML.fragment('')
|
99
|
+
@builder = Nokogiri::HTML::Builder.with(@fragment)
|
100
|
+
@block.call(@builder, locals)
|
101
|
+
@fragment
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Lithograph
|
2
|
+
module Publishers
|
3
|
+
|
4
|
+
class TestPublisher
|
5
|
+
|
6
|
+
attr_reader :content
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@content = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def write_path(path, body)
|
13
|
+
@content[path] = body
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class S3Publisher
|
19
|
+
|
20
|
+
DEFAULT_OPTIONS = {
|
21
|
+
region: 'us-west-1'
|
22
|
+
}
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
|
26
|
+
options = DEFAULT_OPTIONS.merge(options)
|
27
|
+
@connection = Aws::S3::Resource.new(
|
28
|
+
credentials: Aws::Credentials.new(
|
29
|
+
options[:access_key_id],
|
30
|
+
options[:secret_access_key]
|
31
|
+
),
|
32
|
+
region: options[:region]
|
33
|
+
)
|
34
|
+
|
35
|
+
if @connection.nil?
|
36
|
+
raise "No connection to s3"
|
37
|
+
end
|
38
|
+
|
39
|
+
@bucket = @connection.bucket(options[:bucket])
|
40
|
+
|
41
|
+
if @bucket.nil?
|
42
|
+
raise "No such bucket #{options[:bucket]}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_object(path)
|
47
|
+
path = path.gsub /^\//, '' # remove forward slash on path
|
48
|
+
@bucket.object(path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def write_path(path, body)
|
52
|
+
object = find_object path
|
53
|
+
puts "S3: Writing: #{path} -> #{object.public_url}"
|
54
|
+
object.put(body: body)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lithograph.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lithograph/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lithograph"
|
8
|
+
spec.version = Lithograph::VERSION
|
9
|
+
spec.authors = ["Sam Murphy"]
|
10
|
+
spec.email = ["sam.murphy@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A small static site generator.}
|
13
|
+
spec.description = %q{A small static site generator.}
|
14
|
+
spec.homepage = "https://github.com/smurphy/lithograph"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'json'
|
22
|
+
spec.add_dependency 'aws-sdk'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lithograph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Murphy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description: A small static site generator.
|
84
|
+
email:
|
85
|
+
- sam.murphy@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/lithograph.rb
|
98
|
+
- lib/lithograph/publishers.rb
|
99
|
+
- lib/lithograph/version.rb
|
100
|
+
- lithograph.gemspec
|
101
|
+
homepage: https://github.com/smurphy/lithograph
|
102
|
+
licenses: []
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.5.1
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: A small static site generator.
|
124
|
+
test_files: []
|