blogdoor 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/blogdoor.gemspec +1 -0
- data/lib/blogdoor/builder.rb +6 -0
- data/lib/blogdoor/command.rb +2 -1
- data/lib/blogdoor/converter.rb +22 -1
- data/lib/blogdoor/version.rb +1 -1
- data/spec/blogdoor/builder_spec.rb +11 -1
- data/spec/blogdoor/converter_spec.rb +21 -0
- data/spec/fixtures/sample.md +20 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3b618c306cec2db96a2784b49b09bab1b9187a9
|
4
|
+
data.tar.gz: 3802255ba4afb6ac702358e8494970f3f2525aec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 386332bb26c6807ead49170d6ad20ed95bb0293d7c719a95e2af2eeab38eccb167059bcbb8147e1b2ef31bc7bf7fe5d347771eac79326a8b2aaf29a5e71013e3
|
7
|
+
data.tar.gz: 2b1afbde8154b8b02b5a99a780190e3bad29ae7cc32443a3d12b367bdd5db1523598693625340d76efb20f61f9b33814bc0767ec93f3a79fc60baac572faf057
|
data/blogdoor.gemspec
CHANGED
data/lib/blogdoor/builder.rb
CHANGED
@@ -4,6 +4,8 @@ require "redcarpet"
|
|
4
4
|
|
5
5
|
module Blogdoor
|
6
6
|
class Builder
|
7
|
+
attr_accessor :ignore_patterns
|
8
|
+
|
7
9
|
def initialize(args = {})
|
8
10
|
@root_path = Pathname.new(args[:root_path] || ".")
|
9
11
|
@builds_path = @root_path.join("builds")
|
@@ -12,6 +14,8 @@ module Blogdoor
|
|
12
14
|
@layout = ERB.new(layout_path.read)
|
13
15
|
@converter = Converter.new
|
14
16
|
@client = Client.new
|
17
|
+
|
18
|
+
@ignore_patterns = (args[:ignore_patterns] || []).map { |pattern| /#{pattern}/ }
|
15
19
|
end
|
16
20
|
|
17
21
|
def build_all
|
@@ -22,6 +26,8 @@ module Blogdoor
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def build(post_path)
|
29
|
+
return if @ignore_patterns.any? { |pattern| post_path.to_s =~ pattern }
|
30
|
+
|
25
31
|
filename = post_path.basename(".md")
|
26
32
|
html_path = @builds_path.join("#{filename}.html")
|
27
33
|
|
data/lib/blogdoor/command.rb
CHANGED
@@ -4,8 +4,9 @@ require "rack"
|
|
4
4
|
module Blogdoor
|
5
5
|
class Command < Thor
|
6
6
|
desc "start", "Start blogdoor"
|
7
|
+
option :ignore, type: :array, aliases: "-I", default: []
|
7
8
|
def start
|
8
|
-
builder = Builder.new
|
9
|
+
builder = Builder.new(ignore_patterns: options[:ignore])
|
9
10
|
builder.build_all
|
10
11
|
watcher = Watcher.new
|
11
12
|
watcher.builder = builder
|
data/lib/blogdoor/converter.rb
CHANGED
@@ -1,14 +1,35 @@
|
|
1
1
|
require "redcarpet"
|
2
|
+
require "pygments"
|
2
3
|
|
3
4
|
module Blogdoor
|
4
5
|
class Converter
|
5
6
|
def initialize
|
6
|
-
renderer =
|
7
|
+
renderer = BlockCodeWithFilename.new
|
7
8
|
@markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
|
8
9
|
end
|
9
10
|
|
10
11
|
def convert(content)
|
11
12
|
@markdown.render(content)
|
12
13
|
end
|
14
|
+
|
15
|
+
class BlockCodeWithFilename < Redcarpet::Render::HTML
|
16
|
+
INDENT = " " * 2
|
17
|
+
|
18
|
+
def block_code(code, metadata)
|
19
|
+
language, filename = metadata.split(":") if metadata
|
20
|
+
rows = []
|
21
|
+
rows << %(<div class="code-block">)
|
22
|
+
if filename
|
23
|
+
rows << %(#{INDENT}<div class="code-header">)
|
24
|
+
rows << %(#{INDENT * 2}<span>#{filename}</span>)
|
25
|
+
rows << %(#{INDENT}</div>)
|
26
|
+
end
|
27
|
+
rows << %(#{INDENT}<div class="code-body">)
|
28
|
+
rows << %(#{INDENT * 2}#{Pygments.highlight(code, lexer: language)})
|
29
|
+
rows << %(#{INDENT}</div>)
|
30
|
+
rows << %(</div>)
|
31
|
+
rows.join("\n")
|
32
|
+
end
|
33
|
+
end
|
13
34
|
end
|
14
35
|
end
|
data/lib/blogdoor/version.rb
CHANGED
@@ -24,11 +24,21 @@ describe Blogdoor::Builder do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#build" do
|
27
|
-
|
27
|
+
before(:each) do
|
28
28
|
builds_path.mkdir
|
29
|
+
end
|
30
|
+
|
31
|
+
it "inserts script tags for livereload" do
|
29
32
|
builder.build(root_path.join("sample.md"))
|
30
33
|
html = builds_path.join("sample.html").read
|
31
34
|
expect(html).to include "livereload.js"
|
32
35
|
end
|
36
|
+
|
37
|
+
it "ignores file path matched with ignore_patterns" do
|
38
|
+
builder.ignore_patterns = [/sample/]
|
39
|
+
builder.build(root_path.join("sample.md"))
|
40
|
+
html_path = builds_path.join("sample.html")
|
41
|
+
expect(html_path).not_to exist
|
42
|
+
end
|
33
43
|
end
|
34
44
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
describe Blogdoor::Converter do
|
5
|
+
let(:converter) { described_class.new }
|
6
|
+
let(:sample_path) { Pathname.new("../fixtures/sample.md").expand_path(File.dirname(__FILE__)) }
|
7
|
+
|
8
|
+
describe "#convert" do
|
9
|
+
it "generates highlighted code blocks" do
|
10
|
+
content = converter.convert(sample_path.read)
|
11
|
+
expect(content).to match /<div class="highlight">/
|
12
|
+
end
|
13
|
+
|
14
|
+
it "generates code blocks" do
|
15
|
+
content = converter.convert(sample_path.read)
|
16
|
+
expect(content).to match /<div class="code-block">/
|
17
|
+
expect(content).to match /<div class="code-header">/
|
18
|
+
expect(content).to match /<div class="code-body">/
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/fixtures/sample.md
CHANGED
@@ -14,3 +14,23 @@
|
|
14
14
|
|
15
15
|
冬はつとめて。雪の降りたるはいふべきにもあらず。霜のいと白きも、またさらでも、いと寒きに、火などいそぎおこして、炭もてわたるもいとつきづきし。昼になりて、ぬるくゆるびもて行けば、火桶の火も白き灰がちになりてわろし。
|
16
16
|
|
17
|
+
# Code sample
|
18
|
+
|
19
|
+
```rb:greeter.rb
|
20
|
+
class Greeter
|
21
|
+
def initialize(name)
|
22
|
+
@name = name.capitalize
|
23
|
+
end
|
24
|
+
|
25
|
+
def salute
|
26
|
+
puts "Hello #{@name}!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create a new object
|
31
|
+
g = Greeter.new("world")
|
32
|
+
|
33
|
+
# Output "Hello World!"
|
34
|
+
g.salute
|
35
|
+
```
|
36
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blogdoor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoto Kaneko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pygments.rb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: listen
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +161,7 @@ files:
|
|
147
161
|
- lib/blogdoor/watcher.rb
|
148
162
|
- lib/javascripts/livereload.js
|
149
163
|
- spec/blogdoor/builder_spec.rb
|
164
|
+
- spec/blogdoor/converter_spec.rb
|
150
165
|
- spec/fixtures/layout.erb
|
151
166
|
- spec/fixtures/sample.md
|
152
167
|
- spec/spec_helper.rb
|
@@ -176,6 +191,7 @@ specification_version: 4
|
|
176
191
|
summary: Blogdoor is a toolkit for easily previewing posts.
|
177
192
|
test_files:
|
178
193
|
- spec/blogdoor/builder_spec.rb
|
194
|
+
- spec/blogdoor/converter_spec.rb
|
179
195
|
- spec/fixtures/layout.erb
|
180
196
|
- spec/fixtures/sample.md
|
181
197
|
- spec/spec_helper.rb
|