props 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
File without changes
data/Manifest.txt CHANGED
@@ -1,5 +1,7 @@
1
- History.markdown
1
+ History.md
2
2
  Manifest.txt
3
- README.markdown
3
+ README.md
4
4
  Rakefile
5
5
  lib/props.rb
6
+ test/helper.rb
7
+ test/test_ini.rb
@@ -69,11 +69,11 @@ Just install the gem:
69
69
 
70
70
  ## Real World Usage
71
71
 
72
- The [`slideshow`](http://slideshow.rubyforge.org) gem (also known as Slide Show (S9))
72
+ The [`slideshow`](http://slideshow-s9.github.io) gem (also known as Slide Show (S9))
73
73
  that lets you create slide shows
74
74
  and author slides in plain text using a wiki-style markup language that's easy-to-write and easy-to-read.
75
75
 
76
- The [`markdown`](http://geraldb.github.com/markdown) gem that lets you use your markdown library
76
+ The [`markdown`](https://github.com/rubylibs/markdown) gem that lets you use your markdown library
77
77
  of choice.
78
78
 
79
79
  ## Alternatives
data/Rakefile CHANGED
@@ -2,19 +2,25 @@ require 'hoe'
2
2
  require './lib/props.rb'
3
3
 
4
4
  Hoe.spec 'props' do
5
-
5
+
6
6
  self.version = Props::VERSION
7
7
 
8
8
  self.summary = 'props - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)'
9
9
  self.description = summary
10
10
 
11
- self.urls = ['http://geraldb.github.com/props']
12
-
11
+ self.urls = ['https://github.com/rubylibs/props']
12
+
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'webslideshow@googlegroups.com'
15
15
 
16
16
  # switch extension to .markdown for gihub formatting
17
- self.readme_file = 'README.markdown'
18
- self.history_file = 'History.markdown'
19
-
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'History.md'
19
+
20
+ self.licenses = ['Public Domain']
21
+
22
+ self.spec_extras = {
23
+ :required_ruby_version => '>= 1.9.2'
24
+ }
25
+
20
26
  end
data/lib/props.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  # core and stlibs
3
4
 
@@ -24,8 +25,8 @@ class Env
24
25
  else
25
26
  '/'
26
27
  end
27
- end
28
- end
28
+ end
29
+ end
29
30
 
30
31
  # todo: use logger - how?
31
32
  ## puts "env home=>#{path}<"
@@ -36,9 +37,82 @@ class Env
36
37
  end # class Env
37
38
 
38
39
 
40
+ module INI
41
+
42
+ def self.load_file( path )
43
+ # returns a nested hash
44
+ # (compatible structure - works like YAML.load_file)
45
+
46
+ text = File.open( path, 'r:bom|utf-8' ).read
47
+ self.load( text )
48
+ end
49
+
50
+
51
+ def self.load( text )
52
+ hash = top_hash = Hash.new
53
+
54
+ text = text.gsub( "\t", ' ' ) # replace all tabs w/ spaces
55
+
56
+ text.each_line do |line|
57
+
58
+ ### skip comments
59
+ # e.g. # this is a comment line
60
+ # or ; this too
61
+ # or -- haskell style
62
+ # or % text style
63
+
64
+ if line =~ /^\s*#/ || line =~ /^\s*;/ || line =~ /^\s*--/ || line =~ /^\s*%/
65
+ ## logger.debug 'skipping comment line'
66
+ next
67
+ end
68
+
69
+ ### skip blank lines
70
+ if line =~ /^\s*$/
71
+ ## logger.debug 'skipping blank line'
72
+ next
73
+ end
74
+
75
+ # pass 1) remove possible trailing eol comment
76
+ ## e.g -> New York # Sample EOL Comment Here (with or without commas,,,,)
77
+ ## becomes -> New York
78
+
79
+ line = line.sub( /\s+#.*$/, '' )
80
+
81
+ # pass 2) remove leading and trailing whitespace
82
+
83
+ line = line.strip
84
+
85
+ ## check for new section e.g. [planet012-xxx_bc]
86
+
87
+ ### todo: allow _ or - in strict section key? why? why not??
88
+ ### allow _ or - in value key? why why not??
89
+ if line =~ /^\s*\[\s*([a-z0-9_\-]+)\s*\]\s*$/ # strict section
90
+ key = $1.to_s.dup
91
+ hash = top_hash[ key ] = Hash.new
92
+ elsif line =~ /^\s*\[\s*([^ \]]+)\s*\]\s*$/ # liberal section; allow everything in key
93
+ key = $1.to_s.dup
94
+ hash = top_hash[ key ] = Hash.new
95
+ elsif line =~ /^\s*([a-z0-9_\-]+)\s*[:=](.*)$/
96
+ key = $1.to_s.dup
97
+ value = $2.to_s.strip.dup # check if it can be nil? if yes use blank string e.g. ''
98
+ ### todo: strip quotes from value??? why? why not?
99
+ hash[ key ] = value
100
+ else
101
+ puts "*** warn: skipping unknown line type in ini >#{line}<"
102
+ end
103
+ end # each lines
104
+
105
+ top_hash
106
+ end # method load
107
+
108
+
109
+ end # module INI
110
+
111
+
112
+
39
113
  class Props
40
114
 
41
- VERSION = '1.0.0'
115
+ VERSION = '1.0.1'
42
116
 
43
117
  attr_reader :path
44
118
  attr_reader :parent
data/test/helper.rb ADDED
@@ -0,0 +1,13 @@
1
+ ## $:.unshift(File.dirname(__FILE__))
2
+
3
+ ## minitest setup
4
+
5
+ # require 'minitest/unit'
6
+ require 'minitest/autorun'
7
+
8
+ # include MiniTest::Unit # lets us use TestCase instead of MiniTest::Unit::TestCase
9
+
10
+
11
+ ## our own code
12
+
13
+ require 'props'
data/test/test_ini.rb ADDED
@@ -0,0 +1,50 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_ini.rb
4
+ # or better
5
+ # rake test
6
+
7
+ require 'helper'
8
+
9
+ class TestIni < MiniTest::Unit::TestCase
10
+
11
+
12
+ def test_load
13
+
14
+ text = <<EOS
15
+ # comment
16
+ ; another comment
17
+
18
+ key1 = hello
19
+ key2 : hi!
20
+
21
+ [section1]
22
+ key3 = salut # end of line comment here
23
+
24
+ [section2]
25
+ key4: hola
26
+ blank =
27
+ blank2:
28
+
29
+ [ http://example.com ]
30
+ title = A rose is a rose is a rose, eh?
31
+ title2: A rose is a rose is a rose, eh? # comment here
32
+ ; another one here
33
+ title3 = A rose is a rose is a rose, eh?
34
+ EOS
35
+
36
+ hash = INI.load( text )
37
+ pp hash
38
+
39
+ assert( hash['key1'] == 'hello' )
40
+ assert( hash['key2'] == 'hi!' )
41
+ assert( hash['section1']['key3'] == 'salut' )
42
+ assert( hash['section2']['key4'] == 'hola' )
43
+ assert( hash['section2']['blank'] == '' )
44
+ assert( hash['section2']['blank2'] == '' )
45
+ assert( hash['http://example.com']['title'] == 'A rose is a rose is a rose, eh?' )
46
+ assert( hash['http://example.com']['title2'] == 'A rose is a rose is a rose, eh?' )
47
+ assert( hash['http://example.com']['title3'] == 'A rose is a rose is a rose, eh?' )
48
+ end
49
+
50
+ end
metadata CHANGED
@@ -1,99 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: props
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Gerald Bauer
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-06-23 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rdoc
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &83434100 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 19
29
- segments:
30
- - 3
31
- - 10
32
- version: "3.10"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: hoe
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *83434100
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &83477370 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 7
44
- segments:
45
- - 3
46
- - 0
47
- version: "3.0"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.3'
48
33
  type: :development
49
- version_requirements: *id002
50
- description: props - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)
34
+ prerelease: false
35
+ version_requirements: *83477370
36
+ description: props - Manage Settings Hierachies (Commandline, User, Home, Defaults,
37
+ etc.)
51
38
  email: webslideshow@googlegroups.com
52
39
  executables: []
53
-
54
40
  extensions: []
55
-
56
- extra_rdoc_files:
41
+ extra_rdoc_files:
57
42
  - Manifest.txt
58
- files:
59
- - History.markdown
43
+ files:
44
+ - History.md
60
45
  - Manifest.txt
61
- - README.markdown
46
+ - README.md
62
47
  - Rakefile
63
48
  - lib/props.rb
64
- homepage: http://geraldb.github.com/props
65
- licenses: []
66
-
49
+ - test/helper.rb
50
+ - test/test_ini.rb
51
+ - .gemtest
52
+ homepage: https://github.com/rubylibs/props
53
+ licenses:
54
+ - Public Domain
67
55
  post_install_message:
68
- rdoc_options:
56
+ rdoc_options:
69
57
  - --main
70
- - README.markdown
71
- require_paths:
58
+ - README.md
59
+ require_paths:
72
60
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
61
+ required_ruby_version: !ruby/object:Gem::Requirement
74
62
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 1.9.2
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
68
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
91
73
  requirements: []
92
-
93
74
  rubyforge_project: props
94
- rubygems_version: 1.8.24
75
+ rubygems_version: 1.8.17
95
76
  signing_key:
96
77
  specification_version: 3
97
78
  summary: props - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)
98
- test_files: []
99
-
79
+ test_files:
80
+ - test/test_ini.rb