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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9acdaf409f2eeaa0756fac9cd04b76ff29cede4d
4
- data.tar.gz: 2e4804a75002852a98cbc2131d3ca435d2659a35
3
+ metadata.gz: f3b618c306cec2db96a2784b49b09bab1b9187a9
4
+ data.tar.gz: 3802255ba4afb6ac702358e8494970f3f2525aec
5
5
  SHA512:
6
- metadata.gz: 040ca60c84cf640f88fb8f639ceed599f25968b84c620b54958efa3d77979228e61a04d3ca4b784f01c979be16ad93555edd54d725f43ebc4431fac2f035ceea
7
- data.tar.gz: 401ada9d189f99c0963996ccf71f014c93d3e73764c3c668c24c1cbffa72eea7c4e92513f35a1088196cc5a5cabdb762fa177b8f604695492cfd7363f7acc85d
6
+ metadata.gz: 386332bb26c6807ead49170d6ad20ed95bb0293d7c719a95e2af2eeab38eccb167059bcbb8147e1b2ef31bc7bf7fe5d347771eac79326a8b2aaf29a5e71013e3
7
+ data.tar.gz: 2b1afbde8154b8b02b5a99a780190e3bad29ae7cc32443a3d12b367bdd5db1523598693625340d76efb20f61f9b33814bc0767ec93f3a79fc60baac572faf057
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_dependency "thor"
20
20
  spec.add_dependency "redcarpet"
21
+ spec.add_dependency "pygments.rb"
21
22
  spec.add_dependency "listen"
22
23
  spec.add_dependency "sinatra"
23
24
  spec.add_dependency "sinatra-websocket"
@@ -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
 
@@ -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
@@ -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 = Redcarpet::Render::HTML.new(prettify: true)
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
@@ -1,3 +1,3 @@
1
1
  module Blogdoor
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -24,11 +24,21 @@ describe Blogdoor::Builder do
24
24
  end
25
25
 
26
26
  describe "#build" do
27
- it "inserts script tags for livereload" do
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
@@ -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
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-04 00:00:00.000000000 Z
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