tokamak 1.0.0.beta2 → 1.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +14 -0
- data/README.md +159 -0
- data/lib/tokamak/builder/base.rb +74 -0
- data/lib/tokamak/{json/builder.rb → builder/json.rb} +38 -29
- data/lib/tokamak/builder/values.rb +33 -0
- data/lib/tokamak/{atom/builder.rb → builder/xml.rb} +46 -41
- data/lib/tokamak/builder.rb +22 -0
- data/lib/tokamak/errors.rb +3 -0
- data/lib/tokamak/hook/rails.rb +78 -0
- data/lib/tokamak/hook/sinatra.rb +18 -0
- data/lib/tokamak/hook/tilt.rb +42 -0
- data/lib/tokamak/hook.rb +6 -0
- data/lib/tokamak/recipes.rb +26 -0
- data/lib/tokamak/version.rb +13 -0
- data/lib/tokamak.rb +14 -18
- data/script/console +7 -0
- data/test/rails2_skel/Rakefile +16 -0
- data/test/rails2_skel/app/controllers/application_controller.rb +1 -0
- data/test/rails2_skel/app/controllers/test_controller.rb +18 -0
- data/test/rails2_skel/app/views/test/_feed_member.tokamak +9 -0
- data/test/rails2_skel/app/views/test/feed.tokamak +24 -0
- data/test/rails2_skel/app/views/test/show.tokamak +31 -0
- data/test/rails2_skel/config/boot.rb +110 -0
- data/test/rails2_skel/config/environment.rb +20 -0
- data/test/rails2_skel/config/environments/development.rb +17 -0
- data/test/rails2_skel/config/environments/production.rb +28 -0
- data/test/rails2_skel/config/environments/test.rb +28 -0
- data/test/rails2_skel/config/initializers/cookie_verification_secret.rb +2 -0
- data/test/rails2_skel/config/initializers/mime_types.rb +3 -0
- data/test/rails2_skel/config/initializers/new_rails_defaults.rb +10 -0
- data/test/rails2_skel/config/initializers/session_store.rb +5 -0
- data/test/rails2_skel/config/routes.rb +43 -0
- data/test/rails2_skel/script/console +3 -0
- data/test/test_helper.rb +7 -0
- data/test/tokamak/builder/base_test.rb +28 -0
- data/test/tokamak/builder/json_test.rb +227 -0
- data/test/tokamak/builder/xml_test.rb +254 -0
- data/test/tokamak/helper_test.rb +106 -0
- data/test/tokamak/hook/rails_test.rb +74 -0
- data/test/tokamak/hook/sinatra_test.rb +85 -0
- data/test/tokamak/hook/tilt_test.rb +35 -0
- data/test/tokamak/recipes_test.rb +90 -0
- metadata +106 -113
- data/.document +0 -5
- data/.rspec +0 -1
- data/Gemfile +0 -27
- data/Gemfile.lock +0 -77
- data/LICENSE.txt +0 -20
- data/README.rdoc +0 -69
- data/Rakefile +0 -50
- data/VERSION +0 -1
- data/lib/tokamak/atom/base.rb +0 -87
- data/lib/tokamak/atom/helpers.rb +0 -13
- data/lib/tokamak/atom.rb +0 -8
- data/lib/tokamak/error.rb +0 -6
- data/lib/tokamak/json/base.rb +0 -83
- data/lib/tokamak/json/helpers.rb +0 -13
- data/lib/tokamak/json.rb +0 -10
- data/lib/tokamak/representation/atom/atom.rng +0 -597
- data/lib/tokamak/representation/atom/base.rb +0 -140
- data/lib/tokamak/representation/atom/category.rb +0 -39
- data/lib/tokamak/representation/atom/entry.rb +0 -56
- data/lib/tokamak/representation/atom/factory.rb +0 -48
- data/lib/tokamak/representation/atom/feed.rb +0 -108
- data/lib/tokamak/representation/atom/link.rb +0 -66
- data/lib/tokamak/representation/atom/person.rb +0 -46
- data/lib/tokamak/representation/atom/source.rb +0 -57
- data/lib/tokamak/representation/atom/tag_collection.rb +0 -36
- data/lib/tokamak/representation/atom/xml.rb +0 -94
- data/lib/tokamak/representation/atom.rb +0 -18
- data/lib/tokamak/representation/generic.rb +0 -20
- data/lib/tokamak/representation/json/base.rb +0 -25
- data/lib/tokamak/representation/json/keys_as_methods.rb +0 -72
- data/lib/tokamak/representation/json/link.rb +0 -27
- data/lib/tokamak/representation/json/link_collection.rb +0 -21
- data/lib/tokamak/representation/json.rb +0 -11
- data/lib/tokamak/representation/links.rb +0 -9
- data/lib/tokamak/representation.rb +0 -3
- data/lib/tokamak/values.rb +0 -29
- data/lib/tokamak/xml/base.rb +0 -60
- data/lib/tokamak/xml/builder.rb +0 -115
- data/lib/tokamak/xml/helpers.rb +0 -13
- data/lib/tokamak/xml/link.rb +0 -31
- data/lib/tokamak/xml/links.rb +0 -35
- data/lib/tokamak/xml.rb +0 -12
- data/spec/integration/atom/atom_spec.rb +0 -191
- data/spec/integration/full_atom.xml +0 -92
- data/spec/integration/full_json.js +0 -46
- data/spec/integration/json/json_spec.rb +0 -172
- data/spec/integration/xml/xml_spec.rb +0 -203
- data/spec/spec_helper.rb +0 -12
data/README.rdoc
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
= tokamak
|
2
|
-
|
3
|
-
Tokamak is a hypermedia template engine created to enpower Restfulie.
|
4
|
-
|
5
|
-
== Get it on baby!
|
6
|
-
|
7
|
-
Based on Cipriani's example on the Restfulie mailing list, this is a simple Tokamak description:
|
8
|
-
|
9
|
-
collection(@activities) do |collection|
|
10
|
-
collection.members do |m, activity|
|
11
|
-
member.values { |v| v.id = activity.id }
|
12
|
-
member.link "similar", url_for activity.similar
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
There is an entire chapter on tokamak usage on Restfulie's documentation. Go for it! If it still does not show what you want to generate, feel free to ask at Restfulie's mailing list.
|
17
|
-
|
18
|
-
== A full bodied example
|
19
|
-
|
20
|
-
collection(@activities) do |collection|
|
21
|
-
collection.members do |member, activity|
|
22
|
-
member.values { |values|
|
23
|
-
|
24
|
-
values.id activity.id
|
25
|
-
values.title activity.title
|
26
|
-
|
27
|
-
values.actor {
|
28
|
-
values.type activity.actor_type.downcase
|
29
|
-
values.id activity.actor_id
|
30
|
-
}
|
31
|
-
|
32
|
-
values.verbs activity.verbs
|
33
|
-
|
34
|
-
values.object {
|
35
|
-
values.type activity.object_type.downcase
|
36
|
-
values.id activity.object_id
|
37
|
-
values.content activity.object.content if activity.object_content?
|
38
|
-
}
|
39
|
-
|
40
|
-
if activity.indirect_object
|
41
|
-
values.indirect_object {
|
42
|
-
values.type activity.indirect_object_type.downcase
|
43
|
-
values.id activity.indirect_object_id
|
44
|
-
}
|
45
|
-
end
|
46
|
-
}
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
== Team
|
52
|
-
|
53
|
-
It was created by the team who contributed to Restfulie.
|
54
|
-
|
55
|
-
== Contributing to tokamak
|
56
|
-
|
57
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
58
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
59
|
-
* Fork the project
|
60
|
-
* Start a feature/bugfix branch
|
61
|
-
* Commit and push until you are happy with your contribution
|
62
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
63
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
64
|
-
|
65
|
-
== Copyright
|
66
|
-
|
67
|
-
Copyright (c) 2010 Guilherme Silveira. See LICENSE.txt for
|
68
|
-
further details.
|
69
|
-
|
data/Rakefile
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
11
|
-
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "tokamak"
|
16
|
-
gem.homepage = "http://github.com/caelum/tokamak"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{A template engine for hypermedia resources}
|
19
|
-
gem.description = %Q{A template engine for hypermedia resources}
|
20
|
-
gem.email = "guilherme.silveira@caelum.com.br"
|
21
|
-
gem.authors = ["Guilherme Silveira"]
|
22
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rspec/core'
|
30
|
-
require 'rspec/core/rake_task'
|
31
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
-
end
|
34
|
-
|
35
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
-
spec.rcov = true
|
38
|
-
end
|
39
|
-
|
40
|
-
task :default => :spec
|
41
|
-
|
42
|
-
require 'rake/rdoctask'
|
43
|
-
Rake::RDocTask.new do |rdoc|
|
44
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
-
|
46
|
-
rdoc.rdoc_dir = 'rdoc'
|
47
|
-
rdoc.title = "tokamak #{version}"
|
48
|
-
rdoc.rdoc_files.include('README*')
|
49
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.0.beta2
|
data/lib/tokamak/atom/base.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/conversions'
|
2
|
-
|
3
|
-
module Tokamak
|
4
|
-
module Atom
|
5
|
-
module Base
|
6
|
-
module ClassMethods
|
7
|
-
mattr_reader :media_type_name
|
8
|
-
@@media_type_name = 'application/atom+xml'
|
9
|
-
|
10
|
-
mattr_reader :headers
|
11
|
-
@@headers = {
|
12
|
-
:get => { 'Accept' => media_type_name },
|
13
|
-
:post => { 'Content-Type' => media_type_name }
|
14
|
-
}
|
15
|
-
|
16
|
-
mattr_reader :recipes
|
17
|
-
@@recipes = {}
|
18
|
-
|
19
|
-
def helper
|
20
|
-
Tokamak::Atom::Helpers
|
21
|
-
end
|
22
|
-
|
23
|
-
def describe_recipe(recipe_name, options={}, &block)
|
24
|
-
raise 'Undefined recipe' unless block_given?
|
25
|
-
raise 'Undefined recipe_name' unless recipe_name
|
26
|
-
@@recipes[recipe_name] = block
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_atom(obj = nil, options = {}, &block)
|
30
|
-
# just instantiate the string with the atom factory
|
31
|
-
return Tokamak::Representation::Atom::Factory.create(obj) if obj.kind_of?(String)
|
32
|
-
|
33
|
-
if block_given?
|
34
|
-
recipe = block
|
35
|
-
elsif options[:recipe]
|
36
|
-
recipe = @@recipes[options[:recipe]]
|
37
|
-
else
|
38
|
-
return obj if obj.respond_to?(:atom_type) && (obj.atom_type == "feed" || obj.atom_type == "entry")
|
39
|
-
raise Tokamak::ConverterError.new("Recipe required")
|
40
|
-
end
|
41
|
-
|
42
|
-
# execute with the builder if a recipe is set (even if the obj is an atom)
|
43
|
-
options[:atom_type] ||= obj.respond_to?(:each) ? :feed : :entry
|
44
|
-
raise Tokamak::ConverterError.new("Undefined atom type #{options[:atom_type]}") unless [:entry,:feed].include?(options[:atom_type])
|
45
|
-
|
46
|
-
# Create representation and proxy
|
47
|
-
builder = Builder.new(options[:atom_type], obj)
|
48
|
-
|
49
|
-
# Check recipe arity size before calling it
|
50
|
-
recipe.call(*[builder, obj, options][0,recipe.arity])
|
51
|
-
|
52
|
-
builder.representation
|
53
|
-
end
|
54
|
-
|
55
|
-
alias_method :unmarshal, :to_atom
|
56
|
-
|
57
|
-
def to_hash(obj)
|
58
|
-
return obj if obj.kind_of?(Hash)
|
59
|
-
|
60
|
-
xml = nil
|
61
|
-
|
62
|
-
if obj.kind_of?(::String)
|
63
|
-
xml = obj
|
64
|
-
elsif obj.respond_to?(:to_xml)
|
65
|
-
xml = obj.to_xml
|
66
|
-
end
|
67
|
-
|
68
|
-
Hash.from_xml(xml).with_indifferent_access unless xml.nil?
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def to_s(obj)
|
73
|
-
return obj if obj.kind_of?(String)
|
74
|
-
if obj.respond_to?(:to_xml)
|
75
|
-
obj.to_xml.to_s
|
76
|
-
else
|
77
|
-
obj.to_s
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def marshal(obj, options = nil)
|
82
|
-
to_atom(obj, options).to_xml
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/lib/tokamak/atom/helpers.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Tokamak
|
2
|
-
module Atom
|
3
|
-
module Helpers
|
4
|
-
def collection(obj, *args, &block)
|
5
|
-
Tokamak::Atom.to_atom(obj, :atom_type => :feed, &block)
|
6
|
-
end
|
7
|
-
|
8
|
-
def member(obj, *args, &block)
|
9
|
-
Tokamak::Atom.to_atom(obj, :atom_type => :entry, &block)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/tokamak/atom.rb
DELETED
data/lib/tokamak/error.rb
DELETED
data/lib/tokamak/json/base.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
module Tokamak
|
2
|
-
module Json
|
3
|
-
module Base
|
4
|
-
module ClassMethods
|
5
|
-
mattr_reader :media_type_name
|
6
|
-
@@media_type_name = 'application/json'
|
7
|
-
|
8
|
-
mattr_reader :headers
|
9
|
-
@@headers = {
|
10
|
-
:get => { 'Accept' => media_type_name },
|
11
|
-
:post => { 'Content-Type' => media_type_name }
|
12
|
-
}
|
13
|
-
|
14
|
-
mattr_reader :recipes
|
15
|
-
@@recipes = {}
|
16
|
-
|
17
|
-
def describe_recipe(recipe_name, options={}, &block)
|
18
|
-
raise 'Undefined recipe' unless block_given?
|
19
|
-
raise 'Undefined recipe_name' unless recipe_name
|
20
|
-
@@recipes[recipe_name] = block
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_json(obj = nil, options = {:root => {}}, &block)
|
24
|
-
# just instantiate the string with the atom factory
|
25
|
-
return Tokamak::Representation::Json.create(obj) if obj.kind_of?(String)
|
26
|
-
|
27
|
-
if block_given?
|
28
|
-
recipe = block
|
29
|
-
else
|
30
|
-
recipe = options[:recipe]
|
31
|
-
end
|
32
|
-
|
33
|
-
# Check if the object is already an json
|
34
|
-
unless recipe
|
35
|
-
if obj.kind_of?(Hash) || obj.kind_of?(Array)
|
36
|
-
return Tokamak::Representation::Json.create(obj)
|
37
|
-
else
|
38
|
-
raise Tokamak::ConverterError.new("Recipe required")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Get recipe already described
|
43
|
-
recipe = @@recipes[recipe] unless recipe.respond_to?(:call)
|
44
|
-
|
45
|
-
# Create representation and proxy
|
46
|
-
builder = Tokamak::Json::Builder.new(obj, (options[:root] || {}))
|
47
|
-
|
48
|
-
# Check recipe arity size before calling it
|
49
|
-
recipe.call(*[builder, obj, options][0,recipe.arity])
|
50
|
-
|
51
|
-
builder.representation
|
52
|
-
end
|
53
|
-
|
54
|
-
alias_method :unmarshal, :to_json
|
55
|
-
|
56
|
-
def to_hash(obj)
|
57
|
-
return obj if obj.kind_of?(Hash) || obj.kind_of?(Array)
|
58
|
-
|
59
|
-
if obj.kind_of?(::String)
|
60
|
-
Tokamak::Representation::Json.create(obj)
|
61
|
-
else
|
62
|
-
raise Tokamak::ConverterError.new("It was not possible to convert this object to a Hash")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_s(obj)
|
67
|
-
return obj if obj.kind_of?(String)
|
68
|
-
Tokamak::Representation::Json.create(obj).to_s
|
69
|
-
end
|
70
|
-
|
71
|
-
def marshal(obj, options = nil)
|
72
|
-
return obj if obj.kind_of? String
|
73
|
-
to_json(obj, options).to_json
|
74
|
-
end
|
75
|
-
|
76
|
-
# returns the current helper
|
77
|
-
def helper
|
78
|
-
Helpers
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/tokamak/json/helpers.rb
DELETED