props 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +5 -0
- data/README.markdown +60 -7
- data/Rakefile +1 -1
- data/lib/props.rb +28 -7
- metadata +6 -6
data/History.markdown
CHANGED
data/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# `props` - Manage Settings
|
1
|
+
# `props` - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)
|
2
2
|
|
3
3
|
## Description
|
4
4
|
|
@@ -6,7 +6,59 @@ TBD
|
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
9
|
-
|
9
|
+
Example:
|
10
|
+
|
11
|
+
```
|
12
|
+
class Config
|
13
|
+
|
14
|
+
DEFAULTS = { 'libs' => [ 'kramdown' ],
|
15
|
+
'extnames' => [
|
16
|
+
'.markdown',
|
17
|
+
'.m',
|
18
|
+
'.mark',
|
19
|
+
'.mkdn',
|
20
|
+
'.md',
|
21
|
+
'.mdown',
|
22
|
+
'.markdn',
|
23
|
+
'.txt',
|
24
|
+
'.text' ],
|
25
|
+
'redcarpet' => {
|
26
|
+
'extensions' => [
|
27
|
+
'no_intra_emphasis',
|
28
|
+
'fenced_code_blocks',
|
29
|
+
'tables',
|
30
|
+
'strikethrough' ] }
|
31
|
+
}
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@props = @props_default = Props.new( DEFAULTS, 'DEFAULTS' )
|
35
|
+
|
36
|
+
# check for user settings (markdown.yml) in home folder
|
37
|
+
|
38
|
+
props_home_file = File.join( Env.home, 'markdown.yml' )
|
39
|
+
if File.exists?( props_home_file )
|
40
|
+
puts "Loading settings from '#{props_home_file}'..."
|
41
|
+
@props = @props_home = Props.load_file( props_home_file, @props )
|
42
|
+
end
|
43
|
+
|
44
|
+
# check for user settings (markdown.yml) in working folder
|
45
|
+
|
46
|
+
props_work_file = File.join( '.', 'markdown.yml' )
|
47
|
+
if File.exists?( props_work_file )
|
48
|
+
puts "Loading settings from '#{props_work_file}'..."
|
49
|
+
@props = @props_work = Props.load_file( props_work_file, @props )
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def markdown_extnames
|
54
|
+
@props.fetch( 'extnames', nil )
|
55
|
+
end
|
56
|
+
|
57
|
+
...
|
58
|
+
|
59
|
+
end # class Config
|
60
|
+
```
|
61
|
+
|
10
62
|
|
11
63
|
## Install
|
12
64
|
|
@@ -17,17 +69,18 @@ Just install the gem:
|
|
17
69
|
|
18
70
|
## Real World Usage
|
19
71
|
|
20
|
-
The [`slideshow`](http://slideshow.rubyforge.org) (also known as Slide Show (S9))
|
72
|
+
The [`slideshow`](http://slideshow.rubyforge.org) gem (also known as Slide Show (S9))
|
21
73
|
that lets you create slide shows
|
22
|
-
and author slides in plain text using a wiki-style markup language that's easy-to-write and easy-to-read
|
23
|
-
ships with the `props` gem.
|
74
|
+
and author slides in plain text using a wiki-style markup language that's easy-to-write and easy-to-read.
|
24
75
|
|
76
|
+
The [`markdown`](http://geraldb.github.com/markdown) gem that lets you use your markdown library
|
77
|
+
of choice.
|
25
78
|
|
26
79
|
## Alternatives
|
27
80
|
|
28
|
-
|
81
|
+
* [`configtoolkit`](http://configtoolkit.rubyforge.org) gem
|
29
82
|
|
30
83
|
## License
|
31
84
|
|
32
85
|
The `props` scripts are dedicated to the public domain.
|
33
|
-
Use it as you please with no restrictions whatsoever.
|
86
|
+
Use it as you please with no restrictions whatsoever.
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ Hoe.spec 'props' do
|
|
5
5
|
|
6
6
|
self.version = Props::VERSION
|
7
7
|
|
8
|
-
self.summary = 'props - Manage Settings'
|
8
|
+
self.summary = 'props - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)'
|
9
9
|
self.description = summary
|
10
10
|
|
11
11
|
self.urls = ['http://geraldb.github.com/props']
|
data/lib/props.rb
CHANGED
@@ -6,6 +6,7 @@ require 'pp'
|
|
6
6
|
require 'logger'
|
7
7
|
require 'optparse'
|
8
8
|
require 'fileutils'
|
9
|
+
require 'erb'
|
9
10
|
|
10
11
|
|
11
12
|
|
@@ -37,7 +38,7 @@ end # class Env
|
|
37
38
|
|
38
39
|
class Props
|
39
40
|
|
40
|
-
VERSION = '0.
|
41
|
+
VERSION = '0.2.0'
|
41
42
|
|
42
43
|
attr_reader :path
|
43
44
|
attr_reader :parent
|
@@ -54,19 +55,39 @@ class Props
|
|
54
55
|
pp h # todo: add debug flag (turn off for default)
|
55
56
|
Props.new( h, path, parent )
|
56
57
|
end
|
58
|
+
|
59
|
+
### todo: use TOP_LEVEL_BINDING for binding default?
|
60
|
+
def self.load_file_with_erb( path, binding, parent=nil ) # run through erb first
|
61
|
+
text = ERB.new( File.read( path ) ).result( binding )
|
62
|
+
h = YAML.load( text )
|
63
|
+
puts "dump of >#{path}<:"
|
64
|
+
pp h # todo: add debug flag (turn off for default)
|
65
|
+
Props.new( h, path, parent )
|
66
|
+
end
|
57
67
|
|
58
|
-
def [](key) get( key ); end
|
59
68
|
|
60
69
|
def fetch(key, default)
|
61
70
|
value = get( key )
|
62
71
|
value.nil? ? default : value
|
63
72
|
end
|
73
|
+
|
74
|
+
def fetch_from_section(section, key, default)
|
75
|
+
value = get_from_section( section, key )
|
76
|
+
value.nil? ? default : value
|
77
|
+
end
|
78
|
+
|
79
|
+
def [](key) get( key ); end
|
64
80
|
|
65
|
-
private
|
66
81
|
def get( key )
|
67
|
-
value = @hash
|
82
|
+
value = @hash.fetch( key.to_s, nil )
|
68
83
|
# if not found try lookup in parent hash
|
69
|
-
(value.nil? && parent) ? parent
|
84
|
+
(value.nil? && parent) ? parent.get(key) : value
|
70
85
|
end
|
71
|
-
|
72
|
-
|
86
|
+
|
87
|
+
def get_from_section( section, key )
|
88
|
+
value = @hash.fetch( section.to_s, {} ).fetch( key.to_s, nil )
|
89
|
+
# if not found try lookup in parent hash
|
90
|
+
(value.nil? && parent) ? parent.get_from_section(section,key) : value
|
91
|
+
end
|
92
|
+
|
93
|
+
end # class Props
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: props
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rdoc
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: "3.0"
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
-
description: props - Manage Settings
|
50
|
+
description: props - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)
|
51
51
|
email: webslideshow@googlegroups.com
|
52
52
|
executables: []
|
53
53
|
|
@@ -94,6 +94,6 @@ rubyforge_project: props
|
|
94
94
|
rubygems_version: 1.8.24
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
|
-
summary: props - Manage Settings
|
97
|
+
summary: props - Manage Settings Hierachies (Commandline, User, Home, Defaults, etc.)
|
98
98
|
test_files: []
|
99
99
|
|