yrb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Capital Thought
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = yrb
2
+
3
+ Processes Yahoo! Resource Bundle format translation files and converts them to a hash.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Capital Thought. See LICENSE for details.
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "yrb"
8
+ gem.summary = %Q{Processes Yahoo! Resource Bundle format translation files.}
9
+ gem.description = %Q{Processes Yahoo! Resource Bundle format translation files and converts them to a hash.}
10
+ gem.email = "progressions@gmail.com"
11
+ gem.homepage = "http://github.com/progressions/yrb"
12
+ gem.authors = ["Jeff Coleman"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.6"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ spec.spec_opts = ['-c']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov_opts = ['--exclude', '.gem,Library,spec', '--sort', 'coverage']
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "YMDP #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,55 @@
1
+ # Processes Yahoo! Resource Bundle format translation files and converts them to a hash.
2
+ #
3
+ # === Options
4
+ #
5
+ # :unique (true/false) Raise an error if a file contains duplicated values. Defaults to true.
6
+ #
7
+ class YRB
8
+ class DuplicateKeyError < RuntimeError; end
9
+
10
+ attr_accessor :path
11
+
12
+ def self.load_file(path, options={})
13
+ @path = path
14
+
15
+ unless options.has_key?(:unique)
16
+ options[:unique] = true
17
+ end
18
+ parse(File.read(path), options)
19
+ end
20
+
21
+ # Is this line a valid comment in YRB?
22
+ #
23
+ def self.comment?(line)
24
+ line =~ /^[\s]*#/
25
+ end
26
+
27
+ # Is this line valid YRB syntax?
28
+ #
29
+ def self.key_and_value_from_line(line)
30
+ if line =~ /^([^\=]+)=(.+)/
31
+ return $1, $2.strip
32
+ else
33
+ return nil, nil
34
+ end
35
+ end
36
+
37
+ # Parse YRB and add it to a hash. Raise an error if the key already exists in the hash.
38
+ #
39
+ def self.parse(template, options={})
40
+ @hash = {}
41
+ lines = template.split("\n")
42
+ lines.each do |line|
43
+ unless comment?(line)
44
+ key, value = key_and_value_from_line(line)
45
+ if key
46
+ if options[:unique] && @hash.has_key?(key)
47
+ raise DuplicateKeyError.new("Duplicate key error: #{key}")
48
+ end
49
+ @hash[key] = value
50
+ end
51
+ end
52
+ end
53
+ @hash
54
+ end
55
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'yrb'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ require 'stubs'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
@@ -0,0 +1,93 @@
1
+ def stub_io
2
+ stub_screen_io
3
+ stub_file_io
4
+ stub_file_utils
5
+ stub_yaml
6
+ stub_growl
7
+ end
8
+
9
+ def stub_screen_io
10
+ $stdout.stub!(:puts)
11
+ $stdout.stub!(:print)
12
+ end
13
+
14
+ def stub_file_io(unprocessed_file="")
15
+ @file ||= mock('file').as_null_object
16
+ @file.stub!(:read).and_return(unprocessed_file)
17
+ @file.stub!(:write)
18
+ @file.stub!(:puts)
19
+
20
+ File.stub!(:new).and_return(@file)
21
+ File.stub!(:exists?).and_return(false)
22
+ File.stub!(:open).and_yield(@file)
23
+ File.stub!(:read).and_return(unprocessed_file)
24
+ File.stub!(:readlines).and_return(["first\n", "second\n"])
25
+ end
26
+
27
+ def stub_file_utils
28
+ FileUtils.stub!(:rm)
29
+ FileUtils.stub!(:rm_rf)
30
+ FileUtils.stub!(:cp_r)
31
+ FileUtils.stub!(:mkdir_p)
32
+ F.stub!(:concat_files)
33
+ F.stub!(:get_line_from_file).and_return("")
34
+ F.stub!(:save_to_file)
35
+ F.stub!(:save_to_tmp_file)
36
+ F.stub!(:execute).and_return("")
37
+ end
38
+
39
+ def stub_yaml(output_hash={})
40
+ YAML.stub!(:load_file).and_return(output_hash)
41
+ end
42
+
43
+ def stub_erb(processed_file="")
44
+ @erb ||= mock('erb').as_null_object
45
+ @erb.stub!(:result).and_return(processed_file)
46
+ ERB.stub!(:new).and_return(@erb)
47
+ end
48
+
49
+ def stub_haml_class
50
+ eval %(
51
+ module Haml
52
+ class Engine
53
+ end
54
+ end
55
+ )
56
+ end
57
+
58
+ def stub_haml(processed_file)
59
+ @haml = mock('haml').as_null_object
60
+ @haml.stub!(:render).and_return(processed_file)
61
+ Haml::Engine.stub!(:new).and_return(@haml)
62
+ end
63
+
64
+ def stub_git_helper
65
+ @git_helper = mock('git_helper').as_null_object
66
+ YMDP::GitHelper.stub!(:new).and_return(@git_helper)
67
+ end
68
+
69
+ def stub_timer
70
+ @timer = mock('timer').as_null_object
71
+ @timer.stub!(:time).and_yield
72
+ Timer.stub!(:new).and_return(@timer)
73
+ end
74
+
75
+ def stub_growl
76
+ @g = Object.new
77
+ Growl.stub(:new).and_return(@g)
78
+ @g.stub(:notify).as_null_object
79
+ end
80
+
81
+ def reset_constant(constant, value)
82
+ Object.send(:remove_const, constant)
83
+ Object.const_set(constant, value)
84
+ end
85
+
86
+ def stub_config
87
+ @config = mock('config')
88
+ @config.stub!(:[]).with("doctype").and_return("HTML 4.0 Transitional")
89
+ @config.stub!(:validate_html?).and_return(false)
90
+ @config.stub!(:compress_embedded_js?).and_return(false)
91
+ @config.stub!(:verbose?).and_return(false)
92
+ reset_constant(:CONFIG, @config)
93
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "YRB" do
4
+ before(:each) do
5
+ stub_file_io
6
+ end
7
+
8
+ describe "load_file" do
9
+ before(:each) do
10
+ end
11
+
12
+ it "should load empty file" do
13
+ @yrb = ""
14
+ File.stub!(:read).with("path").and_return(@yrb)
15
+ YRB.load_file("path").should == {}
16
+ end
17
+
18
+ it "should parse file" do
19
+ @yrb = <<-YRB
20
+ FIRST=first key
21
+ YRB
22
+ File.stub!(:read).with("path").and_return(@yrb)
23
+ YRB.load_file("path")["FIRST"].should == "first key"
24
+ end
25
+
26
+ it "should skip comments" do
27
+ @yrb = <<-YRB
28
+ # comment
29
+ FIRST=first key
30
+
31
+ YRB
32
+ File.stub!(:read).with("path").and_return(@yrb)
33
+ YRB.load_file("path")["FIRST"].should == "first key"
34
+ end
35
+
36
+ it "should skip non-keys" do
37
+ @yrb = <<-YRB
38
+ not a comment but not a key
39
+ FIRST=first key
40
+ YRB
41
+ File.stub!(:read).with("path").and_return(@yrb)
42
+ YRB.load_file("path")["FIRST"].should == "first key"
43
+ end
44
+
45
+ describe "unique true" do
46
+ it "should raise an error on duplicate keys" do
47
+ @yrb = <<-YRB
48
+ FIRST=first key
49
+ FIRST=first key
50
+ YRB
51
+ File.stub!(:read).with("path").and_return(@yrb)
52
+ lambda {
53
+ YRB.load_file("path")
54
+ }.should raise_error("Duplicate key error: FIRST")
55
+ end
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Coleman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-21 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.6
24
+ version:
25
+ description: Processes Yahoo! Resource Bundle format translation files and converts them to a hash.
26
+ email: progressions@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/yrb.rb
42
+ - spec/spec.opts
43
+ - spec/spec_helper.rb
44
+ - spec/stubs.rb
45
+ - spec/yrb_spec.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/progressions/yrb
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Processes Yahoo! Resource Bundle format translation files.
74
+ test_files:
75
+ - spec/spec_helper.rb
76
+ - spec/stubs.rb
77
+ - spec/yrb_spec.rb