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.
Files changed (91) hide show
  1. data/LICENSE +14 -0
  2. data/README.md +159 -0
  3. data/lib/tokamak/builder/base.rb +74 -0
  4. data/lib/tokamak/{json/builder.rb → builder/json.rb} +38 -29
  5. data/lib/tokamak/builder/values.rb +33 -0
  6. data/lib/tokamak/{atom/builder.rb → builder/xml.rb} +46 -41
  7. data/lib/tokamak/builder.rb +22 -0
  8. data/lib/tokamak/errors.rb +3 -0
  9. data/lib/tokamak/hook/rails.rb +78 -0
  10. data/lib/tokamak/hook/sinatra.rb +18 -0
  11. data/lib/tokamak/hook/tilt.rb +42 -0
  12. data/lib/tokamak/hook.rb +6 -0
  13. data/lib/tokamak/recipes.rb +26 -0
  14. data/lib/tokamak/version.rb +13 -0
  15. data/lib/tokamak.rb +14 -18
  16. data/script/console +7 -0
  17. data/test/rails2_skel/Rakefile +16 -0
  18. data/test/rails2_skel/app/controllers/application_controller.rb +1 -0
  19. data/test/rails2_skel/app/controllers/test_controller.rb +18 -0
  20. data/test/rails2_skel/app/views/test/_feed_member.tokamak +9 -0
  21. data/test/rails2_skel/app/views/test/feed.tokamak +24 -0
  22. data/test/rails2_skel/app/views/test/show.tokamak +31 -0
  23. data/test/rails2_skel/config/boot.rb +110 -0
  24. data/test/rails2_skel/config/environment.rb +20 -0
  25. data/test/rails2_skel/config/environments/development.rb +17 -0
  26. data/test/rails2_skel/config/environments/production.rb +28 -0
  27. data/test/rails2_skel/config/environments/test.rb +28 -0
  28. data/test/rails2_skel/config/initializers/cookie_verification_secret.rb +2 -0
  29. data/test/rails2_skel/config/initializers/mime_types.rb +3 -0
  30. data/test/rails2_skel/config/initializers/new_rails_defaults.rb +10 -0
  31. data/test/rails2_skel/config/initializers/session_store.rb +5 -0
  32. data/test/rails2_skel/config/routes.rb +43 -0
  33. data/test/rails2_skel/script/console +3 -0
  34. data/test/test_helper.rb +7 -0
  35. data/test/tokamak/builder/base_test.rb +28 -0
  36. data/test/tokamak/builder/json_test.rb +227 -0
  37. data/test/tokamak/builder/xml_test.rb +254 -0
  38. data/test/tokamak/helper_test.rb +106 -0
  39. data/test/tokamak/hook/rails_test.rb +74 -0
  40. data/test/tokamak/hook/sinatra_test.rb +85 -0
  41. data/test/tokamak/hook/tilt_test.rb +35 -0
  42. data/test/tokamak/recipes_test.rb +90 -0
  43. metadata +106 -113
  44. data/.document +0 -5
  45. data/.rspec +0 -1
  46. data/Gemfile +0 -27
  47. data/Gemfile.lock +0 -77
  48. data/LICENSE.txt +0 -20
  49. data/README.rdoc +0 -69
  50. data/Rakefile +0 -50
  51. data/VERSION +0 -1
  52. data/lib/tokamak/atom/base.rb +0 -87
  53. data/lib/tokamak/atom/helpers.rb +0 -13
  54. data/lib/tokamak/atom.rb +0 -8
  55. data/lib/tokamak/error.rb +0 -6
  56. data/lib/tokamak/json/base.rb +0 -83
  57. data/lib/tokamak/json/helpers.rb +0 -13
  58. data/lib/tokamak/json.rb +0 -10
  59. data/lib/tokamak/representation/atom/atom.rng +0 -597
  60. data/lib/tokamak/representation/atom/base.rb +0 -140
  61. data/lib/tokamak/representation/atom/category.rb +0 -39
  62. data/lib/tokamak/representation/atom/entry.rb +0 -56
  63. data/lib/tokamak/representation/atom/factory.rb +0 -48
  64. data/lib/tokamak/representation/atom/feed.rb +0 -108
  65. data/lib/tokamak/representation/atom/link.rb +0 -66
  66. data/lib/tokamak/representation/atom/person.rb +0 -46
  67. data/lib/tokamak/representation/atom/source.rb +0 -57
  68. data/lib/tokamak/representation/atom/tag_collection.rb +0 -36
  69. data/lib/tokamak/representation/atom/xml.rb +0 -94
  70. data/lib/tokamak/representation/atom.rb +0 -18
  71. data/lib/tokamak/representation/generic.rb +0 -20
  72. data/lib/tokamak/representation/json/base.rb +0 -25
  73. data/lib/tokamak/representation/json/keys_as_methods.rb +0 -72
  74. data/lib/tokamak/representation/json/link.rb +0 -27
  75. data/lib/tokamak/representation/json/link_collection.rb +0 -21
  76. data/lib/tokamak/representation/json.rb +0 -11
  77. data/lib/tokamak/representation/links.rb +0 -9
  78. data/lib/tokamak/representation.rb +0 -3
  79. data/lib/tokamak/values.rb +0 -29
  80. data/lib/tokamak/xml/base.rb +0 -60
  81. data/lib/tokamak/xml/builder.rb +0 -115
  82. data/lib/tokamak/xml/helpers.rb +0 -13
  83. data/lib/tokamak/xml/link.rb +0 -31
  84. data/lib/tokamak/xml/links.rb +0 -35
  85. data/lib/tokamak/xml.rb +0 -12
  86. data/spec/integration/atom/atom_spec.rb +0 -191
  87. data/spec/integration/full_atom.xml +0 -92
  88. data/spec/integration/full_json.js +0 -46
  89. data/spec/integration/json/json_spec.rb +0 -172
  90. data/spec/integration/xml/xml_spec.rb +0 -203
  91. 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
@@ -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
@@ -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
@@ -1,8 +0,0 @@
1
- module Tokamak
2
- module Atom
3
- autoload :Base, 'tokamak/atom/base'
4
- autoload :Builder, 'tokamak/atom/builder'
5
- autoload :Helpers, 'tokamak/atom/helpers'
6
- extend Base::ClassMethods
7
- end
8
- end
data/lib/tokamak/error.rb DELETED
@@ -1,6 +0,0 @@
1
- module Tokamak
2
- class Error < StandardError
3
- end
4
- class ConverterError < Error
5
- end
6
- end
@@ -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
@@ -1,13 +0,0 @@
1
- module Tokamak
2
- module Json
3
- module Helpers
4
- def collection(obj, *args, &block)
5
- Tokamak::Json.to_json(obj, &block)
6
- end
7
-
8
- def member(obj, *args, &block)
9
- Tokamak::Json.to_json(obj, &block)
10
- end
11
- end
12
- end
13
- end
data/lib/tokamak/json.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'json'
2
-
3
- module Tokamak
4
- module Json
5
- autoload :Base, 'tokamak/json/base'
6
- autoload :Builder, 'tokamak/json/builder'
7
- autoload :Helpers, 'tokamak/json/helpers'
8
- extend Base::ClassMethods
9
- end
10
- end