almodovar-server 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +5 -0
- data/lib/almodovar-server.rb +11 -0
- data/lib/almodovar-server/resource_presenter.rb +61 -0
- data/lib/almodovar-server/resource_presenter/collection.rb +69 -0
- data/lib/almodovar-server/resource_presenter/html_serializer.rb +44 -0
- data/lib/almodovar-server/resource_presenter/json_serializer.rb +31 -0
- data/lib/almodovar-server/resource_presenter/link.rb +104 -0
- data/lib/almodovar-server/resource_presenter/metadata.rb +27 -0
- data/lib/almodovar-server/resource_presenter/serializer.rb +18 -0
- data/lib/almodovar-server/resource_presenter/template.html.erb +125 -0
- data/lib/almodovar-server/resource_presenter/xml_serializer.rb +25 -0
- data/lib/almodovar-server/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 042adda5c5a864f06ab2fc981ff6edf4dcca6e50
|
4
|
+
data.tar.gz: 37f2b4006bd09723713318a1038818267a7f2532
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa3861f56194e80b8305e5b9a01025d1cab8e7a2ed7fec1a8b03bb145879b2cb6a0f81bd0520b0bb2074bbd94cfb89cb0bfb148ec5ea9e1f27f5d4db91a774e2
|
7
|
+
data.tar.gz: fe49bd306bee95c790921053144d8e8bb9ff88742e5704e5f7fe9db48ca40b50447eb925f94e62d68685a1e9a821ebdecc21ba17ee1de02ab5c3950f6dac41f4
|
data/README.rdoc
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
=Almodovar Server Components {<img src="http://travis-ci.org/bebanjo/almodovar-server.png" />}[http://travis-ci.org/bebanjo/almodovar-server]
|
2
|
+
|
3
|
+
Server components to ease the creation of the awesome BeBanjo APIs
|
4
|
+
|
5
|
+
Copyright (c) 2010 BeBanjo S.L., released under the MIT license
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
begin
|
3
|
+
require 'active_support/all'
|
4
|
+
rescue LoadError
|
5
|
+
require 'active_support'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'almodovar-server/version' unless defined?(Almodovar::SERVER_VERSION)
|
9
|
+
require 'almodovar-server/resource_presenter'
|
10
|
+
require 'almodovar-server/resource_presenter/collection'
|
11
|
+
require 'almodovar-server/resource_presenter/link'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Almodovar
|
2
|
+
|
3
|
+
class ResourcePresenter
|
4
|
+
|
5
|
+
autoload :Serializer, 'almodovar-server/resource_presenter/serializer'
|
6
|
+
autoload :XmlSerializer, 'almodovar-server/resource_presenter/xml_serializer'
|
7
|
+
autoload :JsonSerializer, 'almodovar-server/resource_presenter/json_serializer'
|
8
|
+
autoload :HtmlSerializer, 'almodovar-server/resource_presenter/html_serializer'
|
9
|
+
autoload :Metadata, 'almodovar-server/resource_presenter/metadata'
|
10
|
+
|
11
|
+
extend Metadata
|
12
|
+
|
13
|
+
attr_accessor :url
|
14
|
+
|
15
|
+
def attributes
|
16
|
+
@attributes ||= ActiveSupport::OrderedHash.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def links
|
20
|
+
@links ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.resource_type
|
24
|
+
name.gsub(/Resource$/, '').underscore
|
25
|
+
end
|
26
|
+
|
27
|
+
def resource_class
|
28
|
+
self.class
|
29
|
+
end
|
30
|
+
|
31
|
+
def resource_type
|
32
|
+
resource_class.resource_type
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_xml(options = {})
|
36
|
+
XmlSerializer.new(self, options).to_xml
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_json(options = {})
|
40
|
+
JsonSerializer.new(self, options).to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def as_json(options = {})
|
44
|
+
JsonSerializer.new(self, options).as_json
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_html(options = {})
|
48
|
+
HtmlSerializer.new(self, options).to_html
|
49
|
+
end
|
50
|
+
|
51
|
+
def all_links
|
52
|
+
([link_to_self] + links).compact
|
53
|
+
end
|
54
|
+
|
55
|
+
def link_to_self
|
56
|
+
Link.new(:self, @url) if @url
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class ResourcePresenter
|
3
|
+
class Collection
|
4
|
+
|
5
|
+
attr_reader :resource_class
|
6
|
+
|
7
|
+
def initialize(resource_class, resources_args = [], options = {})
|
8
|
+
@resource_class = resource_class
|
9
|
+
@resources = resources_args.map { |arg| @resource_class.new(arg) }
|
10
|
+
|
11
|
+
@total = options[:total_entries]
|
12
|
+
@next = options[:next_link]
|
13
|
+
@prev = options[:prev_link]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_xml(options = {})
|
17
|
+
# Most of the following code is borrowed from ActiveSupport's Array#to_xml.
|
18
|
+
# We cannot use Array#to_xml because we need to add a few custom tags for
|
19
|
+
# pagination.
|
20
|
+
require 'active_support/builder' unless defined?(Builder)
|
21
|
+
|
22
|
+
options = options.dup
|
23
|
+
options[:indent] ||= 2
|
24
|
+
options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
|
25
|
+
|
26
|
+
xml = options[:builder]
|
27
|
+
|
28
|
+
xml.instruct! unless options[:skip_instruct]
|
29
|
+
xml.tag! resource_type.pluralize.dasherize, :type => 'array' do
|
30
|
+
xml.tag!('total-entries', @total) if @total
|
31
|
+
prev_link.to_xml(:builder => xml) if prev_link
|
32
|
+
next_link.to_xml(:builder => xml) if next_link
|
33
|
+
@resources.each { |value| value.to_xml(options.merge(:root => resource_type.singularize, :skip_instruct => true)) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def as_json(options = {})
|
38
|
+
message = ActiveSupport::OrderedHash.new.tap do |message|
|
39
|
+
message[:total_entries] = @total if @total
|
40
|
+
message.merge! prev_link.as_json if prev_link
|
41
|
+
message.merge! next_link.as_json if next_link
|
42
|
+
message[:entries] = @resources.map { |resource| resource.as_json(options) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_json(options = {})
|
47
|
+
require 'yajl'
|
48
|
+
Yajl::Encoder.encode(as_json(options), :pretty => true) + "\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_html(options = {})
|
52
|
+
HtmlSerializer.new(self, options).to_html
|
53
|
+
end
|
54
|
+
|
55
|
+
def resource_type
|
56
|
+
@resource_class.resource_type
|
57
|
+
end
|
58
|
+
|
59
|
+
def next_link
|
60
|
+
Link.new(:next, @next) if @next
|
61
|
+
end
|
62
|
+
|
63
|
+
def prev_link
|
64
|
+
Link.new(:prev, @prev) if @prev
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
%w(pygments.rb github-markdown).each do |lib|
|
2
|
+
begin
|
3
|
+
require lib.gsub('-', '/')
|
4
|
+
rescue LoadError => ex
|
5
|
+
raise ex, "In order to use the HtmlSerializer you need the gem `#{lib}` in your Gemfile"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Almodovar
|
10
|
+
class ResourcePresenter
|
11
|
+
class HtmlSerializer < Serializer
|
12
|
+
|
13
|
+
TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'template.html.erb')
|
14
|
+
|
15
|
+
def to_html
|
16
|
+
template = File.read(TEMPLATE_PATH)
|
17
|
+
ERB.new(template).result(binding)
|
18
|
+
end
|
19
|
+
|
20
|
+
def metadata
|
21
|
+
resource.resource_class.metadata
|
22
|
+
end
|
23
|
+
|
24
|
+
def beautify(representation, format)
|
25
|
+
body = Pygments.highlight(representation, :lexer => format)
|
26
|
+
body = body.gsub(/"(http\S+)"/) { url = $1; ""<a href=\"#{url}\">#{url}</a>"" }
|
27
|
+
body.html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
def metadata_text(text)
|
31
|
+
return if text.blank?
|
32
|
+
|
33
|
+
if indentation = text[/\n\s+/]
|
34
|
+
text = text.gsub(indentation, "\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
text = text.strip
|
38
|
+
text = GitHub::Markdown.render text
|
39
|
+
text.html_safe
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class ResourcePresenter
|
3
|
+
class JsonSerializer < Serializer
|
4
|
+
|
5
|
+
def to_json
|
6
|
+
require 'yajl'
|
7
|
+
Yajl::Encoder.encode(as_json, :pretty => true) + "\n"
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_json
|
11
|
+
ActiveSupport::OrderedHash[:resource_type, resource.resource_type].tap do |message|
|
12
|
+
message.merge! attributes_as_json
|
13
|
+
message.merge! links_as_json
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def attributes_as_json
|
20
|
+
resource.attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
def links_as_json
|
24
|
+
resource.all_links.inject(ActiveSupport::OrderedHash.new) do |message, link|
|
25
|
+
message.merge! link.as_json(options_for_link)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class ResourcePresenter
|
3
|
+
class Link
|
4
|
+
|
5
|
+
attr_reader :rel, :href, :expand_resource, :expand_args, :attributes
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
@rel, @href, @expand_resource, @expand_args, @attributes = args
|
9
|
+
@attributes ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_xml(options = {})
|
13
|
+
XmlSerializer.new(self, options.merge(:skip_instruct => true)).to_xml
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_json(options = {})
|
17
|
+
JsonSerializer.new(self, options).as_json
|
18
|
+
end
|
19
|
+
|
20
|
+
def resource
|
21
|
+
resource_collection? ? resource_collection : single_resource
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource_collection?
|
25
|
+
expand_args.is_a?(Array)
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource_collection
|
29
|
+
ResourcePresenter::Collection.new(expand_resource, expand_args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def single_resource
|
33
|
+
expand_resource.new(*[expand_args].compact)
|
34
|
+
end
|
35
|
+
|
36
|
+
def expand_resource?
|
37
|
+
expand_resource.present?
|
38
|
+
end
|
39
|
+
|
40
|
+
class Serializer
|
41
|
+
|
42
|
+
attr_reader :link, :options
|
43
|
+
|
44
|
+
def initialize(link, options)
|
45
|
+
@link = link
|
46
|
+
@options = options
|
47
|
+
end
|
48
|
+
|
49
|
+
def expands?
|
50
|
+
link.expand_resource? &&
|
51
|
+
Array(options[:expand]).include?(link.rel) &&
|
52
|
+
!Array(options[:dont_expand]).include?(link.href)
|
53
|
+
end
|
54
|
+
|
55
|
+
def dont_expand_link!
|
56
|
+
(options[:dont_expand] ||= []) << link.href
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
class XmlSerializer < Serializer
|
62
|
+
|
63
|
+
def to_xml
|
64
|
+
builder.link link.attributes.merge(:rel => link.rel, :href => link.href), &expand_block
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def builder
|
70
|
+
options[:builder]
|
71
|
+
end
|
72
|
+
|
73
|
+
def expand_block
|
74
|
+
Proc.new { expand_resource } if expands?
|
75
|
+
end
|
76
|
+
|
77
|
+
def expand_resource
|
78
|
+
dont_expand_link!
|
79
|
+
link.resource.to_xml(options)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
class JsonSerializer < Serializer
|
85
|
+
|
86
|
+
def as_json
|
87
|
+
ActiveSupport::OrderedHash.new.tap do |message|
|
88
|
+
message["#{link.rel}_link"] = link.href
|
89
|
+
message[link.rel] = expand_resource if expands?
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def expand_resource
|
96
|
+
dont_expand_link!
|
97
|
+
link.resource.as_json(options)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class ResourcePresenter
|
3
|
+
module Metadata
|
4
|
+
|
5
|
+
def inherited(base)
|
6
|
+
base.metadata[:name] = base.name.demodulize.titleize
|
7
|
+
end
|
8
|
+
|
9
|
+
def desc(description)
|
10
|
+
metadata[:desc] = description
|
11
|
+
end
|
12
|
+
|
13
|
+
def link(name, options)
|
14
|
+
metadata[:links][name] = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def attribute(name, options)
|
18
|
+
metadata[:attributes][name] = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def metadata
|
22
|
+
@metadata ||= Hash.new {|h,a| h[a] = ActiveSupport::OrderedHash.new}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class ResourcePresenter
|
3
|
+
class Serializer
|
4
|
+
|
5
|
+
attr_reader :resource, :options
|
6
|
+
|
7
|
+
def initialize(resource, options = {})
|
8
|
+
@resource = resource
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def options_for_link
|
13
|
+
options.merge(:dont_expand => Array(options[:dont_expand]) << resource.url)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<meta charset='utf-8'/>
|
5
|
+
<style type='text/css'>
|
6
|
+
.highlight .hll { background-color: #ffffcc }
|
7
|
+
.highlight { background: #f8f8f8; }
|
8
|
+
.highlight .c { color: #408080; font-style: italic } /* Comment */
|
9
|
+
.highlight .err { border: 1px solid #FF0000 } /* Error */
|
10
|
+
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
|
11
|
+
.highlight .o { color: #666666 } /* Operator */
|
12
|
+
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
|
13
|
+
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
|
14
|
+
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
15
|
+
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
|
16
|
+
.highlight .gd { color: #A00000 } /* Generic.Deleted */
|
17
|
+
.highlight .ge { font-style: italic } /* Generic.Emph */
|
18
|
+
.highlight .gr { color: #FF0000 } /* Generic.Error */
|
19
|
+
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
20
|
+
.highlight .gi { color: #00A000 } /* Generic.Inserted */
|
21
|
+
.highlight .go { color: #808080 } /* Generic.Output */
|
22
|
+
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
23
|
+
.highlight .gs { font-weight: bold } /* Generic.Strong */
|
24
|
+
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
25
|
+
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
|
26
|
+
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
|
27
|
+
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
|
28
|
+
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
|
29
|
+
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
|
30
|
+
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
|
31
|
+
.highlight .kt { color: #B00040 } /* Keyword.Type */
|
32
|
+
.highlight .m { color: #666666 } /* Literal.Number */
|
33
|
+
.highlight .s { color: #BA2121 } /* Literal.String */
|
34
|
+
.highlight .na { color: #7D9029 } /* Name.Attribute */
|
35
|
+
.highlight .nb { color: #008000 } /* Name.Builtin */
|
36
|
+
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
37
|
+
.highlight .no { color: #880000 } /* Name.Constant */
|
38
|
+
.highlight .nd { color: #AA22FF } /* Name.Decorator */
|
39
|
+
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
40
|
+
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
41
|
+
.highlight .nf { color: #0000FF } /* Name.Function */
|
42
|
+
.highlight .nl { color: #A0A000 } /* Name.Label */
|
43
|
+
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
44
|
+
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
|
45
|
+
.highlight .nv { color: #19177C } /* Name.Variable */
|
46
|
+
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
47
|
+
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
|
48
|
+
.highlight .mf { color: #666666 } /* Literal.Number.Float */
|
49
|
+
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
|
50
|
+
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
|
51
|
+
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
|
52
|
+
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
|
53
|
+
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
|
54
|
+
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
|
55
|
+
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
|
56
|
+
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
57
|
+
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
|
58
|
+
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
59
|
+
.highlight .sx { color: #008000 } /* Literal.String.Other */
|
60
|
+
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
|
61
|
+
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
|
62
|
+
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
|
63
|
+
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
|
64
|
+
.highlight .vc { color: #19177C } /* Name.Variable.Class */
|
65
|
+
.highlight .vg { color: #19177C } /* Name.Variable.Global */
|
66
|
+
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
|
67
|
+
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
|
68
|
+
|
69
|
+
body {
|
70
|
+
padding-top: 30px;
|
71
|
+
}
|
72
|
+
</style>
|
73
|
+
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
|
74
|
+
</head>
|
75
|
+
<body>
|
76
|
+
<div class='container'>
|
77
|
+
|
78
|
+
<ul class="nav nav-tabs">
|
79
|
+
<li><a href="#xml" data-toggle="tab">XML</a> </li>
|
80
|
+
<li><a href="#help" data-toggle="tab">Reference</a> </li>
|
81
|
+
</ul>
|
82
|
+
|
83
|
+
<div class="tab-content">
|
84
|
+
<div class="tab-pane" id="xml">
|
85
|
+
<%= beautify resource.to_xml(options), :xml %>
|
86
|
+
</div>
|
87
|
+
<div class="tab-pane" id="help">
|
88
|
+
<h2><%= metadata[:name] %></h2>
|
89
|
+
<%= metadata_text metadata[:desc] %>
|
90
|
+
<% if metadata[:attributes].present? %>
|
91
|
+
<h3>Attributes</h3>
|
92
|
+
<dl>
|
93
|
+
<% metadata[:attributes].each do |name, options| %>
|
94
|
+
<dt><%= name %></dt>
|
95
|
+
<dd><%= metadata_text options[:desc] %></dd>
|
96
|
+
<% end %>
|
97
|
+
</dl>
|
98
|
+
<% end %>
|
99
|
+
<% if metadata[:links].present? %>
|
100
|
+
<h3>Links</h3>
|
101
|
+
<dl>
|
102
|
+
<% metadata[:links].each do |name, options| %>
|
103
|
+
<dt><%= name %></dt>
|
104
|
+
<dd><%= metadata_text options[:desc] %></dd>
|
105
|
+
<% end %>
|
106
|
+
</dl>
|
107
|
+
<% end %>
|
108
|
+
</div>
|
109
|
+
</div>
|
110
|
+
|
111
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
|
112
|
+
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
|
113
|
+
<script>
|
114
|
+
$(function () {
|
115
|
+
var currentTab = localStorage.currentTab || '#xml'
|
116
|
+
$('ul.nav a[href="' + currentTab + '"]').tab('show')
|
117
|
+
|
118
|
+
$('a[data-toggle="tab"]').on('shown', function (e) {
|
119
|
+
localStorage.currentTab = $(e.target).attr('href')
|
120
|
+
})
|
121
|
+
})
|
122
|
+
</script>
|
123
|
+
</div>
|
124
|
+
</body>
|
125
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class ResourcePresenter
|
3
|
+
class XmlSerializer < Serializer
|
4
|
+
|
5
|
+
def to_xml
|
6
|
+
attributes_to_xml do |builder|
|
7
|
+
links_to_xml builder
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def attributes_to_xml(&block)
|
14
|
+
resource.attributes.to_xml(options.merge(:root => resource.resource_type), &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def links_to_xml(builder)
|
18
|
+
resource.all_links.each do |link|
|
19
|
+
link.to_xml(options_for_link.merge(:builder => builder))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: almodovar-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BeBanjo S.L.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: builder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yajl-ruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email: ballsbreaking@bebanjo.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- README.rdoc
|
89
|
+
files:
|
90
|
+
- README.rdoc
|
91
|
+
- lib/almodovar-server/resource_presenter/collection.rb
|
92
|
+
- lib/almodovar-server/resource_presenter/html_serializer.rb
|
93
|
+
- lib/almodovar-server/resource_presenter/json_serializer.rb
|
94
|
+
- lib/almodovar-server/resource_presenter/link.rb
|
95
|
+
- lib/almodovar-server/resource_presenter/metadata.rb
|
96
|
+
- lib/almodovar-server/resource_presenter/serializer.rb
|
97
|
+
- lib/almodovar-server/resource_presenter/template.html.erb
|
98
|
+
- lib/almodovar-server/resource_presenter/xml_serializer.rb
|
99
|
+
- lib/almodovar-server/resource_presenter.rb
|
100
|
+
- lib/almodovar-server/version.rb
|
101
|
+
- lib/almodovar-server.rb
|
102
|
+
homepage: http://github.com/bebanjo/almodovar-server/
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options:
|
107
|
+
- --main
|
108
|
+
- README.rdoc
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.0.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: BeBanjo API server components
|
127
|
+
test_files: []
|