octopress-render-code 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbab0868b38b969b758ec3ad8919c56628464e02
4
+ data.tar.gz: 2dd79c6b5abdce957da74989ff270ec3714c7fb7
5
+ SHA512:
6
+ metadata.gz: 52f6d3555359efbf36cb741ecb11c2c956024e532250c1d97369f15f9902bb7909191b1d2028747ac8ca995d4ad13ff26ca952e5f387456c88509f3a1da53729
7
+ data.tar.gz: 36d3cbfee942c04675a4e06cd83fc3a3e49b0e1b967c5e8079986a4af4025d8223d094a08ef06773f6dee61becabd75c3d0f36ebcaeb95ed3564953630aa5724
@@ -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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: cd test && bundle exec ruby test.rb
@@ -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
@@ -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.
@@ -0,0 +1,31 @@
1
+ # Octopress Render Code
2
+
3
+ Write beautiful code snippets within any template.
4
+
5
+ [![Build Status](https://travis-ci.org/octopress/render-code.png?branch=master)](https://travis-ci.org/octopress/render-code)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'octopress-render-code'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install octopress-render-code
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
@@ -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,91 @@
1
+ require 'octopress-render-code/version'
2
+ require 'octopress-code-highlighter'
3
+ require 'liquid'
4
+ require 'colorator'
5
+
6
+ module Octopress
7
+ module RenderCode
8
+ class Tag < Liquid::Tag
9
+
10
+ FileOnly = /^(\S+)$/
11
+ FileTitle = /(\S+)\s+(\S.*?)$/i
12
+ TitleFile = /(\S.*?)\s+(\S+)$/i
13
+
14
+ def initialize(tag_name, markup, tokens)
15
+ @markup = markup
16
+ super
17
+ end
18
+
19
+ def render(context)
20
+ @page_path = context.environments.first['page']['path']
21
+ site = context.registers[:site]
22
+ config_dir = (site.config['code_dir'] || 'downloads/code').sub(/^\//,'')
23
+ @code_dir = File.join(site.source, config_dir)
24
+
25
+ begin
26
+ options = get_options
27
+ code = File.open(@file).read.encode("UTF-8")
28
+ code = CodeHighlighter.select_lines(code, options)
29
+
30
+ highlight(code, options)
31
+ rescue => e
32
+ failure(e)
33
+ end
34
+ end
35
+
36
+ def get_path(file)
37
+ path = File.join(@code_dir, file)
38
+
39
+ if File.symlink?(path)
40
+ raise "Code directory '#{@code_path}' cannot be a symlink"
41
+ end
42
+
43
+ path if File.exists?(path)
44
+ end
45
+
46
+ def get_options
47
+ # wrap with {% raw %} tags to prevent addititional processing
48
+ defaults = { }
49
+
50
+ clean_markup = CodeHighlighter.clean_markup(@markup).strip
51
+
52
+ if clean_markup =~ FileOnly
53
+ @file = $1
54
+ elsif clean_markup =~ FileTitle
55
+ if @file = get_path($1)
56
+ defaults[:title] = $2
57
+
58
+ # Allow for deprecated title first syntax
59
+ #
60
+ elsif clean_markup =~ TitleFile
61
+ defaults[:title] = $1
62
+ @file = get_path($2)
63
+ puts "\nRenderCode Warning:".red
64
+ puts " Passing title before path has been deprecated and will be removed in RenderCode 2.0".red
65
+ puts " Update #{@page_path} with {% render_code #{$2} #{$1} ... %}.".yellow
66
+ end
67
+ end
68
+
69
+ options = CodeHighlighter.parse_markup(@markup, defaults)
70
+ options[:lang] ||= File.extname(@file).delete('.')
71
+ options[:link_text] ||= "Raw code"
72
+ options
73
+ end
74
+
75
+ def failure(message)
76
+ CodeHighlighter.highlight_failed(message, "{% include_code path/to/file [title] [lang:language] [start:#] [end:#] [range:#-#] [mark:#,#-#] [linenos:false] %}", @markup, '')
77
+ end
78
+
79
+
80
+ def highlight(code, options)
81
+ options[:aliases] = @aliases || {}
82
+ code = CodeHighlighter.highlight(code, options)
83
+ code = "<notextile>#{code}</notextile>" if File.extname(@page_path).match(/textile/)
84
+ code
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ Liquid::Template.register_tag('render_code', Octopress::RenderCode::Tag)
91
+ Liquid::Template.register_tag('include_code', Octopress::RenderCode::Tag)
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ module RenderCode
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopress-render-code/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "octopress-render-code"
8
+ gem.version = Octopress::RenderCode::VERSION
9
+ gem.authors = ["Brandon Mathis"]
10
+ gem.email = ["brandon@imathis.com"]
11
+ gem.description = %q{Embed highlighted code snippets from a file.}
12
+ gem.summary = %q{Embed highlighted code snippets from a file.}
13
+ gem.homepage = "https://github.com/octopress/render-code"
14
+ gem.license = "MIT"
15
+
16
+ gem.add_runtime_dependency 'jekyll', '~> 2.0.3'
17
+ gem.add_runtime_dependency 'octopress-code-highlighter', '~> 4.0.1'
18
+
19
+ gem.add_development_dependency 'rake'
20
+ gem.add_development_dependency 'rspec'
21
+
22
+ gem.files = `git ls-files`.split($/)
23
+ gem.require_paths = ["lib"]
24
+ end
@@ -0,0 +1 @@
1
+ _site
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry-debugger'
4
+ gem 'jekyll'
5
+ gem 'jekyll-page-hooks'
6
+ gem 'octopress-render-code', :path => '../'
@@ -0,0 +1,9 @@
1
+ name: Your New Jekyll Site
2
+ markdown: redcarpet
3
+ highlighter: pygments
4
+ exclude:
5
+ - Gemfile*
6
+ - expected.html
7
+ - test.rb
8
+ pygments_aliases:
9
+ abc: ruby
@@ -0,0 +1 @@
1
+ require 'octopress-render-code'
@@ -0,0 +1,5 @@
1
+ # Given an alphabet:
2
+ alphabet = 'abcdefghijklmnopqrstuvwxyz'
3
+
4
+ # Iterate over part of the alphabet:
5
+ console.log letter for letter in alphabet[4..8]
@@ -0,0 +1,13 @@
1
+ <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='1' class='code-highlight-row numbered marked-line start-marked-line'><div class='code-highlight-line'># Given an alphabet:</span>
2
+ </div></div><div data-line='2' class='code-highlight-row numbered marked-line end-marked-line'><div class='code-highlight-line'><span class="nv">alphabet = </span><span class="s">&#39;abcdefghijklmnopqrstuvwxyz&#39;</span>
3
+ </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="c1"># Iterate over part of the alphabet:</span>
4
+ </div></div><div data-line='5' class='code-highlight-row numbered'><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>
5
+
6
+ <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='1' class='code-highlight-row numbered'><div class='code-highlight-line'># Given an alphabet:</span>
7
+ </div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="nv">alphabet = </span><span class="s">&#39;abcdefghijklmnopqrstuvwxyz&#39;</span>
8
+ </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="c1"># Iterate over part of the alphabet:</span>
9
+ </div></div><div data-line='5' class='code-highlight-row numbered'><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>
10
+
11
+ <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='2' class='code-highlight-row numbered'><div class='code-highlight-line'>alphabet = </span><span class="s">&#39;abcdefghijklmnopqrstuvwxyz&#39;</span>
12
+ </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="c1"># Iterate over part of the alphabet:</span>
13
+ </div></div><div data-line='5' class='code-highlight-row numbered'><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>
@@ -0,0 +1,6 @@
1
+ ---
2
+ ---
3
+
4
+ {% render_code Coffeescript Tricks tricks.coffee mark:1,2 %}
5
+ {% render_code tricks.coffee Coffeescript Tricks link_text:"Download"%}
6
+ {% render_code tricks.coffee Coffeescript Tricks range:2-4 %}
@@ -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,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-render-code
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-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: octopress-code-highlighter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Embed highlighted code snippets from a file.
70
+ email:
71
+ - brandon@imathis.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/octopress-render-code.rb
85
+ - lib/octopress-render-code/version.rb
86
+ - octopress-render-code.gemspec
87
+ - test/.gitignore
88
+ - test/Gemfile
89
+ - test/_config.yml
90
+ - test/_plugins/render-code.rb
91
+ - test/downloads/code/tricks.coffee
92
+ - test/expected.html
93
+ - test/index.md
94
+ - test/test.rb
95
+ homepage: https://github.com/octopress/render-code
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Embed highlighted code snippets from a file.
119
+ test_files: []