pie 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pie.rb +1 -1
- data/lib/pie.rb~ +171 -0
- metadata +3 -2
data/lib/pie.rb
CHANGED
@@ -15,6 +15,7 @@ class Pie
|
|
15
15
|
@default_template = :image_page
|
16
16
|
@places = Places.new
|
17
17
|
@map = Map.new(@places)
|
18
|
+
@images = {}
|
18
19
|
end
|
19
20
|
|
20
21
|
class WebApp < Sinatra::Base
|
@@ -122,7 +123,6 @@ class Pie
|
|
122
123
|
end
|
123
124
|
|
124
125
|
def image(image_hash)
|
125
|
-
@images ||= {}
|
126
126
|
puts "--- set image"
|
127
127
|
puts image_hash.inspect
|
128
128
|
@images.merge!(image_hash)
|
data/lib/pie.rb~
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'player'
|
3
|
+
|
4
|
+
#puts "----------------- Ruby version = #{RUBY_VERSION}"
|
5
|
+
#raise ScriptError, "Pie requires Ruby 1.9 or higher" if RUBY_VERSION < "1.9.0"
|
6
|
+
NO_WAY_BACK = ""
|
7
|
+
class Pie
|
8
|
+
|
9
|
+
|
10
|
+
attr_accessor :places
|
11
|
+
attr_accessor :images
|
12
|
+
attr_accessor :default_template
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@default_template = :image_page
|
16
|
+
@places = Places.new
|
17
|
+
@map = Map.new(@places)
|
18
|
+
end
|
19
|
+
|
20
|
+
class WebApp < Sinatra::Base
|
21
|
+
set :root, File.join(File.expand_path(File.dirname(__FILE__)), "..")
|
22
|
+
|
23
|
+
get '/' do
|
24
|
+
"hello"
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/:place_name' do
|
28
|
+
name = params[:place_name].to_sym
|
29
|
+
$current = name unless name.nil?
|
30
|
+
puts "current place name is #{$current}"
|
31
|
+
puts "current place is #{$pie.places[$current]}"
|
32
|
+
puts "--- skip out"; return if $pie.places[$current].nil?
|
33
|
+
puts "current links are #{$pie.places[$current].links.inspect}"
|
34
|
+
puts "displaying template: #{$pie.default_template.inspect}"
|
35
|
+
erb $pie.default_template
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
at_exit { WebApp.run! if !$0.include?("spec")}
|
40
|
+
|
41
|
+
class Map
|
42
|
+
|
43
|
+
def initialize places
|
44
|
+
@places = places
|
45
|
+
end
|
46
|
+
|
47
|
+
def path endpoints
|
48
|
+
puts "---> path #{endpoints.inspect}"
|
49
|
+
puts @places.inspect
|
50
|
+
#if h.size != 2
|
51
|
+
# return puts "path must have two and only two endpoints."
|
52
|
+
#end
|
53
|
+
start_place_key, end_place_key = endpoints.keys
|
54
|
+
label_for_end, label_for_start = endpoints.values
|
55
|
+
|
56
|
+
start_place = @places[start_place_key]
|
57
|
+
end_place = @places[end_place_key]
|
58
|
+
raise ArgumentError, "there is no place named '#{start_place_key}'" if start_place.nil?
|
59
|
+
raise ArgumentError, "there is no place named '#{end_place_key}'" if end_place.nil?
|
60
|
+
|
61
|
+
start_place[:links][end_place_key] = label_for_end unless label_for_end.empty?
|
62
|
+
end_place[:links][start_place_key] = label_for_start unless label_for_start.empty?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Place < Hash
|
67
|
+
def initialize
|
68
|
+
self[:links] = {}
|
69
|
+
end
|
70
|
+
def links
|
71
|
+
result = self[:links]
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class Places < Hash
|
77
|
+
def method_missing name, options = {}
|
78
|
+
unless options.is_a? Hash
|
79
|
+
puts "options for creating a place must have key and value"
|
80
|
+
return
|
81
|
+
end
|
82
|
+
puts "making a #{name} with #{options.inspect}"
|
83
|
+
place = Place.new
|
84
|
+
place.merge! options
|
85
|
+
self[name.to_sym] = place
|
86
|
+
end
|
87
|
+
|
88
|
+
def [] string_or_symbol
|
89
|
+
super string_or_symbol.to_sym
|
90
|
+
end
|
91
|
+
|
92
|
+
def after(place_name)
|
93
|
+
index = keys.index(place_name.to_sym)
|
94
|
+
next_place_name = keys[index + 1]
|
95
|
+
self[next_place_name] unless next_place_name.nil?
|
96
|
+
end
|
97
|
+
|
98
|
+
def before(place_name)
|
99
|
+
index = keys.index(place_name.to_sym)
|
100
|
+
index = index - 1
|
101
|
+
if index < 0
|
102
|
+
nil
|
103
|
+
else
|
104
|
+
prev_place_name = keys[index]
|
105
|
+
self[prev_place_name]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def template(template_name)
|
111
|
+
puts "--> set default template #{template_name.to_sym}"
|
112
|
+
@default_template = template_name.to_sym
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_places(&block)
|
116
|
+
@places.instance_eval(&block)
|
117
|
+
end
|
118
|
+
|
119
|
+
def map(&block)
|
120
|
+
puts "-------- creating map --------"
|
121
|
+
@map.instance_eval(&block)
|
122
|
+
end
|
123
|
+
|
124
|
+
def image(image_hash)
|
125
|
+
@images ||= {}
|
126
|
+
puts "--- set image"
|
127
|
+
puts image_hash.inspect
|
128
|
+
@images.merge!(image_hash)
|
129
|
+
end
|
130
|
+
|
131
|
+
def current
|
132
|
+
@current ||= @places.keys.first
|
133
|
+
end
|
134
|
+
|
135
|
+
def move_to(new_place_key)
|
136
|
+
@current = new_place_key
|
137
|
+
end
|
138
|
+
|
139
|
+
def current_image
|
140
|
+
puts "------- current_image"
|
141
|
+
puts $current.inspect
|
142
|
+
puts @images.inspect
|
143
|
+
@images[$current.to_sym]
|
144
|
+
end
|
145
|
+
|
146
|
+
def current_description
|
147
|
+
puts "------- current_description"
|
148
|
+
puts $current.inspect
|
149
|
+
place = @places[$current.to_sym]
|
150
|
+
puts @place.inspect
|
151
|
+
place[:description] unless place.nil?
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def make_pie(&block)
|
156
|
+
foo = 1
|
157
|
+
puts "-------------------------- making pie ---------------------------- "
|
158
|
+
$pie = Pie.new
|
159
|
+
$pie.instance_eval(&block)
|
160
|
+
puts "-------------------------- pie complete ---------------------------- "
|
161
|
+
end
|
162
|
+
|
163
|
+
def more_pie(&block)
|
164
|
+
puts "-------------------------- more pie ---------------------------- "
|
165
|
+
if $pie.nil?
|
166
|
+
puts "How can you make more pie when you haven't made any pie yet?"
|
167
|
+
return
|
168
|
+
end
|
169
|
+
$pie.instance_eval(&block)
|
170
|
+
puts "-------------------------- pie complete ---------------------------- "
|
171
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sarah Allen, Sarah Mei
|
@@ -28,6 +28,7 @@ extra_rdoc_files: []
|
|
28
28
|
|
29
29
|
files:
|
30
30
|
- lib/pie.rb
|
31
|
+
- lib/pie.rb~
|
31
32
|
- lib/player.rb
|
32
33
|
- views/full_screen.erb
|
33
34
|
- views/game_screen.erb
|