octopress-codeblock 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9197fbc807767b0ae8345433e6d1a03d5c012416
4
+ data.tar.gz: e32c3c85cf6fae3860eecb8ba1cc2ddaf84f329b
5
+ SHA512:
6
+ metadata.gz: c6a803b4cd61e7cc0835e161c37a002345c41719cbb2a3568af27fa33dd6a1e325ff26307b3789b46145ed18eeb8e1e180024a65532e2f6b6363d20fc064764b
7
+ data.tar.gz: 0f73aa2908e2fe856758dcceb62f682d7637694c5c8101be10089fdb5e4a79a92246d510b5c7efa999039c7eafb75ecd088118c061c39d5df1f3128ccc4132ca
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ .pygments-cache
20
+ _site
21
+ .code-highlighter-cache
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: cd test && ruby test.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in octopress-codefence.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Octopress Codeblock
2
+
3
+ Write beautiful code snippets within any template.
4
+
5
+ [![Build Status](https://travis-ci.org/octopress/octopress-codeblock.png?branch=master)](https://travis-ci.org/octopress/octopress-codeblock)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'octopress-codeblock'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install octopress-codeblock
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,60 @@
1
+ require 'octopress-codeblock/version'
2
+ require 'octopress-code-highlighter'
3
+ require 'liquid'
4
+
5
+ module Octopress
6
+ module Codeblock
7
+ class Tag < Liquid::Block
8
+ CaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
9
+ Caption = /(\S[\S\s]*)/
10
+
11
+ def initialize(tag_name, markup, tokens)
12
+ @markup = markup
13
+ super
14
+ end
15
+
16
+ def render(context)
17
+ code = super.encode("UTF-8")
18
+
19
+ begin
20
+ highlight(code, get_options)
21
+ rescue => e
22
+ CodeHighlighter.highlight_failed(e, "{% codeblock [title] [url] [link text] [lang:language] [start:#] [mark:#,#-#] [linenos:false] %}\ncode\n{% endcodeblock %}", @markup, code)
23
+ end
24
+ end
25
+
26
+ def get_options
27
+ defaults = { escape: true }
28
+ clean_markup = CodeHighlighter.clean_markup(@markup)
29
+
30
+ if clean_markup =~ CaptionUrlTitle
31
+ defaults = {
32
+ title: $2,
33
+ url: $2,
34
+ link_text: $3,
35
+ }
36
+ elsif clean_markup =~ Caption
37
+ defaults = {
38
+ title: $1
39
+ }
40
+ end
41
+
42
+ if defaults[:title] =~ /\S[\S\s]*\w+\.(\w+)/
43
+ defaults[:lang] = $1
44
+ end
45
+
46
+ CodeHighlighter.parse_markup(@markup, defaults)
47
+ end
48
+
49
+
50
+ def highlight(code, options)
51
+ options[:aliases] = @aliases || {}
52
+ code = CodeHighlighter.highlight(code, options)
53
+ code = "<notextile>#{code}</notextile>" if !@ext.nil? and @ext.match(/textile/)
54
+ code
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ Liquid::Template.register_tag('codeblock', Octopress::Codeblock::Tag)
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ module Codeblock
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopress-codeblock/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "octopress-codeblock"
8
+ gem.version = Octopress::Codeblock::VERSION
9
+ gem.authors = ["Brandon Mathis"]
10
+ gem.email = ["brandon@imathis.com"]
11
+ gem.description = %q{Write beautiful code snippets within any template.}
12
+ gem.summary = %q{Write beautiful code snippets within any template.}
13
+ gem.homepage = "https://github.com/octopress/octopress-codeblock"
14
+ gem.license = "MIT"
15
+
16
+ gem.add_runtime_dependency 'octopress-code-highlighter', '~> 4.0.0'
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec'
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.require_paths = ["lib"]
23
+ end
data/test/.gitignore ADDED
@@ -0,0 +1 @@
1
+ _site
data/test/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'jekyll'
4
+ gem 'jekyll-page-hooks'
5
+ gem 'octopress-codeblock', :path => '../'
data/test/_config.yml ADDED
@@ -0,0 +1,5 @@
1
+ name: Your New Jekyll Site
2
+ markdown: redcarpet
3
+ highlighter: pygments
4
+ pygments_aliases:
5
+ abc: ruby
@@ -0,0 +1 @@
1
+ require 'octopress-codeblock'
@@ -0,0 +1,6 @@
1
+ <figure class='code-highlight-figure'><figcaption class='code-highlight-caption'><span class='code-highlight-caption-title'>some script.rb</span></figcaption><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='1' class='code-highlight-row numbered'><div class='code-highlight-line'>puts</span> <span class="vi">@awesome</span> <span class="k">if</span> <span class="kp">true</span></div></div></pre></div></figure>
2
+
3
+ <figure class='code-highlight-figure'><figcaption class='code-highlight-caption'><span class='code-highlight-caption-title'>Coffeescript Tricks</span></figcaption><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='51' class='code-highlight-row numbered marked-line start-marked-line end-marked-line'><div class='code-highlight-line'># Given an alphabet:</span>
4
+ </div></div><div data-line='52' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="nv">alphabet = </span><span class="s">&#39;abcdefghijklmnopqrstuvwxyz&#39;</span>
5
+ </div></div><div data-line='53' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='54' class='code-highlight-row numbered marked-line start-marked-line'><div class='code-highlight-line'><span class="c1"># Iterate over part of the alphabet:</span>
6
+ </div></div><div data-line='55' class='code-highlight-row numbered marked-line end-marked-line'><div class='code-highlight-line'><span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">letter</span> <span class="k">for</span> <span class="nx">letter</span> <span class="k">in</span> <span class="nx">alphabet</span><span class="p">[</span><span class="mi">4</span><span class="p">..</span><span class="mi">8</span><span class="p">]</span></div></div></pre></div></figure>
data/test/index.html ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ ---
3
+
4
+ {% codeblock some script.rb %}
5
+ puts @awesome if true
6
+ {% endcodeblock %}
7
+
8
+ {% codeblock Coffeescript Tricks lang:coffeescript start:51 mark:51,54-55 %}
9
+ # Given an alphabet:
10
+ alphabet = 'abcdefghijklmnopqrstuvwxyz'
11
+
12
+ # Iterate over part of the alphabet:
13
+ console.log letter for letter in alphabet[4..8]
14
+ {% endcodeblock %}
data/test/test.rb ADDED
@@ -0,0 +1,3 @@
1
+ system('jekyll build')
2
+ diff = `diff _site/index.html expected.html`
3
+ abort "Filed with diff: #{diff}" if diff.size > 0
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-codeblock
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octopress-code-highlighter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write beautiful code snippets within any template.
56
+ email:
57
+ - brandon@imathis.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/octopress-codeblock.rb
71
+ - lib/octopress-codeblock/version.rb
72
+ - octopress-codeblock.gemspec
73
+ - test/.gitignore
74
+ - test/Gemfile
75
+ - test/_config.yml
76
+ - test/_plugins/codeblock.rb
77
+ - test/expected.html
78
+ - test/index.html
79
+ - test/test.rb
80
+ homepage: https://github.com/octopress/octopress-codeblock
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Write beautiful code snippets within any template.
104
+ test_files: []