dedalus 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.gitignore +7 -0
  4. data/.rspec +1 -0
  5. data/.yardopts +1 -0
  6. data/ChangeLog.md +4 -0
  7. data/Gemfile +11 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +135 -0
  10. data/Rakefile +42 -0
  11. data/bin/dedalus +20 -0
  12. data/dedalus.gemspec +60 -0
  13. data/features/.gitkeep +0 -0
  14. data/features/dedalus.feature +1 -0
  15. data/features/step_definitions/.gitkeep +0 -0
  16. data/features/step_definitions/dedalus_steps.rb +1 -0
  17. data/gemspec.yml +20 -0
  18. data/lib/dedalus/app_view_composer.rb +60 -0
  19. data/lib/dedalus/application_view.rb +48 -0
  20. data/lib/dedalus/elements/heading.rb +13 -0
  21. data/lib/dedalus/elements/icon.rb +21 -0
  22. data/lib/dedalus/elements/image.rb +53 -0
  23. data/lib/dedalus/elements/paragraph.rb +13 -0
  24. data/lib/dedalus/elements/text.rb +44 -0
  25. data/lib/dedalus/elements.rb +78 -0
  26. data/lib/dedalus/palette.rb +89 -0
  27. data/lib/dedalus/pattern_library/application.rb +140 -0
  28. data/lib/dedalus/pattern_library/application_view.rb +28 -0
  29. data/lib/dedalus/pattern_library/library_view.rb +7 -0
  30. data/lib/dedalus/pattern_library/models/library.rb +10 -0
  31. data/lib/dedalus/pattern_library/models/library_item.rb +11 -0
  32. data/lib/dedalus/pattern_library/models/library_section.rb +26 -0
  33. data/lib/dedalus/pattern_library/molecules/library_item_example.rb +50 -0
  34. data/lib/dedalus/pattern_library/molecules/library_section_tab.rb +62 -0
  35. data/lib/dedalus/pattern_library/molecules/periodic_table.rb +32 -0
  36. data/lib/dedalus/pattern_library/molecules/periodic_table_entry.rb +70 -0
  37. data/lib/dedalus/pattern_library/organisms/app_footer.rb +37 -0
  38. data/lib/dedalus/pattern_library/organisms/app_header.rb +36 -0
  39. data/lib/dedalus/pattern_library/organisms/app_sidebar.rb +29 -0
  40. data/lib/dedalus/pattern_library/organisms/library_entry.rb +64 -0
  41. data/lib/dedalus/pattern_library/screens/app_screen.rb +22 -0
  42. data/lib/dedalus/pattern_library/templates/app_template.rb +94 -0
  43. data/lib/dedalus/pattern_library.rb +1 -0
  44. data/lib/dedalus/version.rb +4 -0
  45. data/lib/dedalus/view_traversal.rb +129 -0
  46. data/lib/dedalus.rb +40 -0
  47. data/media/icons/arrow_cursor.png +0 -0
  48. data/media/icons/atom.png +0 -0
  49. data/media/icons/hive.png +0 -0
  50. data/media/icons/house.png +0 -0
  51. data/media/icons/molecule.png +0 -0
  52. data/media/icons/paramecium.png +0 -0
  53. data/spec/dedalus_spec.rb +28 -0
  54. data/spec/spec_helper.rb +4 -0
  55. metadata +226 -0
@@ -0,0 +1,22 @@
1
+ module Dedalus
2
+ module PatternLibrary
3
+ class ApplicationScreen < Dedalus::Screen
4
+ def initialize(template)
5
+ @template = template
6
+ end
7
+
8
+ def show
9
+ @template.show
10
+ end
11
+
12
+ def hydrate(library_section_tabs:, current_entry_name:, library_sections:, library_items:)
13
+ @template.library_name = "Dedalus Pattern Library"
14
+ @template.library_section_tabs = library_section_tabs
15
+ @template.library_sections = library_sections
16
+ @template.library_items = library_items
17
+ @template.current_entry_name = current_entry_name
18
+ self
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,94 @@
1
+ module Dedalus
2
+ module PatternLibrary
3
+ class ApplicationTemplate < Dedalus::Template
4
+ attr_accessor :library_name, :library_section_tabs, :current_entry_name
5
+ attr_accessor :library_sections, :library_items
6
+
7
+ def show
8
+ layout do
9
+ library_page
10
+ end
11
+ end
12
+
13
+ def layout
14
+ [
15
+ app_header,
16
+ [ sidebar, yield ]
17
+ # app_footer
18
+ ]
19
+ end
20
+
21
+ def self.example_data
22
+ {
23
+ library_name: "Ipsum Librarum",
24
+ library_sections: [ {
25
+ title: "Welcome",
26
+ subtitle: "Fake section",
27
+ color: 'blue',
28
+ show_table: false,
29
+ items: []
30
+ } ], #, LibraryEntry.example_data ],
31
+ library_section_tabs: [ LibrarySectionTab.example_data ],
32
+ library_items: [], # LibraryItemExample.example_data ],
33
+ current_entry_name: 'Welcome'
34
+ }
35
+ end
36
+
37
+ private
38
+ def library_page
39
+ if current_section
40
+ LibraryEntry.new(current_section)
41
+ elsif current_item
42
+ LibraryEntry.from_item(current_item)
43
+ else
44
+ Elements::Paragraph.new(text: "no page selected")
45
+ end
46
+ end
47
+
48
+ def current_section
49
+ library_sections.detect { |section| section[:title] == current_entry_name }
50
+ end
51
+
52
+ def current_item
53
+ library_items.detect { |item| item[:name] == current_entry_name }
54
+ end
55
+
56
+ def app_header
57
+ ApplicationHeader.new(
58
+ title: library_name,
59
+ subtitle: 'A Visual Pattern Library for Joyce',
60
+ height_percent: 0.15,
61
+ background_color: Palette.blue
62
+ )
63
+ end
64
+
65
+ def app_footer
66
+ ApplicationFooter.new(
67
+ joyce_version: Joyce::VERSION,
68
+ dedalus_version: Dedalus::VERSION,
69
+ company: "Deep Cerulean Simulations and Games",
70
+ copyright: "2015-#{Time.now.year}",
71
+ height_percent: 0.10,
72
+ background_color: Palette.decode_color('darkgreen')
73
+ )
74
+ end
75
+
76
+ def sidebar
77
+ ApplicationSidebar.new(
78
+ library_section_tab_molecules: section_tabs,
79
+ width_percent: 0.2,
80
+ background_color: Palette.decode_color('darkgray')
81
+ )
82
+ end
83
+
84
+ def section_tabs
85
+ tab_list = library_section_tabs.map do |attrs|
86
+ highlight = attrs[:name] == current_entry_name
87
+ LibrarySectionTab.new(attrs.merge(highlight: highlight))
88
+ end
89
+ # p [ tab_list: tab_list ]
90
+ tab_list
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ module Dedalus
2
+ # dedalus version
3
+ VERSION = "0.1.2"
4
+ end
@@ -0,0 +1,129 @@
1
+ module Dedalus
2
+ class ViewTraversal
3
+ include Geometer::PointHelpers
4
+ include Geometer::DimensionHelpers
5
+
6
+ def initialize(&blk)
7
+ instance_eval(&blk)
8
+ end
9
+
10
+ def on_atom(&blk)
11
+ @atom_callback = blk
12
+ end
13
+
14
+ def on_molecule(&blk)
15
+ @molecule_callback = blk
16
+ end
17
+
18
+ def on_element(&blk)
19
+ @element_callback = blk
20
+ end
21
+
22
+ def walk!(structure, origin:, dimensions:)
23
+ width, height = *dimensions
24
+ height = structure.height if !structure.is_a?(Array) && structure.height
25
+ width = structure.width if !structure.is_a?(Array) && structure.width
26
+ x0, y0 = *origin
27
+
28
+ if structure.is_a?(Dedalus::Atom)
29
+ @atom_callback.call(structure, origin: origin, dimensions: dimensions) if @atom_callback
30
+ elsif structure.is_a?(Dedalus::Element)
31
+ # an element *other than* an atom, we need to call #show on it
32
+ margin = structure.margin || 0.0
33
+ x,y = x0 + margin, y0 + margin
34
+ margin_origin = [ x, y ]
35
+ margin_dims = [ width - margin*2, height - margin*2 ]
36
+
37
+ if structure.is_a?(Dedalus::Molecule) && @molecule_callback
38
+ @molecule_callback.call(structure, origin: margin_origin, dimensions: margin_dims)
39
+ end
40
+
41
+ if @element_callback
42
+ @element_callback.call(structure, origin: margin_origin, dimensions: margin_dims)
43
+ end
44
+
45
+ pad = structure.padding || 10.0
46
+ # x,y = x0+pad, y0+pad
47
+ pad_origin = [x+pad,y+pad]
48
+ pad_dims = [width - pad*2 - margin*2, height - pad*2 - margin*2 ]
49
+
50
+
51
+ walk!(structure.show, origin: pad_origin, dimensions: pad_dims)
52
+ elsif structure.is_a?(Array) # we have a set of rows
53
+ walk_rows!(structure, origin: origin, dimensions: dimensions)
54
+ end
55
+ end
56
+
57
+ private
58
+ def walk_rows!(rows, origin:, dimensions:)
59
+ width, height = *dimensions
60
+ x0, y0 = *origin
61
+
62
+ subdivide_line(rows, distance: height, attr: :height) do |row, current_row_height, height_cursor|
63
+ y = y0 + height_cursor
64
+ dims = [width, current_row_height]
65
+ if row.is_a?(Array)
66
+ walk_columns!(row, origin: [x0, y], dimensions: dims)
67
+ else
68
+ walk!(row, origin: [x0,y], dimensions: dims)
69
+ end
70
+ end
71
+ end
72
+
73
+ def walk_columns!(columns, origin:, dimensions:)
74
+ width, height = *dimensions
75
+ x0, y0 = *origin
76
+ subdivide_line(columns, distance: width, attr: :width) do |column, current_column_width, width_cursor|
77
+ x = x0 + width_cursor
78
+ dims = [ current_column_width, height ]
79
+ walk!(column, origin: [x,y0], dimensions: dims)
80
+ end
81
+ end
82
+
83
+ def subdivide_line(elements, distance:, attr:)
84
+ percent_attr = :"#{attr}_percent"
85
+ elements_with_relative_hints = elements.select do |element|
86
+ if element.is_a?(Array)
87
+ false
88
+ else
89
+ !element.send(percent_attr).nil?
90
+ end
91
+ end
92
+
93
+ elements_with_absolute_hints = elements.select do |element|
94
+ if element.is_a?(Array)
95
+ false
96
+ else
97
+ !element.send(attr).nil?
98
+ end
99
+ end
100
+
101
+ elements_with_hints = (elements_with_relative_hints + elements_with_absolute_hints).uniq
102
+ distance_specified_by_hints =
103
+ (elements_with_relative_hints.sum(&percent_attr) * distance) +
104
+ (elements_with_absolute_hints.sum(&attr))
105
+
106
+ if elements_with_hints.length < elements.length
107
+ default_element_section_distance = (distance - distance_specified_by_hints) / (elements.length - elements_with_hints.length)
108
+ end
109
+
110
+ distance_cursor = 0
111
+ elements.each_with_index do |element, index|
112
+ current_element_distance = if element.is_a?(Array)
113
+ default_element_section_distance
114
+ else
115
+ if !element.send(attr).nil?
116
+ element.send(attr)
117
+ elsif !element.send(percent_attr).nil?
118
+ element.send(percent_attr) * distance
119
+ else
120
+ default_element_section_distance
121
+ end
122
+ end
123
+
124
+ yield(element, current_element_distance, distance_cursor)
125
+ distance_cursor += current_element_distance
126
+ end
127
+ end
128
+ end
129
+ end
data/lib/dedalus.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'joyce'
2
+ require 'geometer'
3
+
4
+ require 'dedalus/version'
5
+ require 'dedalus/view_traversal'
6
+ require 'dedalus/app_view_composer'
7
+ require 'dedalus/application_view'
8
+
9
+ require 'dedalus/palette'
10
+
11
+ require 'dedalus/elements'
12
+ require 'dedalus/elements/text'
13
+ require 'dedalus/elements/heading'
14
+ require 'dedalus/elements/paragraph'
15
+ require 'dedalus/elements/image'
16
+ require 'dedalus/elements/icon'
17
+
18
+ require 'dedalus/pattern_library'
19
+ require 'dedalus/pattern_library/models/library'
20
+ require 'dedalus/pattern_library/models/library_section'
21
+ require 'dedalus/pattern_library/models/library_item'
22
+
23
+ require 'dedalus/pattern_library/molecules/library_section_tab'
24
+ # require 'dedalus/pattern_library/molecules/library_item_molecule'
25
+ require 'dedalus/pattern_library/molecules/library_item_example'
26
+ require 'dedalus/pattern_library/molecules/periodic_table_entry'
27
+ require 'dedalus/pattern_library/molecules/periodic_table'
28
+
29
+ require 'dedalus/pattern_library/organisms/app_header'
30
+ require 'dedalus/pattern_library/organisms/app_footer'
31
+ require 'dedalus/pattern_library/organisms/app_sidebar'
32
+ require 'dedalus/pattern_library/organisms/library_entry'
33
+
34
+ require 'dedalus/pattern_library/templates/app_template'
35
+
36
+ require 'dedalus/pattern_library/screens/app_screen'
37
+
38
+ require 'dedalus/pattern_library/library_view'
39
+ require 'dedalus/pattern_library/application_view'
40
+ require 'dedalus/pattern_library/application'
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'dedalus'
3
+
4
+ describe Dedalus do
5
+ it "should have a VERSION constant" do
6
+ expect(subject.const_get('VERSION')).to_not be_empty
7
+ end
8
+ end
9
+
10
+ describe ApplicationViewComposer do
11
+ before { Dedalus.activate!(app_view) }
12
+ subject(:composer) { ApplicationViewComposer.new }
13
+ let(:app_view) { instance_double(Dedalus::ApplicationView, font: font) }
14
+ let(:font) { instance_double(Gosu::Font, height: 10, text_width: 10) }
15
+ describe "#render" do
16
+ context "a single atom" do
17
+ let(:atom) { Dedalus::Elements::Paragraph.new }
18
+ let(:origin) { [0,0] }
19
+ let(:dimensions) { [1024,720] }
20
+
21
+ it 'should update position and render' do
22
+ expect(atom).to receive(:position=).with(origin)
23
+ expect(atom).to receive(:render)
24
+ composer.render!(atom, origin: origin, dimensions: dimensions,mouse_position: [0,0])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'dedalus/version'
3
+
4
+ include Dedalus
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dedalus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Weissman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: joyce
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: geometer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubygems-tasks
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.8'
139
+ description: atomic ui pattern library toolkit for joyce
140
+ email: jweissman1986@gmail.com
141
+ executables:
142
+ - dedalus
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - ChangeLog.md
146
+ - LICENSE.txt
147
+ - README.md
148
+ files:
149
+ - ".document"
150
+ - ".gitignore"
151
+ - ".rspec"
152
+ - ".yardopts"
153
+ - ChangeLog.md
154
+ - Gemfile
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - bin/dedalus
159
+ - dedalus.gemspec
160
+ - features/.gitkeep
161
+ - features/dedalus.feature
162
+ - features/step_definitions/.gitkeep
163
+ - features/step_definitions/dedalus_steps.rb
164
+ - gemspec.yml
165
+ - lib/dedalus.rb
166
+ - lib/dedalus/app_view_composer.rb
167
+ - lib/dedalus/application_view.rb
168
+ - lib/dedalus/elements.rb
169
+ - lib/dedalus/elements/heading.rb
170
+ - lib/dedalus/elements/icon.rb
171
+ - lib/dedalus/elements/image.rb
172
+ - lib/dedalus/elements/paragraph.rb
173
+ - lib/dedalus/elements/text.rb
174
+ - lib/dedalus/palette.rb
175
+ - lib/dedalus/pattern_library.rb
176
+ - lib/dedalus/pattern_library/application.rb
177
+ - lib/dedalus/pattern_library/application_view.rb
178
+ - lib/dedalus/pattern_library/library_view.rb
179
+ - lib/dedalus/pattern_library/models/library.rb
180
+ - lib/dedalus/pattern_library/models/library_item.rb
181
+ - lib/dedalus/pattern_library/models/library_section.rb
182
+ - lib/dedalus/pattern_library/molecules/library_item_example.rb
183
+ - lib/dedalus/pattern_library/molecules/library_section_tab.rb
184
+ - lib/dedalus/pattern_library/molecules/periodic_table.rb
185
+ - lib/dedalus/pattern_library/molecules/periodic_table_entry.rb
186
+ - lib/dedalus/pattern_library/organisms/app_footer.rb
187
+ - lib/dedalus/pattern_library/organisms/app_header.rb
188
+ - lib/dedalus/pattern_library/organisms/app_sidebar.rb
189
+ - lib/dedalus/pattern_library/organisms/library_entry.rb
190
+ - lib/dedalus/pattern_library/screens/app_screen.rb
191
+ - lib/dedalus/pattern_library/templates/app_template.rb
192
+ - lib/dedalus/version.rb
193
+ - lib/dedalus/view_traversal.rb
194
+ - media/icons/arrow_cursor.png
195
+ - media/icons/atom.png
196
+ - media/icons/hive.png
197
+ - media/icons/house.png
198
+ - media/icons/molecule.png
199
+ - media/icons/paramecium.png
200
+ - spec/dedalus_spec.rb
201
+ - spec/spec_helper.rb
202
+ homepage: https://rubygems.org/gems/dedalus
203
+ licenses:
204
+ - MIT
205
+ metadata: {}
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 2.4.5.1
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: atomic patterns for 2d games
226
+ test_files: []