porth-plist 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ .DS_Store
7
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in porth-plist.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012 Matt Connolly <matt.connolly@me.com>
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.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # porth-plist (Plain Old Ruby Template Handler - Plist output)
2
+
3
+ Adds Property list (.plist) support to 'porth' (Plain Old Ruby Template Handler) gem.
4
+ This allows data stored in plain ruby objects (arrays and hashes) to be easily represented
5
+ in a view with a property list output.
6
+
7
+ ## Requirements
8
+
9
+ ## Installation
10
+
11
+ Add this to your project's Gemfile and run `$ bundle install`
12
+
13
+ ``` ruby
14
+ gem 'porth-plist'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Add the ".plist" mime time to your rails app's config/initializers/mime_types.rb:
20
+
21
+ ``` ruby
22
+ Mime::Type.register "text/xml", :plist
23
+ ```
24
+
25
+ Add ":plist" to your controller's responds_to calls, for example:
26
+
27
+ ``` ruby
28
+ class PeopleController < ApplicationController
29
+
30
+ respond_to :json, :xml, :plist, :html
31
+
32
+ # GET /people
33
+ # GET /people.json
34
+ def index
35
+ @people = Person.all
36
+
37
+ respond_with @people
38
+ end
39
+
40
+ # GET /people/1
41
+ # GET /people/1.json
42
+ def show
43
+ @person = Person.find(params[:id])
44
+
45
+ respond_with @person
46
+ end
47
+ ```
48
+
49
+ etc...
50
+
51
+ Note: This gem adds a #to_plist method to ActiveRecord::Base which makes it consistent with #to_json and #to_xml
52
+ as used by the standard Porth handlers.
53
+
54
+ ## Dependencies
55
+
56
+ Runtime dependencies:
57
+
58
+ * porth
59
+ * plist
60
+ * action_pack (>= 3.1) (to be consistent with porth)
61
+ * active_record (>= 3.1) (to be consistent with above)
62
+
63
+ Development dependencies:
64
+
65
+ * rpsec
66
+ * rake
67
+
68
+ ## Compatibility
69
+
70
+ * MRI 1.8.7
71
+ * MRI 1.9.2+
72
+
73
+ * rails >= 3.1 (to be consistent with Porth)
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork
78
+ 2. Install dependancies by running `$ bundle install`
79
+ 3. Write tests and code
80
+ 4. Make sure the tests pass by running `$ rake test`
81
+ 5. Push and send a pull request on GitHub
82
+
83
+ ## Credits
84
+
85
+ Special thanks to Tate Johnson (et al) for making Porth!
86
+
87
+ ## Copyright
88
+
89
+ Copyright © 2011 Matt Connolly. Released under the MIT license. See LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:test) do |t|
5
+ t.pattern = '**/*_spec.rb'
6
+ end
7
+
@@ -0,0 +1,24 @@
1
+ require 'porth-plist/version'
2
+ require 'action_controller'
3
+ require 'active_record'
4
+ require 'porth'
5
+ require 'porth/format/plist'
6
+ require 'plist'
7
+
8
+ Porth::Handler.register_format :plist, Porth::Format::Plist
9
+
10
+
11
+ if defined? ActiveRecord && ! ActiveRecord::Base.instance_methods.include?(:to_plist)
12
+
13
+ class ActiveRecord::Base
14
+
15
+ #
16
+ # output the attributes of the ActiveRecord::Base object to a .plist property list
17
+ # similar to #to_xml or #to_json
18
+ #
19
+ def to_plist
20
+ attributes.to_plist
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,5 @@
1
+ module Porth
2
+ module Plist
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Porth
2
+ module Format
3
+ module Plist
4
+ def self.call controller, object
5
+ object.to_plist
6
+ end
7
+
8
+ module ControllerExtensions
9
+ protected
10
+
11
+ # no extensions required for this one.
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "porth-plist/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "porth-plist"
7
+ s.version = Porth::Plist::VERSION
8
+ s.authors = ["Matt Connolly"]
9
+ s.email = ["matt.connolly@me.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Plain Old Ruby Template PLIST handler}
12
+ s.description = %q{Plain Old Ruby Template PLIST handler}
13
+
14
+ s.rubyforge_project = "porth-plist"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency 'porth'
23
+ s.add_runtime_dependency 'plist'
24
+ s.add_runtime_dependency 'actionpack', '>= 3.1.0', '< 4.0.0'
25
+ s.add_runtime_dependency 'activerecord', '>= 3.1.0', '< 4.0.0'
26
+
27
+ s.add_development_dependency 'rspec'
28
+ s.add_development_dependency 'rake', '~> 0.9.2'
29
+ end
@@ -0,0 +1,44 @@
1
+ require "rspec"
2
+ require 'spec_helper'
3
+
4
+
5
+ describe "Render to plist" do
6
+
7
+
8
+ def template_dir
9
+ File.expand_path('../../test/fixtures', __FILE__)
10
+ end
11
+
12
+ def render file, format, assigns = {}
13
+ ActionView::Base.new(template_dir, assigns, @controller).tap do |view|
14
+ view.lookup_context.freeze_formats [format]
15
+ end.render :file => file
16
+ end
17
+
18
+ it "outputs an array of hashes as a plist" do
19
+
20
+ output = render('block', :plist)
21
+ output.should =~ /!DOCTYPE plist/
22
+
23
+ decoded = Plist::parse_xml output
24
+
25
+ decoded.class.should == Array
26
+ decoded.length.should == 2
27
+ decoded[0].class.should == Hash
28
+ decoded[1].class.should == Hash
29
+ decoded[0]["value"].should == 1
30
+ decoded[1]["value"].should == 2
31
+
32
+ end
33
+
34
+ it "outputs an instance variable into a plist" do
35
+
36
+ output = render('instance_variable', :plist, 'foo' => 'bar')
37
+ output.should =~ /!DOCTYPE plist/
38
+
39
+ decoded = Plist::parse_xml output
40
+
41
+ decoded.class.should == Array
42
+ decoded[0].should == 'bar'
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ require 'porth'
2
+ require 'porth-plist'
3
+
4
+ include Porth
5
+
@@ -0,0 +1,3 @@
1
+ (1..2).map do |n|
2
+ {:value => n}
3
+ end
@@ -0,0 +1 @@
1
+ [@foo]
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: porth-plist
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Matt Connolly
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: porth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: plist
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: actionpack
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 3
59
+ - 1
60
+ - 0
61
+ version: 3.1.0
62
+ - - <
63
+ - !ruby/object:Gem::Version
64
+ hash: 63
65
+ segments:
66
+ - 4
67
+ - 0
68
+ - 0
69
+ version: 4.0.0
70
+ type: :runtime
71
+ version_requirements: *id003
72
+ - !ruby/object:Gem::Dependency
73
+ name: activerecord
74
+ prerelease: false
75
+ requirement: &id004 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 3
83
+ - 1
84
+ - 0
85
+ version: 3.1.0
86
+ - - <
87
+ - !ruby/object:Gem::Version
88
+ hash: 63
89
+ segments:
90
+ - 4
91
+ - 0
92
+ - 0
93
+ version: 4.0.0
94
+ type: :runtime
95
+ version_requirements: *id004
96
+ - !ruby/object:Gem::Dependency
97
+ name: rspec
98
+ prerelease: false
99
+ requirement: &id005 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ type: :development
109
+ version_requirements: *id005
110
+ - !ruby/object:Gem::Dependency
111
+ name: rake
112
+ prerelease: false
113
+ requirement: &id006 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ hash: 63
119
+ segments:
120
+ - 0
121
+ - 9
122
+ - 2
123
+ version: 0.9.2
124
+ type: :development
125
+ version_requirements: *id006
126
+ description: Plain Old Ruby Template PLIST handler
127
+ email:
128
+ - matt.connolly@me.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files: []
134
+
135
+ files:
136
+ - .gitignore
137
+ - Gemfile
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - lib/porth-plist.rb
142
+ - lib/porth-plist/version.rb
143
+ - lib/porth/format/plist.rb
144
+ - porth-plist.gemspec
145
+ - spec/porth-plist_spec.rb
146
+ - spec/spec_helper.rb
147
+ - test/fixtures/block.rb
148
+ - test/fixtures/instance_variable.rb
149
+ homepage: ""
150
+ licenses: []
151
+
152
+ post_install_message:
153
+ rdoc_options: []
154
+
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ requirements: []
176
+
177
+ rubyforge_project: porth-plist
178
+ rubygems_version: 1.8.11
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: Plain Old Ruby Template PLIST handler
182
+ test_files:
183
+ - spec/porth-plist_spec.rb
184
+ - spec/spec_helper.rb
185
+ - test/fixtures/block.rb
186
+ - test/fixtures/instance_variable.rb
187
+ has_rdoc: