toml 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +69 -0
  3. data/Rakefile +150 -0
  4. data/lib/toml.rb +8 -0
  5. data/lib/toml/parser.rb +67 -0
  6. data/toml.gemspec +57 -0
  7. metadata +53 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Tom Preston-Werner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ RakeGem
2
+ =======
3
+
4
+ # DESCRIPTION
5
+
6
+ Ever wanted to manage your RubyGem in a sane way without having to resort to
7
+ external dependencies like Jeweler or Hoe? Ever thought that Rake and a hand
8
+ crafted gemspec should be enough to deal with these problems? If so, then
9
+ RakeGem is here to make your life awesome!
10
+
11
+ RakeGem is not a library. It is just a few simple file templates that you can
12
+ copy into your project and easily customize to match your specific needs. It
13
+ ships with a few Rake tasks to help you keep your gemspec up-to-date, build
14
+ a gem, and release your library and gem to the world.
15
+
16
+ RakeGem assumes you are using Git. This makes the Rake tasks easy to write. If
17
+ you are using something else, you should be able to get RakeGem up and running
18
+ with your system without too much editing.
19
+
20
+ The RakeGem tasks were inspired by the
21
+ [Sinatra](http://github.com/sinatra/sinatra) project.
22
+
23
+ # INSTALLATION
24
+
25
+ Take a look at `Rakefile` and `NAME.gemspec`. For new projects, you can start
26
+ with these files and edit a few lines to make them fit into your library. If
27
+ you have an existing project, you'll probably want to take the RakeGem
28
+ versions and copy any custom stuff from your existing Rakefile and gemspec
29
+ into them. As long as you're careful, the rake tasks should keep working.
30
+
31
+ # ASSUMPTIONS
32
+
33
+ RakeGem makes a few assumptions. You will either need to satisfy these
34
+ assumptions or modify the rake tasks to work with your setup.
35
+
36
+ You should have a file named `lib/NAME.rb` (where NAME is the name of your
37
+ library) that contains a version line. It should look something like this:
38
+
39
+ module NAME
40
+ VERSION = '0.1.0'
41
+ end
42
+
43
+ It is important that you use the constant `VERSION` and that it appear on a
44
+ line by itself.
45
+
46
+ # UPDATING THE VERSION
47
+
48
+ In order to make a new release, you'll want to update the version. With
49
+ RakeGem, you only need to do that in the `lib/NAME.rb` file. Everything else
50
+ will use this find the canonical version of the library.
51
+
52
+ # TASKS
53
+
54
+ RakeGem provides three rake tasks:
55
+
56
+ `rake gemspec` will update your gemspec with the latest version (taken from
57
+ the `lib/NAME.rb` file) and file list (as reported by `git ls-files`).
58
+
59
+ `rake build` will update your gemspec, build your gemspec into a gem, and
60
+ place it in the `pkg` directory.
61
+
62
+ `rake release` will update your gemspec, build your gem, make a commit with
63
+ the message `Release 0.1.0` (with the correct version, obviously), tag the
64
+ commit with `v0.1.0` (again with the correct version), and push the `master`
65
+ branch and new tag to `origin`.
66
+
67
+ Keep in mind that these are just simple Rake tasks and you can edit them
68
+ however you please. Don't want to auto-commit or auto-push? Just delete those
69
+ lines. You can bend RakeGem to your own needs. That's the whole point!
@@ -0,0 +1,150 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ require 'rdoc/task'
64
+ Rake::RDocTask.new do |rdoc|
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "#{name} #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
70
+
71
+ desc "Open an irb session preloaded with this library"
72
+ task :console do
73
+ sh "irb -rubygems -r ./lib/#{name}.rb"
74
+ end
75
+
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+
83
+
84
+ #############################################################################
85
+ #
86
+ # Packaging tasks
87
+ #
88
+ #############################################################################
89
+
90
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push origin v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ desc "Build #{gem_file} into the pkg directory"
104
+ task :build => :gemspec do
105
+ sh "mkdir -p pkg"
106
+ sh "gem build #{gemspec_file}"
107
+ sh "mv #{gem_file} pkg"
108
+ end
109
+
110
+ desc "Generate #{gemspec_file}"
111
+ task :gemspec => :validate do
112
+ # read spec file and split out manifest section
113
+ spec = File.read(gemspec_file)
114
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
+
116
+ # replace name version and date
117
+ replace_header(head, :name)
118
+ replace_header(head, :version)
119
+ replace_header(head, :date)
120
+ #comment this out if your rubyforge_project has a different name
121
+ replace_header(head, :rubyforge_project)
122
+
123
+ # determine file list from git ls-files
124
+ files = `git ls-files`.
125
+ split("\n").
126
+ sort.
127
+ reject { |file| file =~ /^\./ }.
128
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
129
+ map { |file| " #{file}" }.
130
+ join("\n")
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ desc "Validate #{gemspec_file}"
140
+ task :validate do
141
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142
+ unless libfiles.empty?
143
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
144
+ exit!
145
+ end
146
+ unless Dir['VERSION*'].empty?
147
+ puts "A `VERSION` file at root level violates Gem best practices."
148
+ exit!
149
+ end
150
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'time'
4
+ require 'toml/parser'
5
+
6
+ module TOML
7
+ VERSION = '0.0.1'
8
+ end
@@ -0,0 +1,67 @@
1
+ module TOML
2
+ class Parser
3
+ attr_reader :parsed
4
+
5
+ def initialize(markup)
6
+ lines = markup.split("\n").reject {|l| l.start_with?("#") }
7
+
8
+ @parsed = {}
9
+ @current_key_group = ""
10
+
11
+ lines.each do |line|
12
+ if line.gsub(/\s/, '').empty?
13
+ close_key_group
14
+ elsif line =~ /^\s?\[(.*)\]/
15
+ new_key_group($1)
16
+ elsif line =~ /\s?(.*)=(.*)/
17
+ add_key($1, $2)
18
+ else
19
+ raise "lmao i have no clue what you're doing: #{line}"
20
+ end
21
+ end
22
+ end
23
+
24
+ def new_key_group(key_name)
25
+ @current_key_group = key_name
26
+ end
27
+
28
+ def add_key(key, value)
29
+ @parsed[@current_key_group] ||= {}
30
+ @parsed[@current_key_group][key.strip] = coerce(strip_comments(value))
31
+ end
32
+
33
+ def strip_comments(text)
34
+ text.split("#").first
35
+ end
36
+
37
+ def coerce(value)
38
+ value = value.strip
39
+ if value =~ /\[(.*)\]/
40
+ # array
41
+ array = $1.split(",").map {|s| s.strip.gsub(/\"(.*)\"/, '\1')}
42
+ return array
43
+ elsif value =~ /\"(.*)\"/
44
+ # string
45
+ return $1
46
+ end
47
+
48
+ begin
49
+ time = Time.parse(value)
50
+ return time
51
+ rescue
52
+ end
53
+
54
+ begin
55
+ int = Integer(value)
56
+ return int
57
+ rescue
58
+ end
59
+
60
+ raise "lol no clue what [#{value}] is"
61
+ end
62
+
63
+ def close_key_group
64
+ @current_key_group = ""
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,57 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'toml'
16
+ s.version = '0.0.1'
17
+ s.date = '2013-02-23'
18
+
19
+ ## Make sure your summary is short. The description may be as long
20
+ ## as you like.
21
+ s.summary = "Parse your TOML."
22
+ s.description = "Parse your TOML, seriously."
23
+
24
+ ## List the primary authors. If there are a bunch of authors, it's probably
25
+ ## better to set the email to an email list or something. If you don't have
26
+ ## a custom homepage, consider using your GitHub URL or the like.
27
+ s.authors = ["Jeremy McAnally"]
28
+ s.email = 'jeremy@github.com'
29
+ s.homepage = 'http://github.com/jm/toml'
30
+
31
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
32
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
33
+ s.require_paths = %w[lib]
34
+
35
+ ## Specify any RDoc options here. You'll want to add your README and
36
+ ## LICENSE files to the extra_rdoc_files list.
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.extra_rdoc_files = %w[README.md LICENSE]
39
+
40
+ ## Leave this section as-is. It will be automatically generated from the
41
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
42
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
43
+ # = MANIFEST =
44
+ s.files = %w[
45
+ LICENSE
46
+ README.md
47
+ Rakefile
48
+ lib/toml.rb
49
+ lib/toml/parser.rb
50
+ toml.gemspec
51
+ ]
52
+ # = MANIFEST =
53
+
54
+ ## Test files will be grabbed from the file list. Make sure the path glob
55
+ ## matches what you actually use.
56
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
57
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy McAnally
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Parse your TOML, seriously.
15
+ email: jeremy@github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ - LICENSE
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - lib/toml.rb
26
+ - lib/toml/parser.rb
27
+ - toml.gemspec
28
+ homepage: http://github.com/jm/toml
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options:
32
+ - --charset=UTF-8
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: Parse your TOML.
53
+ test_files: []