jekyll-code-example-tag 0.0.5 → 0.0.6

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: f78a0b35d2b5412c1ee9037a9d9e00dfd1475544
4
- data.tar.gz: f88e066633873bc16b1f2f4302977968c5ff4f95
3
+ metadata.gz: 445ae1847daf8f0cf13a31c1e42f271db93c35f7
4
+ data.tar.gz: 19112d1ad9e6f7dde6050e70c4b3f6f218eff2d5
5
5
  SHA512:
6
- metadata.gz: 6aa90895e3fc7074828bd7f7ea02261b2c56b812d52d3403402aa1f120707b755359b8612b587b66be08b6f8aba4201fcb40afc8deeffa4fca608e9688e2e393
7
- data.tar.gz: 9ce37f352f410ab46dbc01b2cf314a3f05f7f04d69a48630739fdbb948bf82b7a2632df0c97b1183ac06e6b4a0ec6e2192e372252cfe4d713cf45be5ed2dc481
6
+ metadata.gz: 33c5c0e3de929fe09bb757ca32845b8bd74f79ab8f610cede0640ec42dd6ad1712bbe7ab13d4d9a3ad1007e09703c8922c5ffbe0e56776572c55f2cc4ce83fc7
7
+ data.tar.gz: cb04d87c67fad9f267df293bb4e9e4751ed2da5a0494e7c8e7e9d2dfa51d5816ac3c2fc861f867db3043d34fa2b4520b661ec9c97ba84fbc6d6c3e7fe987c758
@@ -0,0 +1,12 @@
1
+ CHANGELOG
2
+ ==========
3
+
4
+ This project does *not* adhere to Semantic Versioning
5
+
6
+ ## 0.0.6 - 2015-03-16
7
+
8
+ ### Added
9
+
10
+ - CSS classes applied to buttons and button container elements can now be
11
+ configured via _config.yml. Supporting JavaScript also uses classes set in
12
+ _config.yml.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-code-example-tag (0.0.5)
4
+ jekyll-code-example-tag (0.0.6)
5
5
  jekyll
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -32,6 +32,20 @@ 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
+
35
49
  ### code_example
36
50
 
37
51
  First, select a folder to place your code examples in. By default, the top
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jekyll-code-example-tag'
3
- s.version = '0.0.5'
3
+ s.version = '0.0.6'
4
4
  s.date = '2015-02-03'
5
5
  s.authors = ['GovDelivery']
6
6
  s.email = 'support@govdelivery.com'
@@ -1,3 +1,5 @@
1
+ require_relative 'js/jekyll-code-example-buttons.js.rb'
2
+
1
3
  module Jekyll
2
4
  module CodeExampleTags
3
5
 
@@ -28,13 +30,16 @@ module Jekyll
28
30
  examples
29
31
  end
30
32
 
31
- def self.buttons_markup(examples)
33
+ def self.buttons_markup(examples, context)
34
+ site = context['site']
35
+ buttons_class = site['code_example_buttons_class'] ? site['code_example_buttons_class'] : 'buttons'
36
+ button_class = site['code_example_button_class'] ? site['code_example_button_class'] : 'button'
32
37
  menu_items = ""
33
38
  examples.each_key do |lang|
34
- menu_items << "<li><a href='#' class='button' target='#{lang}'>#{lang.capitalize}</a></li>"
39
+ menu_items << "<li><a href='#' class='#{button_class}' target='#{lang}'>#{lang.capitalize}</a></li>"
35
40
  end
36
41
  <<EOF
37
- <div class="buttons examples">
42
+ <div class="#{buttons_class} examples">
38
43
  <ul>
39
44
  #{menu_items}
40
45
  </ul>
@@ -80,7 +85,7 @@ EOF
80
85
  examples = Jekyll::CodeExampleTags::code_examples(@context_path, @example_name, context['site'])
81
86
 
82
87
  # Build the code example elements
83
- output = Jekyll::CodeExampleTags::buttons_markup(examples)
88
+ output = Jekyll::CodeExampleTags::buttons_markup(examples, context)
84
89
  examples.each do |lang, path|
85
90
  example_content = File.read(path)
86
91
  output << Jekyll::CodeExampleTags::example_markup(lang, example_content)
@@ -100,7 +105,7 @@ EOF
100
105
  end
101
106
 
102
107
  # Build the code example elements
103
- output = Jekyll::CodeExampleTags::buttons_markup(examples)
108
+ output = Jekyll::CodeExampleTags::buttons_markup(examples, context)
104
109
  examples.each do |lang, paths|
105
110
  example_content = ""
106
111
  for path in paths.split("\n")
@@ -116,15 +121,10 @@ EOF
116
121
  class CodeExamplesJsFile < Jekyll::StaticFile
117
122
  def write(dest)
118
123
 
119
- if File.file?(File.join(FileUtils.pwd, @dir, @name))
120
- in_path = File.join(FileUtils.pwd, @dir, @name)
121
- else
122
- in_path = File.join(File.dirname(__FILE__), @dir, @name)
123
- end
124
124
  dest_path = File.join(dest, @dir, @name)
125
125
 
126
126
  FileUtils.mkdir_p(File.dirname(dest_path))
127
- content = File.read(in_path)
127
+ content = code_example_buttons_js(@site)
128
128
  File.open(dest_path, 'w') do |f|
129
129
  f.write(content)
130
130
  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,8 +1,8 @@
1
1
  require_relative './spec_helper.rb'
2
2
 
3
- def check_code_example_conditions(o_obj)
4
- expect(o_obj.xpath('/div[@class="code-examples"]/div[@class="buttons examples"]/ul/li/a[@class="button"][@target="ruby"][.="Ruby"]')).not_to be_empty
5
- expect(o_obj.xpath('/div[@class="code-examples"]/div[@class="buttons examples"]/ul/li/a[@class="button"][@target="python"][.="Python"]')).not_to be_empty
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
6
  ruby_example = o_obj.xpath('/div[@class="code-examples"]/div[@class="highlight example ruby"]/pre/code[@class="language ruby"][@data-lang="ruby"]')
7
7
  expect(ruby_example).not_to be_empty
8
8
  expect(ruby_example.first.content).to eq 'puts "Hello World"'
@@ -47,6 +47,31 @@ describe 'code_example', fakefs: true do
47
47
  check_code_example_conditions(o_obj)
48
48
  end
49
49
 
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
+
50
75
  it 'allows for dividing examples via context' do
51
76
  FileUtils.mkdir_p('code_examples/v1/ruby')
52
77
  FileUtils.mkdir_p('code_examples/v1/python')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-code-example-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - GovDelivery
@@ -35,13 +35,14 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - ".ruby-version"
37
37
  - ".travis.yml"
38
+ - CHANGELOG
38
39
  - Gemfile
39
40
  - Gemfile.lock
40
41
  - LICENSE.md
41
42
  - README.md
42
43
  - jekyll-code-example-tag.gemspec
43
44
  - lib/jekyll-code-example-tag.rb
44
- - lib/js/jekyll-code-example-buttons.js
45
+ - lib/js/jekyll-code-example-buttons.js.rb
45
46
  - spec/all_page_code_examples_spec.rb
46
47
  - spec/code_example_spec.rb
47
48
  - spec/spec_helper.rb
@@ -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
- });