jekyll-code-example-tag 0.0.1

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: cc6b3dbb5ed6465f5d964a2f14f42ee6024337a2
4
+ data.tar.gz: 92deaf1d6c1133049877ea597c0c6fe28a0d67c9
5
+ SHA512:
6
+ metadata.gz: 0c8f4f1d2cd4464713302dddb000755e6b32e14e86e38563cc64a7138a39102b3597b8b193544f5d253594b14edf049bda29002243070a976d87f6c7cca827cf
7
+ data.tar.gz: fcae7f05e3ada2e1564c13adefd5b49dcc420fe0b8dad4a9c5de007146088cd753e31b98fb2c6bcd508aae644bcacd586ccd293d020e1a8be49eda861967a8b9
data/LICENSE.md ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2015, GovDelivery, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of GovDelivery nor the names of its contributors may be
15
+ used to endorse or promote products derived from this software without
16
+ specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Stuff!
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'jekyll-code-example-tag'
3
+ s.version = '0.0.1'
4
+ s.date = '2015-02-03'
5
+ s.authors = ['GovDelivery']
6
+ s.email = 'support@govdelivery.com'
7
+ s.homepage = 'http://govdelivery.com'
8
+ s.license = 'BSD-3-Clause'
9
+ s.summary = 'Tags for including code examples in posts and pages.'
10
+ s.description = %q{Provides a tag that allows you to include in your posts
11
+ and pages code examples for multiple langagues that are
12
+ kept in seperate files. Another tag allows you to combine
13
+ all code examples that are on a page.}
14
+
15
+ s.add_runtime_dependency 'jekyll'
16
+
17
+ s.files = `git ls-files`.split($\)
18
+ s.require_paths = ['lib']
19
+ end
@@ -0,0 +1,104 @@
1
+ module Jekyll
2
+ module CodeExampleTags
3
+
4
+ def self.code_example_dir(site)
5
+ site.fetch('code_example_dir', 'code_examples')
6
+ end
7
+
8
+ # Returns a hash of available code examples (per language) for the provided example name
9
+ def self.code_examples(example_name, site)
10
+ # Collect all relevant files
11
+ examples_root = code_example_dir(site)
12
+
13
+ code_folders = Dir.entries(examples_root).select do |entry|
14
+ File.directory? File.join(examples_root, entry) and !(entry =='.' || entry == '..')
15
+ end
16
+
17
+ examples = {}
18
+ code_folders.each do |lang|
19
+ code_folder = File.join(examples_root, lang)
20
+ example_file = Dir.entries(code_folder).find do |entry|
21
+ File.file? File.join(code_folder, entry) and entry == example_name
22
+ end
23
+ if example_file
24
+ examples[lang] = File.join(code_folder, example_file)
25
+ end
26
+ end
27
+
28
+ examples
29
+ end
30
+
31
+ def self.buttons_markup(examples)
32
+ menu_items = ""
33
+ examples.each_key do |lang|
34
+ menu_items << "<li><a href='#' class='button' target='#{lang}'>#{lang.capitalize}</a></li>"
35
+ end
36
+ <<EOF
37
+ <div class="buttons examples">
38
+ <ul>
39
+ #{menu_items}
40
+ </ul>
41
+ </div>
42
+ EOF
43
+ end
44
+
45
+ def self.example_markup(language, content)
46
+ <<EOF
47
+ <div class="highlight example #{language}">
48
+ <pre><code class="language-#{language}" data-lang="#{language}">#{content}</code></pre>
49
+ </div>
50
+ EOF
51
+
52
+ end
53
+
54
+ def self.wrap_examples_div(content)
55
+ "<div class='code-examples'>#{content}</div>"
56
+ end
57
+
58
+ class CodeExampleTag < Liquid::Tag
59
+ def initialize(tag_name, example_name, tokens)
60
+ @example_name = example_name.strip
61
+ super
62
+ end
63
+
64
+ def render(context)
65
+
66
+ examples = Jekyll::CodeExampleTags::code_examples(@example_name, context['site'])
67
+
68
+ # Build the code example elements
69
+ output = Jekyll::CodeExampleTags::buttons_markup(examples)
70
+ examples.each do |lang, path|
71
+ example_content = File.read(path)
72
+ output << Jekyll::CodeExampleTags::example_markup(lang, example_content)
73
+ end
74
+
75
+ output = Jekyll::CodeExampleTags::wrap_examples_div(output)
76
+ end
77
+ end
78
+
79
+ class AllPageCodeExamplesTag < Liquid::Tag
80
+ def render(context)
81
+ examples = {}
82
+ context['page']['content'].scan(/\{%\s*code_example (\S+)\s*%\}/) do |name|
83
+ more_examples = Jekyll::CodeExampleTags::code_examples(name[0], context['site'])
84
+ examples.merge!(more_examples){|key, pre_example, new_example| "#{pre_example}\n#{new_example}"}
85
+ end
86
+
87
+ # Build the code example elements
88
+ output = Jekyll::CodeExampleTags::buttons_markup(examples)
89
+ examples.each do |lang, paths|
90
+ example_content = ""
91
+ for path in paths.split("\n")
92
+ example_content << File.read(path)
93
+ end
94
+ output << Jekyll::CodeExampleTags::example_markup(lang, example_content)
95
+ end
96
+
97
+ output = Jekyll::CodeExampleTags::wrap_examples_div(output)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ Liquid::Template.register_tag('code_example', Jekyll::CodeExampleTags::CodeExampleTag)
104
+ Liquid::Template.register_tag('all_page_code_examples', Jekyll::CodeExampleTags::AllPageCodeExamplesTag)
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-code-example-tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - GovDelivery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-03 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: '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
+ description: "Provides a tag that allows you to include in your posts \n and
28
+ pages code examples for multiple langagues that are \n kept
29
+ in seperate files. Another tag allows you to combine\n all code
30
+ examples that are on a page."
31
+ email: support@govdelivery.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - LICENSE.md
37
+ - README.md
38
+ - jekyll-code-example-tag.gemspec
39
+ - lib/jekyll-code-example-tag.rb
40
+ homepage: http://govdelivery.com
41
+ licenses:
42
+ - BSD-3-Clause
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.0.14
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Tags for including code examples in posts and pages.
64
+ test_files: []