jekyll_quick_man 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/jekyll_quick_man.rb +146 -0
  2. metadata +47 -0
@@ -0,0 +1,146 @@
1
+ # encoding: utf-8
2
+ # The above is a 'magic encoding' that ensures support for special characters
3
+ # like umlauts in strings contained in this file.
4
+
5
+ module Jekyll
6
+ module Tags
7
+ class QuickManTag < Liquid::Tag
8
+
9
+ def initialize(tag_name, section_page_provider, tokens)
10
+ @section, @page, @provider = section_page_provider.split
11
+ @provider = @provider || ''
12
+ super
13
+ end
14
+
15
+ def render(context)
16
+ generate_anchor(context.registers[:site].config['man'])
17
+ end
18
+
19
+ def generate_anchor(man)
20
+ description = determine_description(man)
21
+ title = "#{@provider} Manpage zu#{determine_type} '#{@page}#{description}'"
22
+
23
+ href = determine_url
24
+
25
+ "<a title=\"#{title}\" href=\"#{href}\">#{@page}(#{@section})</a>"
26
+ end
27
+
28
+ def determine_description_via_whatis
29
+ man_path = "--manpath=`manpath --quiet --global`"
30
+ section = @section ? "--section #{@section}" : ''
31
+ # locale = "--locale=de"
32
+ thats_it = `whatis #{man_path} #{section} --long --systems=#{@provider},man #{@page} 2> /dev/null`
33
+
34
+ if thats_it
35
+ description = " - #{thats_it.split(/\) +-+ +/).last}"
36
+ description.gsub!(/\n\Z/,'')
37
+ end
38
+
39
+ description || nil
40
+ end
41
+
42
+ def determine_description_via_config(man)
43
+ if man
44
+ man_page = man[@page]
45
+
46
+ if man_page
47
+ if man_page.is_a?(Hash) && man_page.has_key?(@section.to_i)
48
+ # support for yaml paths like man.termios.4
49
+ description = " - #{man_page[@section.to_i]}"
50
+ else
51
+ # support for yaml paths like man.ssh
52
+ description = " - #{man_page}"
53
+ end
54
+ else
55
+ p "WARNING: Missing man page for '#{@page}'. Links will be generated without man descriptions."
56
+ end
57
+
58
+ else
59
+ p 'WARNING: Zero man pages defined in config file. Links will be generated without man descriptions.'
60
+ end
61
+
62
+ description || ''
63
+ end
64
+
65
+ def determine_description(man)
66
+ description = determine_description_via_whatis
67
+
68
+ unless description
69
+ p "whatis failed to find a descripton for #{@page}. Trying config file as a fall back ..."
70
+ description = determine_description_via_config(man)
71
+ end
72
+
73
+ description || ''
74
+ end
75
+
76
+
77
+ def determine_type
78
+ if @provider.downcase.eql? 'ubuntu'
79
+ get_type_linux
80
+ else
81
+ get_type_bsd
82
+ end
83
+ end
84
+
85
+ def get_type_linux
86
+ case @section.to_i
87
+ when 1
88
+ 'm Befehl'
89
+ when 2
90
+ 'm Systemaufruf'
91
+ when 3
92
+ 'm Bibliotheksaufruf'
93
+ when 4
94
+ 'r Spezialdatei'
95
+ when 5
96
+ 'm Dateiformat/zur Konvention'
97
+ when 6
98
+ 'm Spiel'
99
+ when 8
100
+ 'm Systemverwaltungsbefehl'
101
+ when 9
102
+ 'r Kernel-Routine'
103
+ else
104
+ # 7 Verschiedenes (einschließlich Makropaketen und Konventionen), z. B. man(7), groff(7)
105
+ ''
106
+ end
107
+ end
108
+
109
+ def get_type_bsd
110
+ case @section.to_i
111
+ when 1
112
+ 'm Benutzerkommando'
113
+ when 2
114
+ 'Systemaufruf oder Fehlernummer'
115
+ when 3
116
+ 'm Bibliotheksaufruf'
117
+ when 4
118
+ ' Gerätetreiber'
119
+ when 5
120
+ 'm Dateiformat/zur Konvention'
121
+ when 6
122
+ 'm Spiel'
123
+ when 8
124
+ 'm Systemverwaltungskommando'
125
+ when 9
126
+ 'r Kernel-Entwicklerhilfe'
127
+ else
128
+ # 7 Verschiedene Informationen
129
+ ''
130
+ end
131
+ end
132
+
133
+ def determine_url
134
+ case @provider.downcase
135
+ when 'ubuntu'
136
+ "http://manpages.ubuntu.com/manpages/#{@page}.#{@section}"
137
+ else
138
+ "http://www.freebsd.org/cgi/man.cgi?query=#{@page}&apropos=0&sektion=#{@section}&arch=default&format=latin1"
139
+ end
140
+ end
141
+
142
+ end
143
+ end
144
+ end
145
+
146
+ Liquid::Template.register_tag('man', Jekyll::Tags::QuickManTag)
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_quick_man
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - GSI
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Jekyll tag that renders pretty links to man page sources on the internet
15
+ email: rubygems.org@groovy-skills.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/jekyll_quick_man.rb
21
+ homepage: https://github.com/GSI/jekyll_quick_man
22
+ licenses:
23
+ - MIT
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Jekyll Quick Man
46
+ test_files: []
47
+ has_rdoc: