nanoc-snippet 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +4 -2
  3. data/lib/nanoc-snippet.rb +8 -6
  4. metadata +17 -16
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04a868f1dfbd389afe8248b2e49b650d51caac0e
4
+ data.tar.gz: 6825ff2f46d24006668b63cf92bbb923a3c27029
5
+ SHA512:
6
+ metadata.gz: b8b46a81f210ceb0a446c3108dbb7b2a3520be90129d6eb30f929b8a7b50c8e80654639add455183c78fe79ad7288955cfc70881878f9ac4c493e7c2f947f92a
7
+ data.tar.gz: 13ce3b4a7d4d276a64c166fcd85319684cf83cf0186cf431fadf7c6cb631d235eb45447ddaf618f4a30fdb25d4ba8bd3a309784f387b54509e72d6faf0933826
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Show a snippet of one item.
4
4
 
5
- It use [nokogiri](http://nokogiri.org/).
5
+ It use [HTML-Truncator](https://github.com/nono/HTML-Truncator).
6
6
 
7
7
  ## Install
8
8
 
@@ -28,8 +28,10 @@ In your layout:
28
28
  <%= snippet(item) %>
29
29
  ```
30
30
 
31
+ Some options are available. See the code to see all.
32
+
31
33
  ## License
32
34
 
33
- (c) 2012 Stormz
35
+ (c) 2012-2015 Stormz
34
36
 
35
37
  This code is free to use under the terms of the MIT license
@@ -1,16 +1,18 @@
1
- require 'nokogiri'
1
+ require 'html_truncator'
2
2
 
3
3
  module Nanoc::Helpers
4
4
  module Snippet
5
- # Show a snippet of the item
6
- # It take the first paragraph of the item and return the first 150 words.
5
+ # Show a snippet of the item.
7
6
  #
8
7
  # item - the nanoc item
8
+ # options - options to customize the snippet (default: {})
9
+ # :nb_words - the number of words to keep
10
+ # all options valid for html_truncator
9
11
  #
10
12
  # Returns a snippet of the item
11
- def snippet(item)
12
- doc = Nokogiri::HTML(item.compiled_content)
13
- doc.xpath('//p/text()').to_a.join(" ").gsub("\r"," ").gsub("\n"," ")[0..150] + '...'
13
+ def snippet(item, options={})
14
+ nb_words = options.delete(:nb_words) || 10
15
+ HTML_Truncator.truncate(item.compiled_content, nb_words, options)
14
16
  end
15
17
  end
16
18
  end
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-snippet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - François de Metz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-13 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: nokogiri
16
- requirement: &22137480 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: html_truncator
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '0.4'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *22137480
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
25
27
  description:
26
28
  email: francois@2metz.fr
27
29
  executables: []
@@ -31,28 +33,27 @@ extra_rdoc_files:
31
33
  files:
32
34
  - README.md
33
35
  - lib/nanoc-snippet.rb
34
- homepage: https://github.com/stormz/nanoc-plugins
36
+ homepage: https://github.com/stormz/nanoc-snippet
35
37
  licenses: []
38
+ metadata: {}
36
39
  post_install_message:
37
40
  rdoc_options: []
38
41
  require_paths:
39
42
  - lib
40
43
  required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
44
  requirements:
43
- - - ! '>='
45
+ - - ">="
44
46
  - !ruby/object:Gem::Version
45
47
  version: '0'
46
48
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
49
  requirements:
49
- - - ! '>='
50
+ - - ">="
50
51
  - !ruby/object:Gem::Version
51
52
  version: '0'
52
53
  requirements: []
53
54
  rubyforge_project:
54
- rubygems_version: 1.8.10
55
+ rubygems_version: 2.2.2
55
56
  signing_key:
56
- specification_version: 3
57
+ specification_version: 4
57
58
  summary: Show a snippet of one nanoc item
58
59
  test_files: []