nanoc-snippet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +15 -0
  2. data/lib/nanoc/helpers/snippet.rb +16 -0
  3. metadata +58 -0
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Snippet
2
+
3
+ Show a snippet of one item.
4
+
5
+ It use [nokogiri](http://nokogiri.org/).
6
+
7
+ ```ruby
8
+ <%= snippet(item) %>
9
+ ```
10
+
11
+ ## License
12
+
13
+ (c) 2012 Stormz
14
+
15
+ This code is free to use under the terms of the MIT license
@@ -0,0 +1,16 @@
1
+ require 'nokogiri'
2
+
3
+ module Nanoc::Helpers
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.
7
+ #
8
+ # item - the nanoc item
9
+ #
10
+ # 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] + '...'
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-snippet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - François de Metz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &12620520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *12620520
25
+ description:
26
+ email: francois@2metz.fr
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files:
30
+ - README.md
31
+ files:
32
+ - README.md
33
+ - lib/nanoc/helpers/snippet.rb
34
+ homepage: https://github.com/stormz/nanoc-plugins
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.8.10
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Show a snippet of one nanoc item
58
+ test_files: []