capiru 0.0.1 → 0.0.2

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: 6631faf3bc730a21de135f1dc2e9d08a752f2b97
4
- data.tar.gz: 25f4df9754531fa891bf4a609a673135cb40ba2e
3
+ metadata.gz: d75b8e844132d6ad6ada85747dc262edd2c49d79
4
+ data.tar.gz: 20548efe0da7748c2d8ca5f5b9bc5cce81964e2e
5
5
  SHA512:
6
- metadata.gz: bb4c2989e4778bc2b404f93938fe42df3eb629b4d16f4a7e9db5ae2e9cd407fd5e7183f757318621b09cd15d575ef1eb53a3d348f583d02c952068199d131cc0
7
- data.tar.gz: d3090b53121701035aa9e2763c63e2c2f22c054c80c7b0344512e32c80ad635560b76759686ab81002d43364636bb1f266b8953dda639946f970908d00083f33
6
+ metadata.gz: 1bdda05ce6ca878d1e36067f195e5f519aba6c3f6270202d0bf7bf499581038cc9065ba1be32391f46acd91afe3235f8cf9c03a03a1f1296d5b09d28bafa21bf
7
+ data.tar.gz: 24d0f56e1f3b141ffec9a2de20b4e76e4639f043b25a475718cf0257d2bff43f534f559770bf3d91752ce15ffeb3414aec27b4c7659a1f05334cfd52bd9eba1f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capiru (0.0.1)
4
+ capiru (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -20,6 +20,7 @@ GEM
20
20
  multi_json (1.8.4)
21
21
  multi_test (0.0.3)
22
22
  mustache (0.99.5)
23
+ rake (0.9.6)
23
24
  rdiscount (2.1.7)
24
25
  ronn (0.7.3)
25
26
  hpricot (>= 0.8.2)
@@ -40,5 +41,6 @@ PLATFORMS
40
41
  DEPENDENCIES
41
42
  capiru!
42
43
  cucumber
44
+ rake
43
45
  ronn (~> 0.7.3)
44
46
  rspec
data/Rakefile CHANGED
@@ -0,0 +1,54 @@
1
+ require "capiru"
2
+ require "open3"
3
+
4
+ namespace :ref do
5
+
6
+ desc "build the reference pages"
7
+ task :build do
8
+ # set locale
9
+ locale = ENV['LOCALE']
10
+ unless locale
11
+ printf "enter locale: "
12
+ locale = $stdin.gets.chomp!.downcase
13
+ end
14
+
15
+ # set the base locale directory
16
+ base_dir = File.join(Capiru::REFERENCE_ROOT, locale)
17
+ man_dir = File.join(Capiru::MAN_ROOT, locale)
18
+ unless Dir.exists?(base_dir)
19
+ puts "Directory #{base_dir} does not exist."
20
+ exit(1)
21
+ end
22
+
23
+ # Create directory for locale if it doesn't already exist
24
+ unless Dir.exists?(man_dir)
25
+ puts "Creating new directory: #{man_dir}"
26
+ Dir.mkdir(man_dir)
27
+ end
28
+
29
+ # Run ronn on each ronn file
30
+ Dir["#{base_dir}/*"].each do |doc|
31
+ filename = File.basename(doc).split(".")[0]
32
+ cmd = "ronn -r --pipe #{doc}"
33
+ out, err, process = Open3.capture3(cmd)
34
+
35
+ # Handle Errors
36
+ unless process.success?
37
+ puts "Something went wrong while processing #{doc}"
38
+ puts "Command: #{cmd}"
39
+ puts "Error: #{err}"
40
+ end
41
+
42
+ puts out.inspect
43
+
44
+ # Write output to man directory
45
+ path = File.join(man_dir, filename)
46
+ File.open(path, "w:UTF-8") do |f|
47
+ f.write(out)
48
+ end
49
+ puts "wrote file: #{path}"
50
+ end
51
+
52
+ end
53
+
54
+ end
data/bin/capiru CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "capiru"
3
3
 
4
- capiru_app = Capiru::CLI.new(ARGV)
5
- capiru_app.run
4
+ capiru_app = Capiru::CLI.new(ARGV, ENV)
5
+ capiru_app.run
@@ -27,8 +27,10 @@ Gem::Specification.new do |spec|
27
27
  # DEVELOPMENT DEPENDENCIES
28
28
  spec.add_development_dependency "cucumber"
29
29
  spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "ronn", "~> 0.7.3"
30
32
 
31
33
  # RUNTIME DEPENDENCIES
32
- spec.add_runtime_dependency "ronn", "~> 0.7.3"
34
+
33
35
 
34
36
  end
@@ -1,10 +1,18 @@
1
1
  module Capiru
2
2
 
3
- # Constants
4
- Root = File.expand_path("../../", __FILE__ )
5
- autoload :VERSION, "capiru/version"
3
+ # CONSTANTS
4
+ ROOT = File.expand_path("../../", __FILE__ )
5
+ REFERENCE_ROOT = File.join(ROOT, 'reference')
6
+ MAN_ROOT = File.join(ROOT, 'man')
7
+
8
+ # ERRORS
9
+ class TermNotFound < StandardError; ;end
6
10
 
7
- # Application
11
+ # VERSION
12
+ autoload :VERSION, "capiru/version"
13
+
14
+ # APPLICATIONS
8
15
  autoload :Application, "capiru/application"
9
16
  autoload :CLI, "capiru/cli"
17
+
10
18
  end
@@ -1,5 +1,6 @@
1
1
  module Capiru
2
2
  class Application
3
+ EXIT_FAILURE = 1
3
4
 
4
5
  def run
5
6
  raise "Implement"
@@ -1,27 +1,112 @@
1
1
  require "ronn"
2
+ require "optparse"
3
+ require "ostruct"
2
4
 
3
5
  module Capiru
4
6
  class CLI < Application
5
7
 
6
- def initialize(args)
7
- @arguments = args
8
- @document = nil
9
- @filename = args[0]
8
+ attr_accessor :options, :parser, :search_path, :status, :environment
9
+
10
+ def has_man?
11
+ `which man`
12
+ $?.success?
13
+ end
14
+
15
+
16
+ def initialize(args, env)
17
+ @environment = env
18
+ set_default_options
19
+ self.parser = build_options_parser
10
20
  end
11
21
 
12
22
 
13
23
  def run
14
- path = path_for_search(@filename)
15
- @document = Ronn::Document.new(path)
16
- @document_path = @document.path_for("roff")
17
- system("man #{@document_path}")
18
- $?.exitstatus
24
+
25
+ # Parse options and args/env vars
26
+ parse
27
+
28
+ # Set the search path for queries
29
+ set_search_path_for_queries(options.locale)
30
+
31
+ # Run Program
32
+ begin
33
+ if options.query
34
+ match = run_single_query(options.query)
35
+ cmd = "man #{match}"
36
+ system(cmd)
37
+ self.status = $?
38
+ elsif options.regexp
39
+ # TODO: Implement
40
+ else
41
+ # NOOP
42
+ end
43
+ rescue Capiru::TermNotFound => ex
44
+ puts "Error: #{ex.message}"
45
+ exit(EXIT_FAILURE)
46
+ end
47
+ self.status.exitstatus
48
+ end
49
+
50
+
51
+ def run_single_query(query)
52
+ file = File.join(self.search_path, query)
53
+ raise Capiru::TermNotFound, "No results for #{query} in #{options.locale} locale" unless File.exists?(file)
54
+ file
55
+ end
56
+
57
+ def parse
58
+ begin
59
+ parser.parse!
60
+ rescue => ex
61
+ puts "Error: #{ex.message}"
62
+ exit(EXIT_FAILURE)
63
+ end
64
+ end
65
+
66
+ def set_default_options
67
+ self.options = OpenStruct.new
68
+ self.options.query = false
69
+ self.options.regexp = false
70
+ self.options.locale = get_system_locale || "en"
71
+ end
72
+
73
+ def build_options_parser
74
+ OptionParser.new do |opts|
75
+ opts.banner = "Usage: capiru [options]"
76
+
77
+ # Display Help Information
78
+ opts.on("-h", "--help", "Show usage information") do
79
+ puts opts
80
+ exit(EXIT_FAILURE)
81
+ end
82
+
83
+ # Set the search Query
84
+ opts.on("-q", "--query TERM", "Search the documentation for a specific term") do |term|
85
+ options.query = term
86
+ end
87
+
88
+ # Use a Regex Query
89
+ opts.on("-r", "--regexp REGEXP", "Seach the documentatino for terms matching REGEXP") do |regexp|
90
+ options.regexp = Regexp.new(regexp)
91
+ end
92
+
93
+ # Set the locale
94
+ opts.on("-l", "--locale LOCALE", "Return documentation in the given locale") do |locale|
95
+ options.locale = locale
96
+ end
97
+
98
+ end
19
99
  end
20
100
 
101
+ def set_search_path_for_queries(locale="en")
102
+ @search_path = File.join(MAN_ROOT, locale)
103
+ end
21
104
 
22
- def path_for_search(filename, locale="en")
23
- File.join(Root, "reference/#{locale}", "#{filename}.ronn")
105
+ def get_system_locale
106
+ locale = @environment['LANG']
107
+ locale = locale[0..1] if locale && locale.is_a?(String)
108
+ locale
24
109
  end
25
110
 
26
111
  end
27
- end
112
+ end
@@ -1,3 +1,3 @@
1
1
  module Capiru
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,39 @@
1
+ '\" -*- coding: UTF-8 -*-
2
+ .\" generated with Ronn/v0.7.3
3
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
4
+ .
5
+ .TH "RB_TYPE" "" "February 2014" "" ""
6
+ .
7
+ .SH "NAME"
8
+ \fBrb_type\fR \- liefert den Integerwert eines ruby internen Typs zurück
9
+ .
10
+ .SH "ÜBERSICHT"
11
+ \fBstatic inline int rb_type(VALUE obj);\fR
12
+ .
13
+ .SH "BESCHREIBUNG"
14
+ Die rb_type Methode nimmt ein Ruby Object als einziges Argument und liefert den Integerwert dessen internen ruby repräsentation zurück\. Der Integerwert ist einer der ruby Typendefinitionen bsw\. T_STRING für Stringobjekte, T_NIL für NilClassobjekte, T_SYMBOL für Symbolobjekte, usw\.
15
+ .
16
+ .SH "BEISPIELE"
17
+ VALUE gruesse = rb_str_new2("Hallo freundchen!");
18
+ .
19
+ .P
20
+ if( rb_type(gruesse) == T_STRING ) {
21
+ .
22
+ .IP "" 4
23
+ .
24
+ .nf
25
+
26
+ printf("Gruesse von einem Ruby String\.");
27
+ .
28
+ .fi
29
+ .
30
+ .IP "" 0
31
+ .
32
+ .P
33
+ }
34
+ .
35
+ .SH "AUTOR"
36
+ John Faucett
37
+ .
38
+ .SH "SIEHE AUCH"
39
+ ruby_value_type(3)
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "RB_TYPE" "1" "February 2014" "" ""
4
+ .TH "RB_TYPE" "" "February 2014" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBrb_type\fR \- return the integer value of a ruby type
@@ -0,0 +1,29 @@
1
+ rb_type -- liefert den Integerwert eines ruby internen Typs zurück
2
+ ======================================================
3
+
4
+ ## ÜBERSICHT
5
+
6
+ `static inline int rb_type(VALUE obj);`
7
+
8
+ ## BESCHREIBUNG
9
+
10
+ Die rb_type Methode nimmt ein Ruby Object als einziges Argument und liefert
11
+ den Integerwert dessen internen ruby repräsentation zurück. Der Integerwert ist einer der
12
+ ruby Typendefinitionen bsw. T_STRING für Stringobjekte, T_NIL für NilClassobjekte, T_SYMBOL
13
+ für Symbolobjekte, usw.
14
+
15
+ ## BEISPIELE
16
+
17
+ VALUE gruesse = rb_str_new2("Hallo freundchen!");
18
+
19
+ if( rb_type(gruesse) == T_STRING ) {
20
+
21
+ printf("Gruesse von einem Ruby String.");
22
+
23
+ }
24
+
25
+ ## AUTOR
26
+ John Faucett
27
+
28
+ ## SIEHE AUCH
29
+ ruby_value_type(3)
@@ -1,4 +1,4 @@
1
- rb_type(1) -- return the integer value of a ruby type
1
+ rb_type -- return the integer value of a ruby type
2
2
  ======================================================
3
3
 
4
4
  ## SYNOPSIS
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capiru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Faucett
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: ronn
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +59,7 @@ dependencies:
45
59
  - - ~>
46
60
  - !ruby/object:Gem::Version
47
61
  version: 0.7.3
48
- type: :runtime
62
+ type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
@@ -72,8 +86,9 @@ files:
72
86
  - lib/capiru/application.rb
73
87
  - lib/capiru/cli.rb
74
88
  - lib/capiru/version.rb
75
- - reference/en/rb_type.1
76
- - reference/en/rb_type.1.html
89
+ - man/de/rb_type
90
+ - man/en/rb_type
91
+ - reference/de/rb_type.ronn
77
92
  - reference/en/rb_type.ronn
78
93
  homepage: https://jwaterfaucett.github.io/capiru
79
94
  licenses:
@@ -1,114 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
- <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
6
- <title>rb_type(1) - return the integer value of a ruby type</title>
7
- <style type='text/css' media='all'>
8
- /* style: man */
9
- body#manpage {margin:0}
10
- .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
11
- .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
12
- .mp h2 {margin:10px 0 0 0}
13
- .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
14
- .mp h3 {margin:0 0 0 4ex}
15
- .mp dt {margin:0;clear:left}
16
- .mp dt.flush {float:left;width:8ex}
17
- .mp dd {margin:0 0 0 9ex}
18
- .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
19
- .mp pre {margin-bottom:20px}
20
- .mp pre+h2,.mp pre+h3 {margin-top:22px}
21
- .mp h2+pre,.mp h3+pre {margin-top:5px}
22
- .mp img {display:block;margin:auto}
23
- .mp h1.man-title {display:none}
24
- .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
25
- .mp h2 {font-size:16px;line-height:1.25}
26
- .mp h1 {font-size:20px;line-height:2}
27
- .mp {text-align:justify;background:#fff}
28
- .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
29
- .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
30
- .mp u {text-decoration:underline}
31
- .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
32
- .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
33
- .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
34
- .mp b.man-ref {font-weight:normal;color:#434241}
35
- .mp pre {padding:0 4ex}
36
- .mp pre code {font-weight:normal;color:#434241}
37
- .mp h2+pre,h3+pre {padding-left:0}
38
- ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
39
- ol.man-decor {width:100%}
40
- ol.man-decor li.tl {text-align:left}
41
- ol.man-decor li.tc {text-align:center;letter-spacing:4px}
42
- ol.man-decor li.tr {text-align:right;float:right}
43
- </style>
44
- </head>
45
- <!--
46
- The following styles are deprecated and will be removed at some point:
47
- div#man, div#man ol.man, div#man ol.head, div#man ol.man.
48
-
49
- The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
50
- .man-navigation should be used instead.
51
- -->
52
- <body id='manpage'>
53
- <div class='mp' id='man'>
54
-
55
- <div class='man-navigation' style='display:none'>
56
- <a href="#NAME">NAME</a>
57
- <a href="#SYNOPSIS">SYNOPSIS</a>
58
- <a href="#DESCRIPTION">DESCRIPTION</a>
59
- <a href="#EXAMPLES">EXAMPLES</a>
60
- <a href="#AUTHOR">AUTHOR</a>
61
- <a href="#SEE-ALSO">SEE ALSO</a>
62
- </div>
63
-
64
- <ol class='man-decor man-head man head'>
65
- <li class='tl'>rb_type(1)</li>
66
- <li class='tc'></li>
67
- <li class='tr'>rb_type(1)</li>
68
- </ol>
69
-
70
- <h2 id="NAME">NAME</h2>
71
- <p class="man-name">
72
- <code>rb_type</code> - <span class="man-whatis">return the integer value of a ruby type</span>
73
- </p>
74
-
75
- <h2 id="SYNOPSIS">SYNOPSIS</h2>
76
-
77
- <p><code>static inline int rb_type(VALUE obj);</code></p>
78
-
79
- <h2 id="DESCRIPTION">DESCRIPTION</h2>
80
-
81
- <p>The rb_type function takes a ruby object as its argument and returns the
82
- integer value of its internal representation in ruby. The integer value is one
83
- of the the ruby type definitions, i.e. T_STRING for String objects, T_NIL for NilClass objects,
84
- T_SYMBOL for Symbol objects, etc.</p>
85
-
86
- <h2 id="EXAMPLES">EXAMPLES</h2>
87
-
88
- <p> VALUE greeting = rb_str_new2("Hello amigo!");</p>
89
-
90
- <p> if( rb_type(greeting) == T_STRING ) {</p>
91
-
92
- <pre><code>printf("Greeting is a ruby String");
93
- </code></pre>
94
-
95
- <p> }</p>
96
-
97
- <h2 id="AUTHOR">AUTHOR</h2>
98
-
99
- <p> John Faucett</p>
100
-
101
- <h2 id="SEE-ALSO">SEE ALSO</h2>
102
-
103
- <p> <span class="man-ref">ruby_value_type<span class="s">(3)</span></span></p>
104
-
105
-
106
- <ol class='man-decor man-foot man foot'>
107
- <li class='tl'></li>
108
- <li class='tc'>February 2014</li>
109
- <li class='tr'>rb_type(1)</li>
110
- </ol>
111
-
112
- </div>
113
- </body>
114
- </html>