jekyll-code-example-tag 0.0.4 → 2.0.0

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
- SHA1:
3
- metadata.gz: 313440e34ab23b1fc7dbf0f74007afac212cf8d6
4
- data.tar.gz: 1000fa7315fecf654b1b691c3675d0a9ee45f915
2
+ SHA256:
3
+ metadata.gz: 7b13f017a8d87b58d301d173180b0f452f493d6d6ad68f54fdb90c1180beeae9
4
+ data.tar.gz: 33aa124a741ae846c6de84ac72c98890a24a62d6e0cb88eb365c0f45ec67ad16
5
5
  SHA512:
6
- metadata.gz: 03cfaf2a1f6389da446bbb38a2001242d77199e80ffc15f51a519c49736de856f5d9952d185bfc9b995007daa193f69c958d08230e0ff7f41ab76a646852b087
7
- data.tar.gz: db4d25d8a1c4e354e89656d0c0f9658a920794ea1b40fdaab2e29a3e7f3cea19cc3fc7ad5abc80722d53cca7a08e1c1c7dd5e69068d307f623a63c64048ad4d8
6
+ metadata.gz: 5bcc845cacd4d956e588ac3ae782f5962fa7ba4b8a76fd31388d44362134bad7b52adbed67e3aeabaf31101a89dd20aa442f751eff07c50b4d30ccfa0e944bde
7
+ data.tar.gz: bb3e7e483adbe729dd47a8ae8a873a2c56d8ccc7ad9dc26ea4998e93eb86cd87ae3f451aebcef01c64440f4e53f78b8ab89b929b8de058bceb0b83a2b1458398
@@ -0,0 +1 @@
1
+ .bundle
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.7.1
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3-p547
4
- - 2.1.5
5
- - 2.2.0
3
+ - 2.5.8
4
+ - 2.6.6
5
+ - 2.7.1
6
6
  script: "bundle exec rspec"
@@ -0,0 +1,39 @@
1
+ CHANGELOG
2
+ ==========
3
+
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ [How to use a CHANGELOG](http://keepachangelog.com/)
7
+
8
+ ## 2.0.0 - 2020-08-20
9
+
10
+ ## Changed
11
+
12
+ - Various dependency updates to address vulnerabilities
13
+ - Ruby version >= 2.3.0 now required
14
+
15
+ ## 1.0.0 - 2017-01-30
16
+
17
+ ### Changed
18
+
19
+ - Started versioning based on semantic versioning.
20
+
21
+ ### Added
22
+
23
+ - CSS class applied to \<li> and \<ul> tags in language menus can be set via the
24
+ `code_example_list_class` in _config.yml.
25
+
26
+ ## 0.0.7 - 2015-03-18
27
+
28
+ ### Fixed
29
+
30
+ - HTML escaping code examples, so the brower renders HTML/XMl as HTML/XML
31
+ characters
32
+
33
+ ## 0.0.6 - 2015-03-16
34
+
35
+ ### Added
36
+
37
+ - CSS classes applied to buttons and button container elements can now be
38
+ configured via _config.yml. Supporting JavaScript also uses classes set in
39
+ _config.yml.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem "fakefs", require: "fakefs/safe"
8
- gem 'nokogiri'
8
+ gem 'nokogiri', '~>1.10.8'
9
9
  gem 'pry'
10
10
  gem 'rspec'
11
11
  end
@@ -1,77 +1,74 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-code-example-tag (0.0.3)
4
+ jekyll-code-example-tag (2.0.0)
5
+ htmlentities
5
6
  jekyll
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- blankslate (2.1.2.4)
11
- celluloid (0.16.0)
12
- timers (~> 4.0.0)
13
- classifier-reborn (2.0.3)
14
- fast-stemmer (~> 1.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
15
13
  coderay (1.1.0)
16
- coffee-script (2.3.0)
17
- coffee-script-source
18
- execjs
19
- coffee-script-source (1.9.0)
20
- colorator (0.1)
14
+ colorator (1.1.0)
15
+ concurrent-ruby (1.1.7)
21
16
  diff-lcs (1.2.5)
22
- execjs (2.3.0)
17
+ em-websocket (0.5.1)
18
+ eventmachine (>= 0.12.9)
19
+ http_parser.rb (~> 0.6.0)
20
+ eventmachine (1.2.7)
23
21
  fakefs (0.6.5)
24
- fast-stemmer (1.0.2)
25
- ffi (1.9.6)
26
- hitimes (1.2.2)
27
- jekyll (2.5.3)
28
- classifier-reborn (~> 2.0)
29
- colorator (~> 0.1)
30
- jekyll-coffeescript (~> 1.0)
31
- jekyll-gist (~> 1.0)
32
- jekyll-paginate (~> 1.0)
33
- jekyll-sass-converter (~> 1.0)
34
- jekyll-watch (~> 1.1)
35
- kramdown (~> 1.3)
36
- liquid (~> 2.6.1)
37
- mercenary (~> 0.3.3)
38
- pygments.rb (~> 0.6.0)
39
- redcarpet (~> 3.1)
22
+ ffi (1.13.1)
23
+ forwardable-extended (2.6.0)
24
+ htmlentities (4.3.4)
25
+ http_parser.rb (0.6.0)
26
+ i18n (1.8.5)
27
+ concurrent-ruby (~> 1.0)
28
+ jekyll (4.1.1)
29
+ addressable (~> 2.4)
30
+ colorator (~> 1.0)
31
+ em-websocket (~> 0.5)
32
+ i18n (~> 1.0)
33
+ jekyll-sass-converter (~> 2.0)
34
+ jekyll-watch (~> 2.0)
35
+ kramdown (~> 2.1)
36
+ kramdown-parser-gfm (~> 1.0)
37
+ liquid (~> 4.0)
38
+ mercenary (~> 0.4.0)
39
+ pathutil (~> 0.9)
40
+ rouge (~> 3.0)
40
41
  safe_yaml (~> 1.0)
41
- toml (~> 0.1.0)
42
- jekyll-coffeescript (1.0.1)
43
- coffee-script (~> 2.2)
44
- jekyll-gist (1.1.0)
45
- jekyll-paginate (1.1.0)
46
- jekyll-sass-converter (1.3.0)
47
- sass (~> 3.2)
48
- jekyll-watch (1.2.1)
49
- listen (~> 2.7)
50
- kramdown (1.5.0)
51
- liquid (2.6.2)
52
- listen (2.8.5)
53
- celluloid (>= 0.15.2)
54
- rb-fsevent (>= 0.9.3)
55
- rb-inotify (>= 0.9)
56
- mercenary (0.3.5)
42
+ terminal-table (~> 1.8)
43
+ jekyll-sass-converter (2.1.0)
44
+ sassc (> 2.0.1, < 3.0)
45
+ jekyll-watch (2.2.1)
46
+ listen (~> 3.0)
47
+ kramdown (2.3.0)
48
+ rexml
49
+ kramdown-parser-gfm (1.1.0)
50
+ kramdown (~> 2.0)
51
+ liquid (4.0.3)
52
+ listen (3.2.1)
53
+ rb-fsevent (~> 0.10, >= 0.10.3)
54
+ rb-inotify (~> 0.9, >= 0.9.10)
55
+ mercenary (0.4.0)
57
56
  method_source (0.8.2)
58
- mini_portile (0.6.2)
59
- nokogiri (1.6.6.2)
60
- mini_portile (~> 0.6.0)
61
- parslet (1.5.0)
62
- blankslate (~> 2.0)
63
- posix-spawn (0.3.9)
57
+ mini_portile2 (2.4.0)
58
+ nokogiri (1.10.10)
59
+ mini_portile2 (~> 2.4.0)
60
+ pathutil (0.16.2)
61
+ forwardable-extended (~> 2.6)
64
62
  pry (0.10.1)
65
63
  coderay (~> 1.1.0)
66
64
  method_source (~> 0.8.1)
67
65
  slop (~> 3.4)
68
- pygments.rb (0.6.2)
69
- posix-spawn (~> 0.3.6)
70
- yajl-ruby (~> 1.2.0)
71
- rb-fsevent (0.9.4)
72
- rb-inotify (0.9.5)
73
- ffi (>= 0.5.0)
74
- redcarpet (3.2.2)
66
+ public_suffix (4.0.5)
67
+ rb-fsevent (0.10.4)
68
+ rb-inotify (0.10.1)
69
+ ffi (~> 1.0)
70
+ rexml (3.2.4)
71
+ rouge (3.22.0)
75
72
  rspec (3.2.0)
76
73
  rspec-core (~> 3.2.0)
77
74
  rspec-expectations (~> 3.2.0)
@@ -85,14 +82,13 @@ GEM
85
82
  diff-lcs (>= 1.2.0, < 2.0)
86
83
  rspec-support (~> 3.2.0)
87
84
  rspec-support (3.2.0)
88
- safe_yaml (1.0.4)
89
- sass (3.4.11)
85
+ safe_yaml (1.0.5)
86
+ sassc (2.4.0)
87
+ ffi (~> 1.9)
90
88
  slop (3.6.0)
91
- timers (4.0.1)
92
- hitimes
93
- toml (0.1.2)
94
- parslet (~> 1.5.0)
95
- yajl-ruby (1.2.1)
89
+ terminal-table (1.8.0)
90
+ unicode-display_width (~> 1.1, >= 1.1.1)
91
+ unicode-display_width (1.7.0)
96
92
 
97
93
  PLATFORMS
98
94
  ruby
@@ -100,6 +96,9 @@ PLATFORMS
100
96
  DEPENDENCIES
101
97
  fakefs
102
98
  jekyll-code-example-tag!
103
- nokogiri
99
+ nokogiri (~> 1.10.8)
104
100
  pry
105
101
  rspec
102
+
103
+ BUNDLED WITH
104
+ 2.1.4
data/README.md CHANGED
@@ -5,7 +5,7 @@ jekyll-code-example-tag
5
5
  =======================
6
6
 
7
7
  Provides a tag that allows you to include in your posts and pages code examples
8
- for multiple langagues that are kept in seperate files. Another tag allows you
8
+ for multiple languages that are kept in separate files. Another tag allows you
9
9
  to combine all code examples that are on a page.
10
10
 
11
11
  ## Installation
@@ -32,6 +32,27 @@ file in the `/js/` directory of your Jekyll project.
32
32
 
33
33
  ## Usage
34
34
 
35
+ ### Configure CSS Classes
36
+
37
+ Via your site's _config.yml, you can define what CSS class or classes the
38
+ example buttons and button containers will have. For example:
39
+
40
+ code_example_buttons_class: 'the_buttons'
41
+ code_example_button_class: 'a_button'
42
+
43
+ will cause each button to have the class `a_button`, and buttons will be inside
44
+ a div with the class `the_buttons`.
45
+
46
+ `code_example_buttons_class` defaults to 'buttons', and
47
+ `code_example_button_class` defaults to 'button'.
48
+
49
+ Same is true for ```code_example_list_class``` which controls the class used for the ```<li>``` and ```<ul>``` tags.
50
+ The default class is 'code-tab' which can be changed by setting:
51
+ ```
52
+ code_example_list_class: my-list-class
53
+ ```
54
+ in _config.yml.
55
+
35
56
  ### code_example
36
57
 
37
58
  First, select a folder to place your code examples in. By default, the top
@@ -124,6 +145,43 @@ the resulting markup will include just the Ruby example:
124
145
  </div>
125
146
  </div>
126
147
 
148
+ The *code_example* tag can also support examples organized in sub directories.
149
+ For example, say you would like to organize some of your code examples by
150
+ product and API version:
151
+
152
+ .
153
+ |-code_examples
154
+ |-productA
155
+ |-api_v1
156
+ |-ruby
157
+ |-widget_maker
158
+ |-python
159
+ |-widget_maker
160
+ |-api_v2
161
+ |-ruby
162
+ |-widget_maker
163
+ |-python
164
+ |-widget_maker
165
+ |-productB
166
+ |-api_v1
167
+ |-ruby
168
+ |-authenticating
169
+ |-python
170
+ |-authenticating
171
+ |-ruby
172
+ |-hello_world
173
+ |-python
174
+ |-hello_world
175
+
176
+ With the above directory structure, including any of the following calls to
177
+ code_example will result in including only the relevant code examples from
178
+ the referred to directory:
179
+
180
+ {% code_example productA/api_v1/widget_maker %}
181
+ {% code_example productA/api_v2/widget_maker %}
182
+ {% code_example productB/api_v1/authenticating %}
183
+ {% code_example hello_world %}
184
+
127
185
  ### all_page_code_examples
128
186
 
129
187
  If you have included a few code examples on a page via the *code_example* tag,
@@ -1,19 +1,21 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jekyll-code-example-tag'
3
- s.version = '0.0.4'
3
+ s.version = '2.0.0'
4
4
  s.date = '2015-02-03'
5
5
  s.authors = ['GovDelivery']
6
6
  s.email = 'support@govdelivery.com'
7
- s.homepage = 'https://github.com/govdelivery/jekyll-code-example-tag'
7
+ s.homepage = 'https://github.com/Granicus/jekyll-code-example-tag'
8
8
  s.license = 'BSD-3-Clause'
9
9
  s.summary = 'Tags for including code examples in posts and pages.'
10
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
11
+ and pages code examples for multiple languages that are
12
+ kept in separate files. Another tag allows you to combine
13
13
  all code examples that are on a page.}
14
14
 
15
15
  s.add_runtime_dependency 'jekyll'
16
+ s.add_runtime_dependency 'htmlentities'
16
17
 
17
18
  s.files = `git ls-files`.split($\)
18
19
  s.require_paths = ['lib']
20
+ s.required_ruby_version = '>= 2.3.0'
19
21
  end
@@ -1,3 +1,6 @@
1
+ require_relative 'js/jekyll-code-example-buttons.js.rb'
2
+ require 'htmlentities'
3
+
1
4
  module Jekyll
2
5
  module CodeExampleTags
3
6
 
@@ -6,9 +9,9 @@ module Jekyll
6
9
  end
7
10
 
8
11
  # Returns a hash of available code examples (per language) for the provided example name
9
- def self.code_examples(example_name, site)
12
+ def self.code_examples(context_path, example_name, site)
10
13
  # Collect all relevant files
11
- examples_root = code_example_dir(site)
14
+ examples_root = File.join(code_example_dir(site), context_path)
12
15
 
13
16
  code_folders = Dir.entries(examples_root).select do |entry|
14
17
  File.directory? File.join(examples_root, entry) and !(entry =='.' || entry == '..')
@@ -28,14 +31,18 @@ module Jekyll
28
31
  examples
29
32
  end
30
33
 
31
- def self.buttons_markup(examples)
34
+ def self.buttons_markup(examples, context)
35
+ site = context['site']
36
+ buttons_class = site['code_example_buttons_class'] ? site['code_example_buttons_class'] : 'buttons'
37
+ button_class = site['code_example_button_class'] ? site['code_example_button_class'] : 'button'
38
+ list_class = site['code_example_list_class'] ? site['code_example_list_class'] : 'code-tab'
32
39
  menu_items = ""
33
40
  examples.each_key do |lang|
34
- menu_items << "<li><a href='#' class='button' target='#{lang}'>#{lang.capitalize}</a></li>"
41
+ menu_items << "<li class='#{list_class}'><a href='#' class='#{button_class}' target='#{lang}'>#{lang.capitalize}</a></li>"
35
42
  end
36
43
  <<EOF
37
- <div class="buttons examples">
38
- <ul>
44
+ <div class="#{buttons_class} examples">
45
+ <ul class="#{list_class}">
39
46
  #{menu_items}
40
47
  </ul>
41
48
  </div>
@@ -43,9 +50,10 @@ EOF
43
50
  end
44
51
 
45
52
  def self.example_markup(language, content)
53
+ he = HTMLEntities.new
46
54
  <<EOF
47
55
  <div class="highlight example #{language}">
48
- <pre><code class="language #{language}" data-lang="#{language}">#{content}</code></pre>
56
+ <pre><code class="#{language}" data-lang="#{language}">#{he.encode(content)}</code></pre>
49
57
  </div>
50
58
  EOF
51
59
 
@@ -55,18 +63,32 @@ EOF
55
63
  "<div class='code-examples'>#{content}</div>"
56
64
  end
57
65
 
66
+ def self.get_example_name_and_context(example_string)
67
+ example_string.strip!
68
+ if example_string.include?('/')
69
+ example_arr = example_string.split('/')
70
+ example_name = example_arr.delete_at(-1)
71
+ context_path = example_arr.join(File::SEPARATOR) + File::SEPARATOR
72
+ else
73
+ context_path = ''
74
+ example_name = example_string
75
+ end
76
+
77
+ return context_path, example_name
78
+ end
79
+
58
80
  class CodeExampleTag < Liquid::Tag
59
- def initialize(tag_name, example_name, tokens)
60
- @example_name = example_name.strip
61
- super
81
+ def initialize(tag_name, example_string, tokens)
82
+ @context_path, @example_name = Jekyll::CodeExampleTags::get_example_name_and_context(example_string)
83
+ super
62
84
  end
63
85
 
64
86
  def render(context)
65
87
 
66
- examples = Jekyll::CodeExampleTags::code_examples(@example_name, context['site'])
88
+ examples = Jekyll::CodeExampleTags::code_examples(@context_path, @example_name, context['site'])
67
89
 
68
90
  # Build the code example elements
69
- output = Jekyll::CodeExampleTags::buttons_markup(examples)
91
+ output = Jekyll::CodeExampleTags::buttons_markup(examples, context)
70
92
  examples.each do |lang, path|
71
93
  example_content = File.read(path)
72
94
  output << Jekyll::CodeExampleTags::example_markup(lang, example_content)
@@ -80,12 +102,13 @@ EOF
80
102
  def render(context)
81
103
  examples = {}
82
104
  context['page']['content'].scan(/\{%\s*code_example (\S+)\s*%\}/) do |name|
83
- more_examples = Jekyll::CodeExampleTags::code_examples(name[0], context['site'])
105
+ context_path, example_name = Jekyll::CodeExampleTags::get_example_name_and_context(name[0])
106
+ more_examples = Jekyll::CodeExampleTags::code_examples(context_path, example_name, context['site'])
84
107
  examples.merge!(more_examples){|key, pre_example, new_example| "#{pre_example}\n#{new_example}"}
85
108
  end
86
109
 
87
110
  # Build the code example elements
88
- output = Jekyll::CodeExampleTags::buttons_markup(examples)
111
+ output = Jekyll::CodeExampleTags::buttons_markup(examples, context)
89
112
  examples.each do |lang, paths|
90
113
  example_content = ""
91
114
  for path in paths.split("\n")
@@ -101,15 +124,10 @@ EOF
101
124
  class CodeExamplesJsFile < Jekyll::StaticFile
102
125
  def write(dest)
103
126
 
104
- if File.file?(File.join(FileUtils.pwd, @dir, @name))
105
- in_path = File.join(FileUtils.pwd, @dir, @name)
106
- else
107
- in_path = File.join(File.dirname(__FILE__), @dir, @name)
108
- end
109
127
  dest_path = File.join(dest, @dir, @name)
110
128
 
111
129
  FileUtils.mkdir_p(File.dirname(dest_path))
112
- content = File.read(in_path)
130
+ content = code_example_buttons_js(@site)
113
131
  File.open(dest_path, 'w') do |f|
114
132
  f.write(content)
115
133
  end
@@ -0,0 +1,24 @@
1
+ def code_example_buttons_js(site)
2
+ buttons_class = site.config['code_example_buttons_class'] ? site.config['code_example_buttons_class'] : 'buttons'
3
+ button_class = site.config['code_example_button_class'] ? site.config['code_example_button_class'] : 'button'
4
+
5
+ <<EOF
6
+ "use strict";
7
+
8
+ jQuery(function(){
9
+ jQuery('.#{buttons_class}.examples .#{button_class}').click(function(e){
10
+ e.preventDefault();
11
+ var parent = jQuery(this).closest('body');
12
+ var target = jQuery(this).attr('target');
13
+
14
+ parent.find('.example').hide();
15
+ parent.find('.example.'+target).show();
16
+ parent.find('.#{buttons_class}.examples .#{button_class}.active').removeClass('active');
17
+ parent.find('.#{buttons_class}.examples .#{button_class}[target="'+target+'"]').addClass('active');
18
+ });
19
+
20
+
21
+ jQuery('.#{buttons_class}.examples li:first-child .#{button_class}').click();
22
+ });
23
+ EOF
24
+ end
@@ -1,33 +1,88 @@
1
1
  require_relative './spec_helper.rb'
2
2
 
3
+ def check_code_example_conditions(o_obj, buttons_class: 'buttons', button_class: 'button')
4
+ expect(o_obj.xpath('/div[@class="code-examples"]/div[@class="'+buttons_class+' examples"]/ul/li/a[@class="'+button_class+'"][@target="ruby"][.="Ruby"]')).not_to be_empty
5
+ expect(o_obj.xpath('/div[@class="code-examples"]/div[@class="'+buttons_class+' examples"]/ul/li/a[@class="'+button_class+'"][@target="python"][.="Python"]')).not_to be_empty
6
+ ruby_example = o_obj.xpath('/div[@class="code-examples"]/div[@class="highlight example ruby"]/pre/code[@class="ruby"][@data-lang="ruby"]')
7
+ expect(ruby_example).not_to be_empty
8
+ expect(ruby_example.first.content).to eq 'puts "Hello World"'
9
+ python_example = o_obj.xpath('/div[@class="code-examples"]/div[@class="highlight example python"]/pre/code[@class="python"][@data-lang="python"]')
10
+ expect(python_example).not_to be_empty
11
+ expect(python_example.first.content).to eq 'print "Hello World"'
12
+ end
13
+
3
14
  describe 'code_example', fakefs: true do
4
15
 
5
16
  let(:page) { "{% code_example hello_world %}" }
6
17
 
7
18
  before(:all) do
8
19
  FakeFS.activate!
20
+ end
21
+
22
+ after(:all) do
23
+ FakeFS.deactivate!
24
+ end
9
25
 
26
+ it 'can be used' do
10
27
  FileUtils.mkdir_p('code_examples/ruby')
11
28
  FileUtils.mkdir_p('code_examples/python')
12
29
  File.open('code_examples/ruby/hello_world', 'w') { |f| f << 'puts "Hello World"'}
13
30
  File.open('code_examples/python/hello_world', 'w') { |f| f << 'print "Hello World"'}
31
+
32
+ t = Liquid::Template.parse(page)
33
+ o = t.render!({'site' => {}})
34
+ o_obj = Nokogiri::XML.parse(o)
35
+ check_code_example_conditions(o_obj)
14
36
  end
15
37
 
16
- after(:all) do
17
- FakeFS.deactivate!
38
+ it 'can be configured via "code_example_dir"' do
39
+ FileUtils.mkdir_p('examples/ruby')
40
+ FileUtils.mkdir_p('examples/python')
41
+ File.open('examples/ruby/hello_world', 'w') { |f| f << 'puts "Hello World"'}
42
+ File.open('examples/python/hello_world', 'w') { |f| f << 'print "Hello World"'}
43
+
44
+ t = Liquid::Template.parse(page)
45
+ o = t.render!({'site' => {'code_example_dir' => 'examples'}})
46
+ o_obj = Nokogiri::XML.parse(o)
47
+ check_code_example_conditions(o_obj)
18
48
  end
19
49
 
20
- it 'can be used' do
50
+ it 'can be configured via "code_example_button_class"' do
51
+ FileUtils.mkdir_p('code_examples/ruby')
52
+ FileUtils.mkdir_p('code_examples/python')
53
+ File.open('code_examples/ruby/hello_world', 'w') { |f| f << 'puts "Hello World"'}
54
+ File.open('code_examples/python/hello_world', 'w') { |f| f << 'print "Hello World"'}
55
+
56
+ t = Liquid::Template.parse(page)
57
+ o = t.render!({'site' => {'code_example_button_class' => 'button'}})
58
+ o_obj = Nokogiri::XML.parse(o)
59
+ check_code_example_conditions(o_obj, button_class: 'button')
60
+ end
61
+
62
+ it 'can be configured via "code_example_buttons_class"' do
63
+ FileUtils.mkdir_p('code_examples/ruby')
64
+ FileUtils.mkdir_p('code_examples/python')
65
+ File.open('code_examples/ruby/hello_world', 'w') { |f| f << 'puts "Hello World"'}
66
+ File.open('code_examples/python/hello_world', 'w') { |f| f << 'print "Hello World"'}
67
+
68
+ t = Liquid::Template.parse(page)
69
+ o = t.render!({'site' => {'code_example_buttons_class' => 'button-group'}})
70
+ o_obj = Nokogiri::XML.parse(o)
71
+ check_code_example_conditions(o_obj, buttons_class: 'button-group')
72
+ end
73
+
74
+
75
+ it 'allows for dividing examples via context' do
76
+ FileUtils.mkdir_p('code_examples/v1/ruby')
77
+ FileUtils.mkdir_p('code_examples/v1/python')
78
+ File.open('code_examples/v1/ruby/hello_world', 'w') { |f| f << 'puts "Hello World"'}
79
+ File.open('code_examples/v1/python/hello_world', 'w') { |f| f << 'print "Hello World"'}
80
+
81
+ page = "{% code_example v1/hello_world %}"
82
+
21
83
  t = Liquid::Template.parse(page)
22
84
  o = t.render!({'site' => {}})
23
85
  o_obj = Nokogiri::XML.parse(o)
24
- expect(o_obj.xpath('/div[@class="code-examples"]/div[@class="buttons examples"]/ul/li/a[@class="button"][@target="ruby"][.="Ruby"]')).not_to be_empty
25
- expect(o_obj.xpath('/div[@class="code-examples"]/div[@class="buttons examples"]/ul/li/a[@class="button"][@target="python"][.="Python"]')).not_to be_empty
26
- ruby_example = o_obj.xpath('/div[@class="code-examples"]/div[@class="highlight example ruby"]/pre/code[@class="language ruby"][@data-lang="ruby"]')
27
- expect(ruby_example).not_to be_empty
28
- expect(ruby_example.first.content).to eq 'puts "Hello World"'
29
- python_example = o_obj.xpath('/div[@class="code-examples"]/div[@class="highlight example python"]/pre/code[@class="language python"][@data-lang="python"]')
30
- expect(python_example).not_to be_empty
31
- expect(python_example.first.content).to eq 'print "Hello World"'
86
+ check_code_example_conditions(o_obj)
32
87
  end
33
88
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-code-example-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GovDelivery
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-02-03 00:00:00.000000000 Z
@@ -24,32 +24,48 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlentities
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  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
42
+ pages code examples for multiple languages that are\n kept in
43
+ separate files. Another tag allows you to combine\n all code
30
44
  examples that are on a page."
31
45
  email: support@govdelivery.com
32
46
  executables: []
33
47
  extensions: []
34
48
  extra_rdoc_files: []
35
49
  files:
50
+ - ".gitignore"
36
51
  - ".ruby-version"
37
52
  - ".travis.yml"
53
+ - CHANGELOG.md
38
54
  - Gemfile
39
55
  - Gemfile.lock
40
56
  - LICENSE.md
41
57
  - README.md
42
58
  - jekyll-code-example-tag.gemspec
43
59
  - lib/jekyll-code-example-tag.rb
44
- - lib/js/jekyll-code-example-buttons.js
60
+ - lib/js/jekyll-code-example-buttons.js.rb
45
61
  - spec/all_page_code_examples_spec.rb
46
62
  - spec/code_example_spec.rb
47
63
  - spec/spec_helper.rb
48
- homepage: https://github.com/govdelivery/jekyll-code-example-tag
64
+ homepage: https://github.com/Granicus/jekyll-code-example-tag
49
65
  licenses:
50
66
  - BSD-3-Clause
51
67
  metadata: {}
52
- post_install_message:
68
+ post_install_message:
53
69
  rdoc_options: []
54
70
  require_paths:
55
71
  - lib
@@ -57,16 +73,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
73
  requirements:
58
74
  - - ">="
59
75
  - !ruby/object:Gem::Version
60
- version: '0'
76
+ version: 2.3.0
61
77
  required_rubygems_version: !ruby/object:Gem::Requirement
62
78
  requirements:
63
79
  - - ">="
64
80
  - !ruby/object:Gem::Version
65
81
  version: '0'
66
82
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.4.5
69
- signing_key:
83
+ rubygems_version: 3.1.2
84
+ signing_key:
70
85
  specification_version: 4
71
86
  summary: Tags for including code examples in posts and pages.
72
87
  test_files: []
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- jQuery(function(){
4
- jQuery('.buttons.examples .button').click(function(e){
5
- e.preventDefault();
6
- var parent = jQuery(this).closest('body');
7
- var target = jQuery(this).attr('target');
8
-
9
- parent.find('.example').hide();
10
- parent.find('.example.'+target).show();
11
- parent.find('.buttons.examples .button.active').removeClass('active');
12
- parent.find('.buttons.examples .button[target="'+target+'"]').addClass('active');
13
- });
14
-
15
-
16
- jQuery('.buttons.examples li:first-child .button').click();
17
- });