slippery 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,125 +6,127 @@
6
6
  # See https://github.com/3/blob/master/lib/kramdown/element.rb for a list of
7
7
  # types
8
8
  #
9
- class Slippery::Converter
10
- private_attr_accessor :type, :value, :attr, :children, :options
11
- undef_method :p
9
+ module Slippery
10
+ class Converter
11
+ attr_accessor :type, :value, :attr, :children, :options
12
+ undef_method :p
12
13
 
13
- # Convert a Kramdown syntax tree into Hexp.
14
- #
15
- # @example
16
- # markdown = "# Hello!\n\nChunky *bacon*!\n"
17
- # document = Kramdown::Document.new(markdown)
18
- # hexp = converter.convert(document.root)
19
- #
20
- # @param el [Kramdown::Element] The root element to convert
21
- # @return [Hexp::Node]
22
- # @api public
23
- #
24
- def convert(el)
25
- #Kernel.p el ; exit
26
- @type, @value, @attr, @children, @options =
27
- el.type, el.value, el.attr, el.children, el.options
28
- send(type)
29
- end
14
+ # Convert a Kramdown syntax tree into Hexp.
15
+ #
16
+ # @example
17
+ # markdown = "# Hello!\n\nChunky *bacon*!\n"
18
+ # document = Kramdown::Document.new(markdown)
19
+ # hexp = converter.convert(document.root)
20
+ #
21
+ # @param el [Kramdown::Element] The root element to convert
22
+ # @return [Hexp::Node]
23
+ # @api public
24
+ #
25
+ def convert(el)
26
+ #Kernel.p el ; exit
27
+ @type, @value, @attr, @children, @options =
28
+ el.type, el.value, el.attr, el.children, el.options
29
+ send(type)
30
+ end
30
31
 
31
- # Process a Kramdown :root type element
32
- #
33
- # @return [Hexp::Node]
34
- # @api semipublic
35
- #
36
- def root
37
- H[:html, [H[:head], tag!(:body)]]
38
- end
32
+ # Process a Kramdown :root type element
33
+ #
34
+ # @return [Hexp::Node]
35
+ # @api semipublic
36
+ #
37
+ def root
38
+ H[:html, [H[:head], tag!(:body)]]
39
+ end
39
40
 
40
- # Process a Kramdown :header type element
41
- #
42
- # @return [Hexp::Node]
43
- # @api semipublic
44
- #
45
- def header
46
- tag! "h#{options[:level]}".intern
47
- end
41
+ # Process a Kramdown :header type element
42
+ #
43
+ # @return [Hexp::Node]
44
+ # @api semipublic
45
+ #
46
+ def header
47
+ tag! "h#{options[:level]}".intern
48
+ end
48
49
 
49
- # Process a Kramdown :codeblock type element
50
- #
51
- # @return [Hexp::Node]
52
- # @api semipublic
53
- #
54
- def codeblock
55
- H[:pre, attr, H[:code, value]]
56
- end
50
+ # Process a Kramdown :codeblock type element
51
+ #
52
+ # @return [Hexp::Node]
53
+ # @api semipublic
54
+ #
55
+ def codeblock
56
+ H[:pre, attr, H[:code, value]]
57
+ end
57
58
 
58
- def smart_quote
59
- {
60
- :lsquo => '‘',
61
- :rsquo => '’',
62
- :ldquo => '“',
63
- :rdquo => '”',
64
- }[value]
65
- end
59
+ def smart_quote
60
+ {
61
+ :lsquo => '‘',
62
+ :rsquo => '’',
63
+ :ldquo => '“',
64
+ :rdquo => '”',
65
+ }[value]
66
+ end
66
67
 
67
- def typographic_sym
68
- {
69
- :hellip => '…',
70
- :mdash => '—',
71
- :ndash => '–',
72
- :laquo => '«',
73
- :raquo => '»',
74
- :laquo_space => '« ',
75
- :raquo_space => ' »',
76
- }[value]
77
- end
68
+ def typographic_sym
69
+ {
70
+ :hellip => '…',
71
+ :mdash => '—',
72
+ :ndash => '–',
73
+ :laquo => '«',
74
+ :raquo => '»',
75
+ :laquo_space => '« ',
76
+ :raquo_space => ' »',
77
+ }[value]
78
+ end
78
79
 
79
- def html_element
80
- H[value.to_sym, attr, convert_children]
81
- end
80
+ def html_element
81
+ H[value.to_sym, attr, convert_children]
82
+ end
82
83
 
83
- def entity
84
- value.char
85
- end
84
+ def entity
85
+ value.char
86
+ end
86
87
 
87
- def codespan
88
- H[:code, value]
89
- end
88
+ def codespan
89
+ H[:code, value]
90
+ end
90
91
 
91
- def xml_comment; end
92
+ def xml_comment; end
92
93
 
93
- # Create a Hexp::Node from the current element
94
- #
95
- # Helper for when you want to turn the Kramdown element straight into a
96
- # Hexp::Node with the same attributes, and a one-to-one mapping of the child
97
- # elements.
98
- #
99
- # @param tag [Symbol] The HTML tag to generate
100
- # @return [Hexp::Node]
101
- # @api semipublic
102
- #
103
- def tag!(tag)
104
- H[tag, attr, convert_children]
105
- end
94
+ # Create a Hexp::Node from the current element
95
+ #
96
+ # Helper for when you want to turn the Kramdown element straight into a
97
+ # Hexp::Node with the same attributes, and a one-to-one mapping of the child
98
+ # elements.
99
+ #
100
+ # @param tag [Symbol] The HTML tag to generate
101
+ # @return [Hexp::Node]
102
+ # @api semipublic
103
+ #
104
+ def tag!(tag)
105
+ H[tag, attr, convert_children]
106
+ end
106
107
 
107
- [:text, :blank, :raw].each do |sym|
108
- define_method sym do
109
- Hexp::TextNode.new(value)
108
+ [:text, :blank, :raw].each do |sym|
109
+ define_method sym do
110
+ Hexp::TextNode.new(value)
111
+ end
110
112
  end
111
- end
112
113
 
113
- [:p, :blockquote, :ul, :li, :ol, :dl, :dt, :dd, :em, :strong, :img, :a, :hr, :br].each do |sym|
114
- define_method sym do
115
- tag! type
114
+ [:p, :blockquote, :ul, :li, :ol, :dl, :dt, :dd, :em, :strong, :img, :a, :hr, :br].each do |sym|
115
+ define_method sym do
116
+ tag! type
117
+ end
116
118
  end
117
- end
118
119
 
119
- # Convert the children of the Kramdown element to Hexps
120
- #
121
- # In other words, recurse down the tree. This will pass each
122
- # child element into the converter.
123
- #
124
- # @return [Array<Hexp::Node>]
125
- # @api private
126
- #
127
- def convert_children
128
- children.map {|ch| convert ch }.compact
120
+ # Convert the children of the Kramdown element to Hexps
121
+ #
122
+ # In other words, recurse down the tree. This will pass each
123
+ # child element into the converter.
124
+ #
125
+ # @return [Array<Hexp::Node>]
126
+ # @api private
127
+ #
128
+ def convert_children
129
+ children.map {|ch| convert ch }.compact
130
+ end
129
131
  end
130
132
  end
@@ -2,8 +2,6 @@ module Slippery
2
2
  class Document
3
3
  include Hexp
4
4
 
5
- private_attr_accessor :processors
6
-
7
5
  def initialize(markdown)
8
6
  @markdown = markdown
9
7
  end
@@ -11,20 +11,18 @@ module Slippery
11
11
  def initialize(document, options = {})
12
12
  @document = document
13
13
  @options = DEFAULT_OPTIONS.merge(options).freeze
14
-
15
- Assets::embed_locally if @options[:local]
16
14
  end
17
15
 
18
16
  def processors
19
17
  {
20
18
  impress_js: [
21
19
  Processors::HrToSections.new(H[:div, class: 'step']),
22
- Processors::ImpressJs::AddImpressJs.new(Assets::path_composer(@options[:local]), js_options),
20
+ Processors::ImpressJs::AddImpressJs.new(js_options),
23
21
  (Processors::ImpressJs::AutoOffsets.new unless @options.fetch(:manual_offsets, false)),
24
22
  ].compact,
25
23
  reveal_js: [
26
24
  Processors::HrToSections.new(H[:section]),
27
- Processors::RevealJs::AddRevealJs.new(Assets::path_composer(@options[:local]), js_options),
25
+ Processors::RevealJs::AddRevealJs.new(js_options),
28
26
  ]
29
27
  }[@options[:type]]
30
28
  end
@@ -4,6 +4,10 @@ module Slippery
4
4
  klz.extend ClassMethods
5
5
  end
6
6
 
7
+ def asset_uri(path)
8
+ "file://" + Slippery::ROOT.join('assets', path).to_s
9
+ end
10
+
7
11
  def include_local_javascript(element, path)
8
12
  element.add javascript_include_tag(path)
9
13
  end
@@ -14,8 +14,8 @@ module Slippery
14
14
 
15
15
  def call(doc)
16
16
  doc
17
- .rewrite(@selector, &create_svg_from_dot)
18
- .rewrite('polygon[fill=white][stroke=white]') { [] }
17
+ .replace(@selector, &create_svg_from_dot)
18
+ .replace('polygon[fill=white][stroke=white]') { [] }
19
19
  end
20
20
 
21
21
  def create_svg_from_dot
@@ -14,14 +14,13 @@ module Slippery
14
14
  'transition-duration' => 1000
15
15
  }.freeze
16
16
 
17
- def initialize(path_composer, attributes = {})
18
- @path_composer = path_composer
19
- @attributes = DEFAULT_ATTRS.merge(attributes).freeze
17
+ def initialize(attributes = {})
18
+ @attributes = DEFAULT_ATTRS.merge(attributes).freeze
20
19
  end
21
20
 
22
21
  def call(doc)
23
22
  doc.replace('body') do |body|
24
- include_local_javascript(body, @path_composer.call('impress.js/js/impress.js'))
23
+ include_local_javascript(body, asset_uri('impress.js/js/impress.js'))
25
24
  .set_attrs({id: 'impress'}.merge(data_attributes(attributes)))
26
25
  .add H[:script, 'impress().init();']
27
26
  end
@@ -12,8 +12,7 @@ module Slippery
12
12
 
13
13
  DEFAULT_OPTIONS = {theme: 'default'}.freeze
14
14
 
15
- def initialize(path_composer, options = {})
16
- @path_composer = path_composer
15
+ def initialize(options = {})
17
16
  @options = DEFAULT_OPTIONS.merge(options).freeze
18
17
  end
19
18
 
@@ -28,16 +27,16 @@ module Slippery
28
27
  end
29
28
 
30
29
  processor :add_reveal_js, 'body' do |body|
31
- body = include_local_javascript(body, @path_composer.call('reveal.js/lib/js/head.min.js'))
32
- include_local_javascript(body, @path_composer.call('reveal.js/js/reveal.js'))
30
+ body = include_local_javascript(body, asset_uri('reveal.js/lib/js/head.min.js'))
31
+ include_local_javascript(body, asset_uri('reveal.js/js/reveal.js'))
33
32
  end
34
33
 
35
34
  processor :add_reveal_css, 'head' do |head|
36
- include_local_css(head, @path_composer.call('reveal.js/css/reveal.min.css'))
35
+ include_local_css(head, asset_uri('reveal.js/css/reveal.min.css'))
37
36
  end
38
37
 
39
38
  processor :add_theme, 'head' do |head|
40
- include_local_css(head, @path_composer.call("reveal.js/css/theme/#{@options[:theme]}.css"))
39
+ include_local_css(head, asset_uri("reveal.js/css/theme/#{@options[:theme]}.css"))
41
40
  end
42
41
 
43
42
  processor :add_settings, 'body' do |body|
@@ -27,10 +27,11 @@ module Slippery
27
27
  end
28
28
 
29
29
  def markdown_to_hexp(infile, options = {})
30
+ @infile = infile
30
31
  doc = Slippery::Document.new(infile.read)
31
32
  doc = Slippery::Presentation.new(doc, @options.merge(options))
32
33
 
33
- doc.process(*processors.reject {|pr| options[:skip_self_contained] && pr == Slippery::Processors::SelfContained})
34
+ doc.process(*processors)
34
35
  end
35
36
 
36
37
  def processor(selector, &blk)
@@ -41,9 +42,19 @@ module Slippery
41
42
  end
42
43
  end
43
44
 
44
- def self_contained
45
- processors << Slippery::Processors::SelfContained
45
+ def include_assets
46
+ processors << method(:call_asset_packer)
46
47
  end
48
+ alias self_contained include_assets
49
+
50
+ def call_asset_packer(doc)
51
+ AssetPacker::Processor::Local.new(
52
+ @infile.to_s,
53
+ @infile.dirname.join('assets'),
54
+ @infile
55
+ ).(doc)
56
+ end
57
+
47
58
 
48
59
  def title(title)
49
60
  processor 'head' do |head|
@@ -1,3 +1,3 @@
1
1
  module Slippery
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -17,11 +17,13 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = `git ls-files -- spec`.split($/)
18
18
  gem.extra_rdoc_files = %w[README.md LICENSE]
19
19
 
20
- gem.add_runtime_dependency 'hexp' , '~> 0.0'
21
- gem.add_runtime_dependency 'kramdown' , '~> 1.1'
22
- gem.add_runtime_dependency 'rb-inotify'
23
- gem.add_runtime_dependency 'rake' , '~> 10.1'
20
+ gem.add_runtime_dependency 'hexp' , '~> 0.3.3'
21
+ gem.add_runtime_dependency 'kramdown' , '~> 1.1'
22
+ gem.add_runtime_dependency 'rake' , '~> 10.1'
23
+ gem.add_runtime_dependency 'rb-inotify' , '~> 0.9.3'
24
+ gem.add_runtime_dependency 'concord' , '~> 0.1.4'
25
+ gem.add_runtime_dependency 'asset_packer' , '~> 0.1.0'
24
26
 
25
- gem.add_development_dependency 'rspec', '~> 2.14'
26
- gem.add_development_dependency 'rubygems-tasks'
27
+ gem.add_development_dependency 'rspec' , '~> 2.14'
28
+ gem.add_development_dependency 'mutant-rspec' , '~> 0.5.3'
27
29
  end
@@ -1,5 +1,5 @@
1
1
  require 'slippery'
2
- require 'devtools/spec_helper'
2
+ #require 'devtools/spec_helper'
3
3
 
4
4
  # Helper to load markdown files under spec/fixtures
5
5
  #
metadata CHANGED
@@ -1,31 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slippery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-06 00:00:00.000000000 Z
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- prerelease: false
15
14
  name: hexp
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - ~>
19
18
  - !ruby/object:Gem::Version
20
- version: '0.0'
19
+ version: 0.3.3
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0.0'
26
+ version: 0.3.3
27
27
  - !ruby/object:Gem::Dependency
28
- prerelease: false
29
28
  name: kramdown
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
@@ -33,41 +32,69 @@ dependencies:
33
32
  - !ruby/object:Gem::Version
34
33
  version: '1.1'
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.1'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :runtime
42
49
  prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
43
56
  name: rb-inotify
44
57
  requirement: !ruby/object:Gem::Requirement
45
58
  requirements:
46
- - - ! '>='
59
+ - - ~>
47
60
  - !ruby/object:Gem::Version
48
- version: '0'
61
+ version: 0.9.3
49
62
  type: :runtime
63
+ prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ! '>='
66
+ - - ~>
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 0.9.3
55
69
  - !ruby/object:Gem::Dependency
56
- prerelease: false
57
- name: rake
70
+ name: concord
58
71
  requirement: !ruby/object:Gem::Requirement
59
72
  requirements:
60
73
  - - ~>
61
74
  - !ruby/object:Gem::Version
62
- version: '10.1'
75
+ version: 0.1.4
63
76
  type: :runtime
77
+ prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ~>
67
81
  - !ruby/object:Gem::Version
68
- version: '10.1'
82
+ version: 0.1.4
69
83
  - !ruby/object:Gem::Dependency
84
+ name: asset_packer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :runtime
70
91
  prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ - !ruby/object:Gem::Dependency
71
98
  name: rspec
72
99
  requirement: !ruby/object:Gem::Requirement
73
100
  requirements:
@@ -75,25 +102,26 @@ dependencies:
75
102
  - !ruby/object:Gem::Version
76
103
  version: '2.14'
77
104
  type: :development
105
+ prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - ~>
81
109
  - !ruby/object:Gem::Version
82
110
  version: '2.14'
83
111
  - !ruby/object:Gem::Dependency
84
- prerelease: false
85
- name: rubygems-tasks
112
+ name: mutant-rspec
86
113
  requirement: !ruby/object:Gem::Requirement
87
114
  requirements:
88
- - - ! '>='
115
+ - - ~>
89
116
  - !ruby/object:Gem::Version
90
- version: '0'
117
+ version: 0.5.3
91
118
  type: :development
119
+ prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - ! '>='
122
+ - - ~>
95
123
  - !ruby/object:Gem::Version
96
- version: '0'
124
+ version: 0.5.3
97
125
  description: Make presentations with Markdown
98
126
  email:
99
127
  - arne@arnebrasseur.net
@@ -103,10 +131,9 @@ extra_rdoc_files:
103
131
  - README.md
104
132
  - LICENSE
105
133
  files:
106
- - .bundle/install.log
134
+ - .gitignore
107
135
  - .travis.yml
108
136
  - Gemfile
109
- - Gemfile.devtools
110
137
  - Gemfile.lock
111
138
  - LICENSE
112
139
  - README.md
@@ -176,7 +203,6 @@ files:
176
203
  - config/rubocop.yml
177
204
  - config/yardstick.yml
178
205
  - lib/slippery.rb
179
- - lib/slippery/assets.rb
180
206
  - lib/slippery/converter.rb
181
207
  - lib/slippery/document.rb
182
208
  - lib/slippery/presentation.rb
@@ -188,7 +214,6 @@ files:
188
214
  - lib/slippery/processors/impress_js/add_impress_js.rb
189
215
  - lib/slippery/processors/impress_js/auto_offsets.rb
190
216
  - lib/slippery/processors/reveal_js/add_reveal_js.rb
191
- - lib/slippery/processors/self_contained.rb
192
217
  - lib/slippery/rake_tasks.rb
193
218
  - lib/slippery/version.rb
194
219
  - slippery.gemspec
@@ -199,8 +224,7 @@ files:
199
224
  - spec/fixtures/headers.md
200
225
  - spec/fixtures/ordered_list.md
201
226
  - spec/fixtures/unordered_list.md
202
- - spec/slippery/converter_spec.rb
203
- - spec/slippery_spec.rb
227
+ - spec/integration/slippery/converter_spec.rb
204
228
  - spec/spec_helper.rb
205
229
  homepage: https://github.com/plexus/slippery
206
230
  licenses:
@@ -212,17 +236,17 @@ require_paths:
212
236
  - lib
213
237
  required_ruby_version: !ruby/object:Gem::Requirement
214
238
  requirements:
215
- - - ! '>='
239
+ - - '>='
216
240
  - !ruby/object:Gem::Version
217
241
  version: '0'
218
242
  required_rubygems_version: !ruby/object:Gem::Requirement
219
243
  requirements:
220
- - - ! '>='
244
+ - - '>='
221
245
  - !ruby/object:Gem::Version
222
246
  version: '0'
223
247
  requirements: []
224
248
  rubyforge_project:
225
- rubygems_version: 2.2.1
249
+ rubygems_version: 2.0.14
226
250
  signing_key:
227
251
  specification_version: 4
228
252
  summary: Make presentations with Markdown
@@ -234,6 +258,5 @@ test_files:
234
258
  - spec/fixtures/headers.md
235
259
  - spec/fixtures/ordered_list.md
236
260
  - spec/fixtures/unordered_list.md
237
- - spec/slippery/converter_spec.rb
238
- - spec/slippery_spec.rb
261
+ - spec/integration/slippery/converter_spec.rb
239
262
  - spec/spec_helper.rb