amy 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +50 -0
- data/bin/amy +12 -0
- data/lib/amy/generate.rb +23 -0
- data/lib/amy/parser/defs.rb +25 -0
- data/lib/amy/parser/lexer.rb +118 -0
- data/lib/amy/parser/parser.rb +91 -0
- data/lib/amy/parser/tokens.rb +39 -0
- data/lib/amy/parser.rb +129 -0
- data/lib/amy/templates/main.rb +36 -0
- data/lib/amy.rb +8 -0
- data/views/js/amy.coffee +79 -0
- data/views/js/amy.js +301 -0
- data/views/js/amy.min.js +1 -0
- data/views/js/form.coffee +69 -0
- data/views/js/resource.coffee +57 -0
- data/views/js/utils.coffee +17 -0
- data/views/main.erb.html +40 -0
- data/views/style/style.css +444 -0
- metadata +205 -0
data/views/js/amy.js
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var MethodRunner, Resource, ResourceForm, Tabelle, Utils;
|
4
|
+
|
5
|
+
Tabelle = (function() {
|
6
|
+
function Tabelle() {
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
|
10
|
+
Tabelle.prototype.setup = function(url) {
|
11
|
+
var request_config, self;
|
12
|
+
self = this;
|
13
|
+
request_config = {
|
14
|
+
url: url + "?date=" + (new Date()).getTime(),
|
15
|
+
type: "GET",
|
16
|
+
dataType: "json",
|
17
|
+
success: function(data) {
|
18
|
+
var config, i, resource, _ref;
|
19
|
+
$('.resources div').remove();
|
20
|
+
i = 0;
|
21
|
+
_ref = data['resources'];
|
22
|
+
for (resource in _ref) {
|
23
|
+
config = _ref[resource];
|
24
|
+
resource = self.add_resource(resource, config, i, data['base_url']);
|
25
|
+
resource.toggle();
|
26
|
+
i++;
|
27
|
+
}
|
28
|
+
self.add_resource_events(data);
|
29
|
+
return self.toggle_method_if_necessary();
|
30
|
+
},
|
31
|
+
error: function(e) {
|
32
|
+
return $('.resources div').remove();
|
33
|
+
}
|
34
|
+
};
|
35
|
+
$.ajax(request_config);
|
36
|
+
};
|
37
|
+
|
38
|
+
Tabelle.prototype.add_resource = function(name, resource, i, base_url) {
|
39
|
+
if (base_url == null) {
|
40
|
+
base_url = "";
|
41
|
+
}
|
42
|
+
resource = new Resource(name, resource, i, base_url);
|
43
|
+
resource.build();
|
44
|
+
return resource;
|
45
|
+
};
|
46
|
+
|
47
|
+
Tabelle.prototype.add_resource_events = function(data) {
|
48
|
+
var handlerIn, handlerOut;
|
49
|
+
handlerIn = function() {
|
50
|
+
$(this).css("background", "#f5f5f5");
|
51
|
+
$(this).children('div').children().css('color', 'black');
|
52
|
+
};
|
53
|
+
handlerOut = function() {
|
54
|
+
$(this).css("background", "#fff");
|
55
|
+
$(this).children('div').children().css('color', '#999');
|
56
|
+
};
|
57
|
+
$(".resource").hover(handlerIn, handlerOut);
|
58
|
+
$('.resource').click(function() {
|
59
|
+
event.stopPropagation();
|
60
|
+
$(this).next().fadeToggle();
|
61
|
+
});
|
62
|
+
};
|
63
|
+
|
64
|
+
Tabelle.prototype.toggle_method_if_necessary = function() {
|
65
|
+
var anchor, fields;
|
66
|
+
anchor = window.location.hash.replace('!', '');
|
67
|
+
anchor = anchor.replace(/\//g, "\\/");
|
68
|
+
anchor = anchor.replace(/:/g, '\\:');
|
69
|
+
fields = anchor.split('#');
|
70
|
+
$("#" + fields[1] + " + div .method." + fields[2] + " .content").fadeToggle();
|
71
|
+
$("#" + fields[1] + " + div .method." + fields[2] + " .form").fadeToggle();
|
72
|
+
$("#" + fields[1]).next().fadeToggle();
|
73
|
+
};
|
74
|
+
|
75
|
+
Tabelle.toggleMethods = function(i) {
|
76
|
+
event.stopPropagation();
|
77
|
+
$("#resource" + i).fadeToggle();
|
78
|
+
};
|
79
|
+
|
80
|
+
Tabelle.showJSON = function() {
|
81
|
+
var url;
|
82
|
+
event.stopPropagation();
|
83
|
+
url = $("#selector #key").val();
|
84
|
+
if (url) {
|
85
|
+
window.open(url, "_self");
|
86
|
+
}
|
87
|
+
};
|
88
|
+
|
89
|
+
window.toggleMethods = Tabelle.toggleMethods;
|
90
|
+
|
91
|
+
window.showJSON = Tabelle.showJSON;
|
92
|
+
|
93
|
+
return Tabelle;
|
94
|
+
|
95
|
+
})();
|
96
|
+
|
97
|
+
$(document).ready(function() {
|
98
|
+
var tabelle, url, utils;
|
99
|
+
tabelle = new Tabelle;
|
100
|
+
utils = new Utils;
|
101
|
+
utils.toggle_by_class('content');
|
102
|
+
url = utils.default_config_url();
|
103
|
+
$('#header #selector input').val(url);
|
104
|
+
tabelle.setup(url);
|
105
|
+
$('#header #explore').click(function() {
|
106
|
+
return tabelle.setup($('#header #selector input').val());
|
107
|
+
});
|
108
|
+
});
|
109
|
+
|
110
|
+
ResourceForm = (function() {
|
111
|
+
function ResourceForm(method, config) {
|
112
|
+
this.method = method;
|
113
|
+
this.config = config;
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
|
117
|
+
ResourceForm.prototype.build = function() {
|
118
|
+
var html, params, _ref;
|
119
|
+
html = '';
|
120
|
+
params = this.config['params'] || [];
|
121
|
+
if ((_ref = this.method) === "get" || _ref === "options" || _ref === "head") {
|
122
|
+
html = this.add_form(params);
|
123
|
+
}
|
124
|
+
return html;
|
125
|
+
};
|
126
|
+
|
127
|
+
ResourceForm.prototype.add_form = function(params) {
|
128
|
+
var html, param, _i, _len;
|
129
|
+
html = '<form>';
|
130
|
+
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
131
|
+
param = params[_i];
|
132
|
+
html += "<div class='field'>";
|
133
|
+
html += "<label>:" + param[0] + "<small>(" + param[1] + ")</small></label>";
|
134
|
+
html += "<input type='text' id='" + param[0] + "'></input>";
|
135
|
+
html += '</div>';
|
136
|
+
}
|
137
|
+
html += '<input type="button" value="Submit"></input>';
|
138
|
+
html += '</form>';
|
139
|
+
html += '<textarea class="output"></textarea>';
|
140
|
+
return html;
|
141
|
+
};
|
142
|
+
|
143
|
+
return ResourceForm;
|
144
|
+
|
145
|
+
})();
|
146
|
+
|
147
|
+
MethodRunner = (function() {
|
148
|
+
function MethodRunner(method, config, base_url, i) {
|
149
|
+
this.method = method;
|
150
|
+
this.config = config;
|
151
|
+
this.base_url = base_url;
|
152
|
+
this.i = i;
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
MethodRunner.prototype.attach_to_form = function() {
|
157
|
+
var self;
|
158
|
+
self = this;
|
159
|
+
$("#resource" + this.i + " ." + this.method + " .form input[type=button]").click(function(event) {
|
160
|
+
var config, outputField, params;
|
161
|
+
params = self.scrap_params(event);
|
162
|
+
outputField = $(event.target).parent().siblings('.output');
|
163
|
+
config = self.config[self.method];
|
164
|
+
return self.execute_method(self.method.toUpperCase(), self.base_url, config, params, outputField);
|
165
|
+
});
|
166
|
+
};
|
167
|
+
|
168
|
+
MethodRunner.prototype.scrap_params = function(event) {
|
169
|
+
var fields, oid, params;
|
170
|
+
oid = $(event.target).parentsUntil(".methods");
|
171
|
+
oid = $($(oid)[oid.length - 1]).parent().prev().attr('id');
|
172
|
+
fields = $(event.target).parent().children('.field').children('input');
|
173
|
+
params = {};
|
174
|
+
$.each(fields, function(i, n) {
|
175
|
+
params[$(n).attr('id')] = $(n).val();
|
176
|
+
});
|
177
|
+
return params;
|
178
|
+
};
|
179
|
+
|
180
|
+
MethodRunner.prototype.execute_method = function(method, base_url, config, params, output) {
|
181
|
+
var ajax_call, oid, param, url;
|
182
|
+
url = "" + base_url + config['url'];
|
183
|
+
for (oid in params) {
|
184
|
+
param = params[oid];
|
185
|
+
url = url.replace(':' + oid, param);
|
186
|
+
}
|
187
|
+
ajax_call = {
|
188
|
+
type: method,
|
189
|
+
async: true,
|
190
|
+
url: url,
|
191
|
+
success: function(data) {
|
192
|
+
output.text(JSON.stringify(data));
|
193
|
+
}
|
194
|
+
};
|
195
|
+
$.ajax(ajax_call);
|
196
|
+
};
|
197
|
+
|
198
|
+
return MethodRunner;
|
199
|
+
|
200
|
+
})();
|
201
|
+
|
202
|
+
Resource = (function() {
|
203
|
+
function Resource(resource, config, i, base_url) {
|
204
|
+
this.resource = resource;
|
205
|
+
this.config = config;
|
206
|
+
this.i = i;
|
207
|
+
this.base_url = base_url;
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
|
211
|
+
Resource.prototype.toggle = function() {
|
212
|
+
$("#resource" + this.i).toggle();
|
213
|
+
};
|
214
|
+
|
215
|
+
Resource.prototype.build = function() {
|
216
|
+
var data, html, method, runner, _ref;
|
217
|
+
html = this.build_html(this.resource, this.config, this.i);
|
218
|
+
$('.resources').append(html);
|
219
|
+
_ref = this.config['config'];
|
220
|
+
for (method in _ref) {
|
221
|
+
data = _ref[method];
|
222
|
+
runner = new MethodRunner(method, this.config['config'], this.base_url, this.i);
|
223
|
+
runner.attach_to_form();
|
224
|
+
}
|
225
|
+
$("#resource" + this.i + " .content").toggle();
|
226
|
+
$("#resource" + this.i + " .form").toggle();
|
227
|
+
$("#resource" + this.i + " .method .url a").click(function(event) {
|
228
|
+
$(this).parent().parent().next().next().fadeToggle();
|
229
|
+
return $(this).parent().parent().next().fadeToggle();
|
230
|
+
});
|
231
|
+
};
|
232
|
+
|
233
|
+
Resource.prototype.build_html = function(resource, config, i) {
|
234
|
+
var html;
|
235
|
+
html = "<div class='resource' id='" + resource + "'>";
|
236
|
+
html += "<div class='name'> <a href='#!" + resource + "'>" + resource + "</a> </div>";
|
237
|
+
html += "<div class='title'>" + config['title'] + "</div>";
|
238
|
+
html += "<div class='menu'> <a href='#' onclick='toggleMethods(" + i + ")'>Show/Hide</a> | <a href='#' onclick='showJSON()'>Raw</a> </div>";
|
239
|
+
html += '</div>';
|
240
|
+
html += this.add_section(resource, config['config'], config['config'], i);
|
241
|
+
return html;
|
242
|
+
};
|
243
|
+
|
244
|
+
Resource.prototype.add_section = function(resource, config, entries, i) {
|
245
|
+
var content, field, html, method, method_name;
|
246
|
+
html = "<div class='methods' id='resource" + i + "'>";
|
247
|
+
for (method in config) {
|
248
|
+
field = config[method];
|
249
|
+
method_name = method.replace(/(\d+)/g, '');
|
250
|
+
content = entries[method.toLowerCase()]['content'];
|
251
|
+
html += "<div class='method " + method_name + "'>";
|
252
|
+
html += '<div class="header">';
|
253
|
+
html += "<div class='name " + method_name + "'>" + method_name + "</div>";
|
254
|
+
html += "<div class='url'><a href='#!" + resource + "#" + (method.toLowerCase()) + "'>" + field['url'] + "</a></div>";
|
255
|
+
html += "<div class='desc'>" + field['title'] + "</div>";
|
256
|
+
html += '</div>';
|
257
|
+
html += "<div class='form'>" + (this.add_form(method.toLowerCase(), entries[method.toLowerCase()])) + "</div>";
|
258
|
+
html += "<div class='content'>" + content + "</div>";
|
259
|
+
html += "</div>";
|
260
|
+
}
|
261
|
+
html += '</div>';
|
262
|
+
return html;
|
263
|
+
};
|
264
|
+
|
265
|
+
Resource.prototype.add_form = function(method, config) {
|
266
|
+
var form;
|
267
|
+
form = new ResourceForm(method, config);
|
268
|
+
return form.build();
|
269
|
+
};
|
270
|
+
|
271
|
+
return Resource;
|
272
|
+
|
273
|
+
})();
|
274
|
+
|
275
|
+
Utils = (function() {
|
276
|
+
function Utils() {
|
277
|
+
return;
|
278
|
+
}
|
279
|
+
|
280
|
+
Utils.prototype.toggle_by_class = function(clazz) {
|
281
|
+
var elem, elems, _i, _len;
|
282
|
+
elems = document.getElementsByClassName(clazz);
|
283
|
+
for (_i = 0, _len = elems.length; _i < _len; _i++) {
|
284
|
+
elem = elems[_i];
|
285
|
+
console.log(elem);
|
286
|
+
$(elem).toggle(false);
|
287
|
+
}
|
288
|
+
};
|
289
|
+
|
290
|
+
Utils.prototype.default_config_url = function() {
|
291
|
+
var pn;
|
292
|
+
pn = window.location.pathname;
|
293
|
+
pn = pn.replace(pn.substring(pn.lastIndexOf('/') + 1, pn.length), '');
|
294
|
+
return "" + window.location.origin + pn + "data.json";
|
295
|
+
};
|
296
|
+
|
297
|
+
return Utils;
|
298
|
+
|
299
|
+
})();
|
300
|
+
|
301
|
+
}).call(this);
|
data/views/js/amy.min.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
(function(){var t,e,o,n,r;n=function(){function t(){}return t.prototype.setup=function(t){var e,o;o=this,e={url:t+"?date="+(new Date).getTime(),type:"GET",dataType:"json",success:function(t){var e,n,r,i;$(".resources div").remove(),n=0,i=t.resources;for(r in i)e=i[r],r=o.add_resource(r,e,n,t.base_url),r.toggle(),n++;return o.add_resource_events(t),o.toggle_method_if_necessary()},error:function(){return $(".resources div").remove()}},$.ajax(e)},t.prototype.add_resource=function(t,o,n,r){return null==r&&(r=""),o=new e(t,o,n,r),o.build(),o},t.prototype.add_resource_events=function(){var t,e;t=function(){$(this).css("background","#f5f5f5"),$(this).children("div").children().css("color","black")},e=function(){$(this).css("background","#fff"),$(this).children("div").children().css("color","#999")},$(".resource").hover(t,e),$(".resource").click(function(){event.stopPropagation(),$(this).next().fadeToggle()})},t.prototype.toggle_method_if_necessary=function(){var t,e;t=window.location.hash.replace("!",""),t=t.replace(/\//g,"\\/"),t=t.replace(/:/g,"\\:"),e=t.split("#"),$("#"+e[1]+" + div .method."+e[2]+" .content").fadeToggle(),$("#"+e[1]+" + div .method."+e[2]+" .form").fadeToggle(),$("#"+e[1]).next().fadeToggle()},t.toggleMethods=function(t){event.stopPropagation(),$("#resource"+t).fadeToggle()},t.showJSON=function(){var t;event.stopPropagation(),t=$("#selector #key").val(),t&&window.open(t,"_self")},window.toggleMethods=t.toggleMethods,window.showJSON=t.showJSON,t}(),$(document).ready(function(){var t,e,o;t=new n,o=new r,o.toggle_by_class("content"),e=o.default_config_url(),$("#header #selector input").val(e),t.setup(e),$("#header #explore").click(function(){return t.setup($("#header #selector input").val())})}),o=function(){function t(t,e){this.method=t,this.config=e}return t.prototype.build=function(){var t,e,o;return t="",e=this.config.params||[],("get"===(o=this.method)||"options"===o||"head"===o)&&(t=this.add_form(e)),t},t.prototype.add_form=function(t){var e,o,n,r;for(e="<form>",n=0,r=t.length;r>n;n++)o=t[n],e+="<div class='field'>",e+="<label>:"+o[0]+"<small>("+o[1]+")</small></label>",e+="<input type='text' id='"+o[0]+"'></input>",e+="</div>";return e+='<input type="button" value="Submit"></input>',e+="</form>",e+='<textarea class="output"></textarea>'},t}(),t=function(){function t(t,e,o,n){this.method=t,this.config=e,this.base_url=o,this.i=n}return t.prototype.attach_to_form=function(){var t;t=this,$("#resource"+this.i+" ."+this.method+" .form input[type=button]").click(function(e){var o,n,r;return r=t.scrap_params(e),n=$(e.target).parent().siblings(".output"),o=t.config[t.method],t.execute_method(t.method.toUpperCase(),t.base_url,o,r,n)})},t.prototype.scrap_params=function(t){var e,o,n;return o=$(t.target).parentsUntil(".methods"),o=$($(o)[o.length-1]).parent().prev().attr("id"),e=$(t.target).parent().children(".field").children("input"),n={},$.each(e,function(t,e){n[$(e).attr("id")]=$(e).val()}),n},t.prototype.execute_method=function(t,e,o,n,r){var i,s,a,c;c=""+e+o.url;for(s in n)a=n[s],c=c.replace(":"+s,a);i={type:t,async:!0,url:c,success:function(t){r.text(JSON.stringify(t))}},$.ajax(i)},t}(),e=function(){function e(t,e,o,n){this.resource=t,this.config=e,this.i=o,this.base_url=n}return e.prototype.toggle=function(){$("#resource"+this.i).toggle()},e.prototype.build=function(){var e,o,n,r,i;o=this.build_html(this.resource,this.config,this.i),$(".resources").append(o),i=this.config.config;for(n in i)e=i[n],r=new t(n,this.config.config,this.base_url,this.i),r.attach_to_form();$("#resource"+this.i+" .content").toggle(),$("#resource"+this.i+" .form").toggle(),$("#resource"+this.i+" .method .url a").click(function(){return $(this).parent().parent().next().next().fadeToggle(),$(this).parent().parent().next().fadeToggle()})},e.prototype.build_html=function(t,e,o){var n;return n="<div class='resource' id='"+t+"'>",n+="<div class='name'> <a href='#!"+t+"'>"+t+"</a> </div>",n+="<div class='title'>"+e.title+"</div>",n+="<div class='menu'> <a href='#' onclick='toggleMethods("+o+")'>Show/Hide</a> | <a href='#' onclick='showJSON()'>Raw</a> </div>",n+="</div>",n+=this.add_section(t,e.config,e.config,o)},e.prototype.add_section=function(t,e,o,n){var r,i,s,a,c;s="<div class='methods' id='resource"+n+"'>";for(a in e)i=e[a],c=a.replace(/(\d+)/g,""),r=o[a.toLowerCase()].content,s+="<div class='method "+c+"'>",s+='<div class="header">',s+="<div class='name "+c+"'>"+c+"</div>",s+="<div class='url'><a href='#!"+t+"#"+a.toLowerCase()+"'>"+i.url+"</a></div>",s+="<div class='desc'>"+i.title+"</div>",s+="</div>",s+="<div class='form'>"+this.add_form(a.toLowerCase(),o[a.toLowerCase()])+"</div>",s+="<div class='content'>"+r+"</div>",s+="</div>";return s+="</div>"},e.prototype.add_form=function(t,e){var n;return n=new o(t,e),n.build()},e}(),r=function(){function t(){}return t.prototype.toggle_by_class=function(t){var e,o,n,r;for(o=document.getElementsByClassName(t),n=0,r=o.length;r>n;n++)e=o[n],console.log(e),$(e).toggle(!1)},t.prototype.default_config_url=function(){var t;return t=window.location.pathname,t=t.replace(t.substring(t.lastIndexOf("/")+1,t.length),""),""+window.location.origin+t+"data.json"},t}()}).call(this);
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class ResourceForm
|
2
|
+
|
3
|
+
constructor: (method, config) ->
|
4
|
+
@method = method
|
5
|
+
@config = config
|
6
|
+
return
|
7
|
+
|
8
|
+
build: ->
|
9
|
+
html = ''
|
10
|
+
params = @config['params'] || []
|
11
|
+
if @method in ["get", "options", "head"]
|
12
|
+
html = this.add_form(params)
|
13
|
+
return html
|
14
|
+
|
15
|
+
add_form: (params) ->
|
16
|
+
html = '<form>'
|
17
|
+
for param in params
|
18
|
+
html += "<div class='field'>"
|
19
|
+
html += "<label>:#{param[0]}<small>(#{param[1]})</small></label>"
|
20
|
+
html += "<input type='text' id='#{param[0]}'></input>"
|
21
|
+
html += '</div>'
|
22
|
+
html += '<input type="button" value="Submit"></input>'
|
23
|
+
html += '</form>'
|
24
|
+
html += '<textarea class="output"></textarea>'
|
25
|
+
return html
|
26
|
+
|
27
|
+
class MethodRunner
|
28
|
+
|
29
|
+
constructor: (method, config, base_url, i) ->
|
30
|
+
@method = method
|
31
|
+
@config = config
|
32
|
+
@base_url = base_url
|
33
|
+
@i = i
|
34
|
+
return
|
35
|
+
|
36
|
+
attach_to_form: ->
|
37
|
+
self = this
|
38
|
+
$("#resource#{@i} .#{@method} .form input[type=button]").click (event) ->
|
39
|
+
params = self.scrap_params event
|
40
|
+
outputField = $(event.target).parent().siblings('.output')
|
41
|
+
config = self.config[self.method]
|
42
|
+
self.execute_method(self.method.toUpperCase(), self.base_url, config, params, outputField)
|
43
|
+
return
|
44
|
+
|
45
|
+
scrap_params: (event) ->
|
46
|
+
oid = $(event.target).parentsUntil(".methods")
|
47
|
+
oid = $($(oid)[oid.length-1]).parent().prev().attr('id')
|
48
|
+
fields = $(event.target).parent().children('.field').children('input')
|
49
|
+
params = {}
|
50
|
+
$.each fields, (i, n) ->
|
51
|
+
params[$(n).attr('id')] = $(n).val()
|
52
|
+
return
|
53
|
+
return params
|
54
|
+
|
55
|
+
execute_method: (method, base_url, config, params, output) ->
|
56
|
+
url = "#{base_url}#{config['url']}"
|
57
|
+
for oid, param of params
|
58
|
+
url = url.replace(':'+oid, param)
|
59
|
+
ajax_call =
|
60
|
+
type: method
|
61
|
+
async: true
|
62
|
+
url: url
|
63
|
+
success: (data) ->
|
64
|
+
output.text(JSON.stringify(data))
|
65
|
+
return
|
66
|
+
$.ajax ajax_call
|
67
|
+
return
|
68
|
+
|
69
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Resource
|
2
|
+
|
3
|
+
constructor: (resource, config, i, base_url) ->
|
4
|
+
@resource = resource
|
5
|
+
@config = config
|
6
|
+
@i = i
|
7
|
+
@base_url = base_url
|
8
|
+
return
|
9
|
+
|
10
|
+
toggle: ->
|
11
|
+
$("#resource#{@i}").toggle()
|
12
|
+
return
|
13
|
+
|
14
|
+
build: ->
|
15
|
+
html = this.build_html(@resource, @config, @i)
|
16
|
+
$('.resources').append(html)
|
17
|
+
for method, data of @config['config']
|
18
|
+
runner = new MethodRunner(method, @config['config'], @base_url, @i)
|
19
|
+
runner.attach_to_form()
|
20
|
+
|
21
|
+
$("#resource#{@i} .content").toggle()
|
22
|
+
$("#resource#{@i} .form").toggle()
|
23
|
+
$("#resource#{@i} .method .url a").click (event) ->
|
24
|
+
$(this).parent().parent().next().next().fadeToggle()
|
25
|
+
$(this).parent().parent().next().fadeToggle()
|
26
|
+
return
|
27
|
+
|
28
|
+
build_html: (resource, config, i) ->
|
29
|
+
html = "<div class='resource' id='#{resource}'>"
|
30
|
+
html += "<div class='name'> <a href='#!#{resource}'>#{resource}</a> </div>"
|
31
|
+
html += "<div class='title'>#{config['title']}</div>"
|
32
|
+
html += "<div class='menu'> <a href='#' onclick='toggleMethods(#{i})'>Show/Hide</a> | <a href='#' onclick='showJSON()'>Raw</a> </div>"
|
33
|
+
html += '</div>'
|
34
|
+
html += this.add_section(resource, config['config'], config['config'], i)
|
35
|
+
return html
|
36
|
+
|
37
|
+
add_section: (resource, config, entries, i) ->
|
38
|
+
html = "<div class='methods' id='resource#{i}'>"
|
39
|
+
for method, field of config
|
40
|
+
method_name = method.replace(/(\d+)/g,'')
|
41
|
+
content = entries[method.toLowerCase()]['content']
|
42
|
+
html += "<div class='method #{method_name}'>"
|
43
|
+
html += '<div class="header">'
|
44
|
+
html += "<div class='name #{method_name}'>#{method_name}</div>"
|
45
|
+
html += "<div class='url'><a href='#!#{resource}##{method.toLowerCase()}'>#{field['url']}</a></div>"
|
46
|
+
html += "<div class='desc'>#{field['title']}</div>"
|
47
|
+
html += '</div>'
|
48
|
+
html += "<div class='form'>#{this.add_form(method.toLowerCase(), entries[method.toLowerCase()])}</div>"
|
49
|
+
html += "<div class='content'>#{content}</div>"
|
50
|
+
html += "</div>"
|
51
|
+
html += '</div>'
|
52
|
+
return html
|
53
|
+
|
54
|
+
add_form: (method, config) ->
|
55
|
+
form = new ResourceForm(method, config)
|
56
|
+
return form.build()
|
57
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Utils
|
2
|
+
|
3
|
+
constructor: ->
|
4
|
+
return
|
5
|
+
|
6
|
+
toggle_by_class: (clazz) ->
|
7
|
+
elems = document.getElementsByClassName(clazz)
|
8
|
+
for elem in elems
|
9
|
+
console.log elem
|
10
|
+
$(elem).toggle(false)
|
11
|
+
return
|
12
|
+
|
13
|
+
default_config_url: ->
|
14
|
+
pn = window.location.pathname
|
15
|
+
pn = pn.replace(pn.substring(pn.lastIndexOf('/')+1, pn.length), '')
|
16
|
+
return "#{window.location.origin}#{pn}data.json"
|
17
|
+
|
data/views/main.erb.html
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
4
|
+
<link rel="stylesheet" href="style/style.css" />
|
5
|
+
<script src="js/amy.js"></script>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<div id="page">
|
9
|
+
<div id="header">
|
10
|
+
<div class="title">
|
11
|
+
<h1>REST API Documentation</h1>
|
12
|
+
<h4><%= @base_url %></h4>
|
13
|
+
</div>
|
14
|
+
<form id="selector">
|
15
|
+
<input type="text" id="key"/>
|
16
|
+
<a href="#" class="button green" id="explore">Explore</a>
|
17
|
+
</form>
|
18
|
+
</div>
|
19
|
+
<div id="body">
|
20
|
+
<% unless @links.empty? %>
|
21
|
+
<div class="navmenu">
|
22
|
+
<div id="navigation_container">
|
23
|
+
<div class="rectangle">
|
24
|
+
<ul class="navigation_bar">
|
25
|
+
<li> <h3>Quick links</h3> </li>
|
26
|
+
<% @links.each do |link| %>
|
27
|
+
<li><a href="<%= "#{@base_url}#{link[1]}" %>"><%= link[0] %></a></li>
|
28
|
+
<% end %>
|
29
|
+
</ul>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
<% end %>
|
34
|
+
<div class="resources"></div>
|
35
|
+
<div class="footer">
|
36
|
+
[ <div class="base_url"> BASE_URL: <%= @base_url %> </div> | <div class="version"> API_VERSION: <%= @apiversion %></div> ]
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
</body>
|
40
|
+
</html>
|