picatrix 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/.gitignore +37 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +130 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/picapica +6 -0
- data/bin/setup +7 -0
- data/lib/picatrix.rb +28 -0
- data/lib/picatrix/digraph_parser.rb +137 -0
- data/lib/picatrix/generated/.rb +46 -0
- data/lib/picatrix/generated/app.rb +88 -0
- data/lib/picatrix/generated/view_submission.rb +24 -0
- data/lib/picatrix/jenny.rb +175 -0
- data/lib/picatrix/pacman.rb +17 -0
- data/lib/picatrix/schemas/view_submission_item.json +12 -0
- data/lib/picatrix/templates/app.rb +33 -0
- data/lib/picatrix/templates/mason/submission_filter_template.json +4 -0
- data/lib/picatrix/templates/mason/view_submission.json +30 -0
- data/lib/picatrix/templates/mason/view_submission_min.json +11 -0
- data/lib/picatrix/templates/mason/view_submissions.json +32 -0
- data/lib/picatrix/templates/type.rb +24 -0
- data/lib/picatrix/transform_to_hash.rb +51 -0
- data/lib/picatrix/version.rb +3 -0
- data/picatrix.gemspec +37 -0
- metadata +269 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/json'
|
3
|
+
require 'require_all'
|
4
|
+
|
5
|
+
require_all("./lib/picatrix/generated/*.rb")
|
6
|
+
|
7
|
+
class App < Sinatra::Base
|
8
|
+
set :public_folder => "public", :static => true
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
status, headers, body = call env.merge("PATH_INFO" => "/welcome/newest")
|
12
|
+
[status, headers, body]
|
13
|
+
end
|
14
|
+
|
15
|
+
get "/welcome/newest" do
|
16
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"href"=>"http://localhost:9292/welcome/newest"}, "is:filter"=>{"href"=>"http://localhost:9292/submission_filter_template/filter?category={category}&has_photo={has_photo}", "isHrefTemplate"=>true, "title"=>"filter submissions by category", "description"=>"in addition to category, you can ensure the submission has a photo"}, "is:add"=>{"title"=>"add new submission", "encoding"=>"json", "href"=>"http://localhost:9292/submission_add_template/submit", "method"=>"POST", "template"=>{"title"=>"default title", "category"=>"cats", "photo_url"=>"http://cats.com"}}}, "submissions"=>[{"@controls"=>{"self"=>{"title"=>"submission 1", "href"=>"http://localhost:9292/view_submission/1"}}, "id"=>1, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg"}, {"@controls"=>{"self"=>{"title"=>"submission 2", "href"=>"http://localhost:9292/view_submission/2"}}, "id"=>2, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/icqDxNab3Do/maxresdefault.jpg"}]})
|
17
|
+
end
|
18
|
+
|
19
|
+
get "/submission_filter_template/filter" do
|
20
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"href"=>"http://localhost:9292/welcome/newest"}, "is:filter"=>{"href"=>"http://localhost:9292/submission_filter_template/filter?category={category}&has_photo={has_photo}", "isHrefTemplate"=>true, "title"=>"filter submissions by category", "description"=>"in addition to category, you can ensure the submission has a photo"}, "is:add"=>{"title"=>"add new submission", "encoding"=>"json", "href"=>"http://localhost:9292/submission_add_template/submit", "method"=>"POST", "template"=>{"title"=>"default title", "category"=>"cats", "photo_url"=>"http://cats.com"}}}, "submissions"=>[{"@controls"=>{"self"=>{"title"=>"submission 1", "href"=>"http://localhost:9292/view_submission/1"}}, "id"=>1, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg"}, {"@controls"=>{"self"=>{"title"=>"submission 2", "href"=>"http://localhost:9292/view_submission/2"}}, "id"=>2, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/icqDxNab3Do/maxresdefault.jpg"}], "category"=>"#{params[:category]}", "has_photo"=>"#{params[:has_photo]}"})
|
21
|
+
end
|
22
|
+
|
23
|
+
post "/submission_add_template/submit" do
|
24
|
+
json({"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}", :message=>0})
|
25
|
+
end
|
26
|
+
|
27
|
+
get "/view_submission/newest" do
|
28
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "submissions"=>[{"@controls"=>{"self"=>{"title"=>"submission 1", "href"=>"http://localhost:9292/view_submission/1"}}, "id"=>1, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg"}, {"@controls"=>{"self"=>{"title"=>"submission 2", "href"=>"http://localhost:9292/view_submission/2"}}, "id"=>2, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/icqDxNab3Do/maxresdefault.jpg"}], "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"})
|
29
|
+
end
|
30
|
+
|
31
|
+
delete "/submission_delete_template/newest" do
|
32
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"href"=>"http://localhost:9292/welcome/newest"}, "is:filter"=>{"href"=>"http://localhost:9292/submission_filter_template/filter?category={category}&has_photo={has_photo}", "isHrefTemplate"=>true, "title"=>"filter submissions by category", "description"=>"in addition to category, you can ensure the submission has a photo"}, "is:add"=>{"title"=>"add new submission", "encoding"=>"json", "href"=>"http://localhost:9292/submission_add_template/submit", "method"=>"POST", "template"=>{"title"=>"default title", "category"=>"cats", "photo_url"=>"http://cats.com"}}}, "submissions"=>[{"@controls"=>{"self"=>{"title"=>"submission 1", "href"=>"http://localhost:9292/view_submission/1"}}, "id"=>1, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg"}, {"@controls"=>{"self"=>{"title"=>"submission 2", "href"=>"http://localhost:9292/view_submission/2"}}, "id"=>2, "category"=>"cats", "photo"=>"https://i.ytimg.com/vi/icqDxNab3Do/maxresdefault.jpg"}], :message=>0})
|
33
|
+
end
|
34
|
+
|
35
|
+
patch "/submission_edit_template/self" do
|
36
|
+
json({"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}", :message=>0})
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
get "/view_submission/:item_id" do
|
41
|
+
item_id = params[:item_id]
|
42
|
+
item = ViewSubmission.find(item_id)
|
43
|
+
json({"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"})
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/json'
|
3
|
+
require 'require_all'
|
4
|
+
|
5
|
+
require_all("./lib/picatrix/generated/*.rb")
|
6
|
+
|
7
|
+
class App < Sinatra::Base
|
8
|
+
set :public_folder => "public", :static => true
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
status, headers, body = call env.merge("PATH_INFO" => "/welcome/newest")
|
12
|
+
[status, headers, body]
|
13
|
+
end
|
14
|
+
|
15
|
+
get "/welcome/newest" do
|
16
|
+
items = ViewSubmission.all
|
17
|
+
hashed_items = items.collect do |item|
|
18
|
+
item_id = item.id
|
19
|
+
category = item.category
|
20
|
+
photo = item.photo
|
21
|
+
{"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}
|
22
|
+
end
|
23
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"href"=>"http://localhost:9292/welcome/newest"}, "is:filter"=>{"href"=>"http://localhost:9292/submission_filter_template/filter?category={category}&has_photo={has_photo}", "isHrefTemplate"=>true, "title"=>"filter submissions by category", "description"=>"in addition to category, you can ensure the submission has a photo"}, "is:add"=>{"title"=>"add new submission", "encoding"=>"json", "href"=>"http://localhost:9292/submission_add_template/submit", "method"=>"POST", "template"=>{"title"=>"default title", "category"=>"cats", "photo_url"=>"http://cats.com"}}}}.merge({"view_submissions" => hashed_items}))
|
24
|
+
end
|
25
|
+
|
26
|
+
get "/submission_filter_template/filter" do
|
27
|
+
items = ViewSubmission.all
|
28
|
+
hashed_items = items.collect do |item|
|
29
|
+
item_id = item.id
|
30
|
+
category = item.category
|
31
|
+
photo = item.photo
|
32
|
+
{"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}
|
33
|
+
end
|
34
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"href"=>"http://localhost:9292/welcome/newest"}, "is:filter"=>{"href"=>"http://localhost:9292/submission_filter_template/filter?category={category}&has_photo={has_photo}", "isHrefTemplate"=>true, "title"=>"filter submissions by category", "description"=>"in addition to category, you can ensure the submission has a photo"}, "is:add"=>{"title"=>"add new submission", "encoding"=>"json", "href"=>"http://localhost:9292/submission_add_template/submit", "method"=>"POST", "template"=>{"title"=>"default title", "category"=>"cats", "photo_url"=>"http://cats.com"}}}, "category"=>"#{params[:category]}", "has_photo"=>"#{params[:has_photo]}"}.merge({"view_submissions" => hashed_items}))
|
35
|
+
end
|
36
|
+
|
37
|
+
post "/submission_add_template/submit" do
|
38
|
+
items = ViewSubmission.all
|
39
|
+
hashed_items = items.collect do |item|
|
40
|
+
item_id = item.id
|
41
|
+
category = item.category
|
42
|
+
photo = item.photo
|
43
|
+
{"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}
|
44
|
+
end
|
45
|
+
json({"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}", :message=>0}.merge({"view_submissions" => hashed_items}))
|
46
|
+
end
|
47
|
+
|
48
|
+
get "/view_submission/newest" do
|
49
|
+
items = ViewSubmission.all
|
50
|
+
hashed_items = items.collect do |item|
|
51
|
+
item_id = item.id
|
52
|
+
category = item.category
|
53
|
+
photo = item.photo
|
54
|
+
{"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}
|
55
|
+
end
|
56
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}.merge({"view_submissions" => hashed_items}))
|
57
|
+
end
|
58
|
+
|
59
|
+
delete "/submission_delete_template/newest" do
|
60
|
+
items = ViewSubmission.all
|
61
|
+
hashed_items = items.collect do |item|
|
62
|
+
item_id = item.id
|
63
|
+
category = item.category
|
64
|
+
photo = item.photo
|
65
|
+
{"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}
|
66
|
+
end
|
67
|
+
json({"title"=>"View submissions", "description"=>"idk yet", "@meta"=>{"@title"=>"Submissions", "@description"=>"This resource represents submissions."}, "@controls"=>{"self"=>{"href"=>"http://localhost:9292/welcome/newest"}, "is:filter"=>{"href"=>"http://localhost:9292/submission_filter_template/filter?category={category}&has_photo={has_photo}", "isHrefTemplate"=>true, "title"=>"filter submissions by category", "description"=>"in addition to category, you can ensure the submission has a photo"}, "is:add"=>{"title"=>"add new submission", "encoding"=>"json", "href"=>"http://localhost:9292/submission_add_template/submit", "method"=>"POST", "template"=>{"title"=>"default title", "category"=>"cats", "photo_url"=>"http://cats.com"}}}, :message=>0}.merge({"view_submissions" => hashed_items}))
|
68
|
+
end
|
69
|
+
|
70
|
+
patch "/submission_edit_template/self" do
|
71
|
+
items = ViewSubmission.all
|
72
|
+
hashed_items = items.collect do |item|
|
73
|
+
item_id = item.id
|
74
|
+
category = item.category
|
75
|
+
photo = item.photo
|
76
|
+
{"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"}
|
77
|
+
end
|
78
|
+
json({"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}", :message=>0}.merge({"view_submissions" => hashed_items}))
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
get "/view_submission/:item_id" do
|
83
|
+
item_id = params[:item_id]
|
84
|
+
item = ViewSubmission.find(item_id)
|
85
|
+
json({"@controls"=>{"self"=>{"title"=>"submission #{item_id}", "href"=>"http://localhost:9292/view_submission/#{item_id}"}, "up"=>{"title"=>"View submissions", "href"=>"http://localhost:9292/welcome/newest"}, "is:edit"=>{"title"=>"update category or photo url", "encoding"=>"json", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"PATCH", "template"=>{"photo"=>"{new_url}", "category"=>"{new_category}"}}, "is:remove"=>{"title"=>"remove submission", "href"=>"http://localhost:9292/view_submission/#{item_id}", "method"=>"DELETE"}}, "id"=>"#{item.id}", "category"=>"#{item.category}", "photo"=>"#{item.photo}"})
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
class ViewSubmission
|
3
|
+
def self.find(item_id)
|
4
|
+
OpenStruct.new(
|
5
|
+
category: "cats",
|
6
|
+
photo: "http://imgur.com/r/cats/myEqIZx",
|
7
|
+
id: item_id
|
8
|
+
)
|
9
|
+
end
|
10
|
+
def self.all
|
11
|
+
[
|
12
|
+
OpenStruct.new(
|
13
|
+
category: "cats",
|
14
|
+
photo: "http://imgur.com/r/cats/myEqIZx",
|
15
|
+
id: 1
|
16
|
+
),
|
17
|
+
OpenStruct.new(
|
18
|
+
category: "cats",
|
19
|
+
photo: "http://imgur.com/r/cats/myEqIZx",
|
20
|
+
id: 2
|
21
|
+
)
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'require_all'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Picatrix
|
5
|
+
class Jenny
|
6
|
+
include Thor::Base
|
7
|
+
include Thor::Actions
|
8
|
+
attr_accessor :edges, :nodes, :app_name, :routes, :root,
|
9
|
+
:destination_stack, :options, :root_node_name,
|
10
|
+
:default_response, :assets, :addressable_items,
|
11
|
+
:generated
|
12
|
+
|
13
|
+
argument :name
|
14
|
+
source_root File.dirname(__FILE__)
|
15
|
+
|
16
|
+
def initialize(array = [], options = {}, app_name = "app")
|
17
|
+
@app_name = app_name
|
18
|
+
@options = options
|
19
|
+
@destination_stack = [self.class.source_root]
|
20
|
+
@default_response = { message: 0 }
|
21
|
+
|
22
|
+
hash = array.group_by {|e| e.keys.first}
|
23
|
+
@nodes = hash[:node].flat_map {|e| e[:node]}.reduce({}, :merge)
|
24
|
+
@edges = hash[:edge].flat_map {|e| e[:edge]}
|
25
|
+
# TODO need to adjust parser down below so i dont need to traverse this nonsense
|
26
|
+
@root_node_name = hash[:root].first.values.flatten.first.split("[").first.delete(" ")
|
27
|
+
|
28
|
+
@generated = []
|
29
|
+
# TODO for performance combine loops
|
30
|
+
@assets = assets
|
31
|
+
@addressable_items = addressable_items
|
32
|
+
@routes = routes
|
33
|
+
end
|
34
|
+
|
35
|
+
def just_do_it
|
36
|
+
@generated.each do |node_name|
|
37
|
+
require "./lib/picatrix/generated/#{node_name}.rb"
|
38
|
+
end
|
39
|
+
generate_app_file
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def generate_app_file
|
44
|
+
template(
|
45
|
+
'templates/app.rb',
|
46
|
+
File.join("generated/#{app_name}.rb")
|
47
|
+
)
|
48
|
+
end
|
49
|
+
def assets
|
50
|
+
@edges.collect do | edge|
|
51
|
+
source = edge.keys.first
|
52
|
+
properties = edge[source]
|
53
|
+
# if you dont have an inline asset, ignore
|
54
|
+
next unless properties[:inline]
|
55
|
+
|
56
|
+
# TODO ?
|
57
|
+
#link_relation = properties[:link_relation]
|
58
|
+
#path = "#{source}/#{link_relation.delete('"')}"
|
59
|
+
|
60
|
+
mason_path = "lib/picatrix/templates/mason/#{properties[:target]}.json"
|
61
|
+
|
62
|
+
if File.exist?(mason_path)
|
63
|
+
body = JSON.parse(
|
64
|
+
File.read(
|
65
|
+
mason_path
|
66
|
+
)
|
67
|
+
)
|
68
|
+
else
|
69
|
+
body = default_response
|
70
|
+
end
|
71
|
+
{
|
72
|
+
"#{properties[:target]}" => body
|
73
|
+
}
|
74
|
+
end.compact.reduce({}, :merge)
|
75
|
+
end
|
76
|
+
def routes
|
77
|
+
@edges.collect do |edge|
|
78
|
+
source = edge.keys.first
|
79
|
+
properties = edge[source]
|
80
|
+
# we dont need a route if it is inline represented
|
81
|
+
next if properties[:inline]
|
82
|
+
|
83
|
+
link_relation = properties[:link_relation]
|
84
|
+
path = "#{source}/#{link_relation.delete('"')}"
|
85
|
+
|
86
|
+
mason_path = "lib/picatrix/templates/mason/#{edge[source][:target]}.json"
|
87
|
+
|
88
|
+
if File.exist?(mason_path)
|
89
|
+
body = JSON.parse(
|
90
|
+
File.read(
|
91
|
+
mason_path
|
92
|
+
)
|
93
|
+
)
|
94
|
+
else
|
95
|
+
body = default_response
|
96
|
+
end
|
97
|
+
|
98
|
+
if source == root_node_name
|
99
|
+
@root = path
|
100
|
+
end
|
101
|
+
|
102
|
+
if (asset = assets[source]) && body.is_a?(Hash)
|
103
|
+
body.merge!(asset)
|
104
|
+
end
|
105
|
+
|
106
|
+
collections = @addressable_items.inject({}) do |memo, item|
|
107
|
+
memo["#{path}"] = {
|
108
|
+
name: "#{item[:type].pluralize}",
|
109
|
+
resource_name: "#{item[:type].camelcase}",
|
110
|
+
template: JSON.parse(
|
111
|
+
File.read("lib/picatrix/templates/mason/#{item[:type]}_min.json")
|
112
|
+
)
|
113
|
+
}
|
114
|
+
memo
|
115
|
+
end
|
116
|
+
|
117
|
+
{
|
118
|
+
path: path,
|
119
|
+
method: properties[:method],
|
120
|
+
# danger danger danger will robinson we are unescaping here!
|
121
|
+
body: body.to_s.delete("\\"),
|
122
|
+
collection: collections["#{path}"]
|
123
|
+
}
|
124
|
+
end.compact!
|
125
|
+
end
|
126
|
+
def addressable_items
|
127
|
+
@nodes.collect do |node|
|
128
|
+
node_name = node.first
|
129
|
+
node_properties = node.last
|
130
|
+
|
131
|
+
if node_properties[:type] == "item"
|
132
|
+
item_path = "#{node_name}/:item_id"
|
133
|
+
mason_path = "lib/picatrix/templates/mason/#{node_name}.json"
|
134
|
+
schema_path = "lib/picatrix/schemas/#{node_name}_item.json"
|
135
|
+
|
136
|
+
if File.exist?(mason_path)
|
137
|
+
body = JSON.parse(
|
138
|
+
File.read(
|
139
|
+
mason_path
|
140
|
+
)
|
141
|
+
)
|
142
|
+
else
|
143
|
+
body = default_response
|
144
|
+
end
|
145
|
+
|
146
|
+
if File.exist?(schema_path)
|
147
|
+
schema = JSON.parse(
|
148
|
+
File.read(
|
149
|
+
schema_path
|
150
|
+
)
|
151
|
+
)
|
152
|
+
|
153
|
+
# thor doesnt take locals in
|
154
|
+
@node_name = node_name
|
155
|
+
template(
|
156
|
+
'templates/type.rb',
|
157
|
+
File.join("generated/#{node_name}.rb")
|
158
|
+
)
|
159
|
+
@generated = generated << @node_name
|
160
|
+
else
|
161
|
+
schema = {}
|
162
|
+
end
|
163
|
+
|
164
|
+
{
|
165
|
+
path: item_path,
|
166
|
+
type: node_name,
|
167
|
+
schema: schema,
|
168
|
+
# danger danger danger will robinson we are unescaping here!
|
169
|
+
body: body.to_s.delete("\\")
|
170
|
+
}
|
171
|
+
end
|
172
|
+
end.compact!
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Picatrix
|
2
|
+
# eats dots :)
|
3
|
+
class Pacman
|
4
|
+
attr_accessor :graph, :hash
|
5
|
+
|
6
|
+
def initialize(file_name)
|
7
|
+
@graph = GraphViz.parse(file_name, :path => "/usr/local/bin")
|
8
|
+
@hash = TransformToHash.new.apply(
|
9
|
+
DigraphParser.new.parse(
|
10
|
+
File.read(file_name)
|
11
|
+
)
|
12
|
+
).flat_map(&:entries).
|
13
|
+
group_by(&:first).
|
14
|
+
map {|k,v| Hash[k, v.map(&:last)]}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/json'
|
3
|
+
require 'require_all'
|
4
|
+
|
5
|
+
require_all("./lib/picatrix/generated/*.rb")
|
6
|
+
|
7
|
+
class <%= @app_name.camelize %> < Sinatra::Base
|
8
|
+
set :public_folder => "public", :static => true
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
status, headers, body = call env.merge("PATH_INFO" => "/<%= @root %>")
|
12
|
+
[status, headers, body]
|
13
|
+
end
|
14
|
+
<% @routes.each do |route| %>
|
15
|
+
<%= route[:method] %> "/<%= route[:path] %>" do
|
16
|
+
items = <%= route[:collection][:resource_name].constantize %>.all
|
17
|
+
hashed_items = items.collect do |item|
|
18
|
+
item_id = item.id
|
19
|
+
category = item.category
|
20
|
+
photo = item.photo
|
21
|
+
<%= route[:collection][:template].to_s.delete("\\") %>
|
22
|
+
end
|
23
|
+
json(<%= route[:body] %>.merge({"<%= route[:collection][:name] %>" => hashed_items}))
|
24
|
+
end
|
25
|
+
<% end %>
|
26
|
+
<% @addressable_items.each do |item| %>
|
27
|
+
get "/<%= item[:path] %>" do
|
28
|
+
item_id = params[:item_id]
|
29
|
+
item = <%= item[:type].camelcase.constantize %>.find(item_id)
|
30
|
+
json(<%= item[:body] %>)
|
31
|
+
end
|
32
|
+
<% end %>
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"@controls": {
|
3
|
+
"self": {
|
4
|
+
"title": "submission #{item_id}",
|
5
|
+
"href": "http://localhost:9292/view_submission/#{item_id}"
|
6
|
+
},
|
7
|
+
"up": {
|
8
|
+
"title": "View submissions",
|
9
|
+
"href": "http://localhost:9292/welcome/newest"
|
10
|
+
},
|
11
|
+
"is:edit": {
|
12
|
+
"title": "update category or photo url",
|
13
|
+
"encoding": "json",
|
14
|
+
"href": "http://localhost:9292/view_submission/#{item_id}",
|
15
|
+
"method": "PATCH",
|
16
|
+
"template": {
|
17
|
+
"photo": "{new_url}",
|
18
|
+
"category": "{new_category}"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"is:remove": {
|
22
|
+
"title": "remove submission",
|
23
|
+
"href": "http://localhost:9292/view_submission/#{item_id}",
|
24
|
+
"method": "DELETE"
|
25
|
+
}
|
26
|
+
},
|
27
|
+
"id": "#{item.id}",
|
28
|
+
"category": "#{item.category}",
|
29
|
+
"photo": "#{item.photo}"
|
30
|
+
}
|