redpotion 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0abf1e1631d21bf8bfa879fe8e6fb14a9c3ec223
4
- data.tar.gz: ee2269a3f65fa9ce99ffe036381160fbce750880
3
+ metadata.gz: abe41c73f1dd1327dd6a008509bd04f1d894fd5d
4
+ data.tar.gz: c1c67ea54c78dcd18a435f52bdd136dcfc8fef8d
5
5
  SHA512:
6
- metadata.gz: 8b6241dfffefc134da38ea26078ba915543cdfdaf79495870a8f41e04ab6a34048632140c8c5596ba66ffc087d3c3c815a8bd27f2b32adbfe478fcae268f9af7
7
- data.tar.gz: 8aec9fa68e66009ab06083150d51a54fbc90e305e89d0ba4e5fa4c146a2f755793f183e0308f3fa4374c2f9fe7fe8255583593e255f151433eaabe0ca8f6dff4
6
+ metadata.gz: c082e46b802e647b554824152393de86896fe71538fad1623c96a0bb755fe073ca27baaaab6bd20400683cc2fe9914cd723a5e7d4e1310333800463892dd996f
7
+ data.tar.gz: 1a2432aa8264225e94ccf5828afcff13cce8232670c6b56f8874961da0805eb19e7bbc343db0b6d80120c4b7ba5a80a84fd5c6417dde51fe47cee236ddf94ec2
data/README.md CHANGED
@@ -7,10 +7,6 @@ We believe iPhone development should be clean, scalable, and fast with a languag
7
7
 
8
8
  RedPotion combines [RMQ](http://rubymotionquery.com/), [ProMotion](https://github.com/clearsightstudio/ProMotion), [CDQ](https://github.com/infinitered/cdq), [AFMotion](https://github.com/clayallsopp/afmotion), [MotionPrint](https://github.com/OTGApps/motion_print) and [MORE!](#full-listing-of-gems-and-pods-for-redpotion). It also adds new features to better integrate RMQ with ProMotion. The goal is simply to choose standard libraries and promote best practices, allowing you to develop iOS apps in record time.
9
9
 
10
- =========
11
-
12
- ## Read the [documentation](http://redpotion.readthedocs.org/en/latest) [here](http://redpotion.readthedocs.org/en/latest)
13
-
14
10
 
15
11
  The **makers of RMQ** at [InfiniteRed](http://infinitered.com/) and the **creators of ProMotion** at [ClearSight](https://clearsightstudio.com/) as well as [David Larrabee](https://twitter.com/Squidpunch) have teamed up to create the ultimate RubyMotion library.
16
12
 
@@ -18,13 +14,9 @@ The **makers of RMQ** at [InfiniteRed](http://infinitered.com/) and the **creato
18
14
 
19
15
  ProMotion for screens and RMQ for styles, animations, traversing, events, etc.
20
16
 
21
- ## Plugins and Add-ons
22
-
23
- You can use both RMQ Plugins and ProMotion Add-ons
24
-
25
- ![image](https://camo.githubusercontent.com/523372b371be1de2fb2cec421be423e2b89bcfd0/687474703a2f2f69725f77702e73332e616d617a6f6e6177732e636f6d2f77702d636f6e74656e742f75706c6f6164732f73697465732f31392f323031342f30392f726d715f706c7567696e2e706e67)
17
+ =========
26
18
 
27
- ![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/11/2014/11/ProMotion-addon-logo.png)
19
+ ## Read the [documentation](http://redpotion.readthedocs.org/en/latest) [here](http://redpotion.readthedocs.org/en/latest)
28
20
 
29
21
 
30
22
  ## Quick start
@@ -51,297 +43,6 @@ add it to your `Gemfile`:
51
43
  - `gem 'redpotion'`
52
44
 
53
45
 
54
- ## Let's build something
55
-
56
- Let's start by creating our app, do this:
57
-
58
- ```
59
- > potion create myapp
60
- > cd myapp
61
- > bundle
62
- > rake pod:install
63
- > rake
64
- ```
65
-
66
- Your app should be running now. Type `exit` in console to stop your app.
67
-
68
- Let's add a text field, a button, and an image to the main screen:
69
-
70
- Open the `home_screen.rb` file, then add this
71
-
72
- ```ruby
73
- @image_url = append!(UITextField, :image_url)
74
-
75
- append UIButton, :go_button
76
-
77
- @sample_image = append!(UIImageView, :sample_image)
78
- ```
79
-
80
- Delete this line:
81
-
82
- ```ruby
83
- @hello_world = append!(UILabel, :hello_world)
84
- ```
85
-
86
- Now we need to style them so you can see them on your screen.
87
-
88
- Open up `home_screen_stylesheet.rb`, then add this:
89
-
90
- ```ruby
91
- def image_url(st)
92
- st.frame = {left: 20, from_right: 20, top: 80, height: 30}
93
- st.background_color = color.light_gray
94
- end
95
-
96
- def go_button(st)
97
- st.frame = {below_prev: 10, from_right: 20, width: 40, height: 30}
98
- st.text = "go"
99
- st.background_color = color.blue
100
- st.color = color.white
101
- end
102
-
103
- def sample_image(st)
104
- st.frame = {left: 20, below_prev: 10, from_right: 20, from_bottom: 20}
105
- st.background_color = color.gray
106
-
107
- # an example of using the view directly
108
- st.view.contentMode = UIViewContentModeScaleAspectFit
109
- end
110
- ```
111
-
112
- Now let's add the logic. When the user enters a URL to an image in the text field, then tap **Go**, it shows the picture in the image view below.
113
-
114
- Let's add the event to the go_button:
115
-
116
- Replace this:
117
- ```ruby
118
- append UIButton, :go_button
119
- ```
120
-
121
- With this:
122
- ```ruby
123
- append(UIButton, :go_button).on(:touch) do |sender|
124
- @sample_image.remote_image = @image_url.text
125
- @image_url.resignFirstResponder # Closes keyboard
126
- end
127
- ```
128
-
129
- You should end up with this `on_load` method:
130
-
131
- ```ruby
132
- def on_load
133
- set_nav_bar_button :left, system_item: :camera, action: :nav_left_button
134
- set_nav_bar_button :right, title: "Right", action: :nav_right_button
135
-
136
- @image_url = append!(UITextField, :image_url)
137
-
138
- append(UIButton, :go_button).on(:touch) do |sender|
139
- @sample_image.remote_image = @image_url.text
140
- @image_url.resignFirstResponder # Closes keyboard
141
- end
142
-
143
- @sample_image = append!(UIImageView, :sample_image)
144
- end
145
- ```
146
-
147
- Now paste this URL in and hit **Go**
148
- `http://bit.ly/18iMhwc`
149
-
150
- You should have this:
151
-
152
- ![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/11/2015/03/myapp_screenshot.jpg)
153
-
154
- ## Live stylesheet reloading
155
-
156
- In REPL, type: `live`
157
-
158
- ![image](http://clrsight.co/jh/LiveReload4.gif?+)
159
-
160
- ## New generators to integrate RMQ & ProMotion nicely ##
161
-
162
- Our new generators allow you to create your ProMotion screen and stylesheet template to let you hit the ground running. Currently the following RedPotion generators exist:
163
-
164
- ```
165
- potion create screen foo
166
- potion create table_screen foo
167
- potion create view foo
168
-
169
- # All rmq generators work with the potion command as well
170
- potion create model foo
171
- potion create shared foo
172
- potion create lib foo
173
-
174
- # rmq controller generators also still exist
175
- # but screens are preferred to get the redpotion value
176
- potion create controller foo
177
- potion create collection_view_controller foos
178
- potion create table_view_controller bars
179
-
180
- # RedPotion includes CDQ and afmotion by default, if you don't need these gems
181
- # we have provided command line tasks to remove either of them
182
- potion remove cdq
183
- potion remove afmotion
184
- ```
185
-
186
- ## New features for RMQ
187
-
188
- ### `find` is aliased to `rmq` so you can use it for a more natural reading code:
189
-
190
- ```ruby
191
- find.all.hide
192
- find(my_view).children.nudge(right: 10)
193
- ```
194
-
195
- ### You can use `app` directly in code, which is the same as `rmq.app`
196
-
197
- So you also get window, device, and delegate from that.
198
-
199
- ```
200
- app.device
201
- app.window
202
- app.delegate
203
- ```
204
-
205
- ### You can use the following in a UIView or Screen or UIViewController without prefacing it with `rmq`:
206
-
207
- ```ruby
208
- append
209
- append!
210
- prepend
211
- prepend!
212
- create
213
- create!
214
- build
215
- build!
216
- on
217
- apply_style
218
- reapply_styles
219
- style
220
- color
221
- image
222
- stylesheet
223
- stylesheet=
224
- ```
225
-
226
- ### Stylesheet in your screens
227
-
228
- You can specify the stylesheet in your screen like so:
229
-
230
- ```ruby
231
- class HomeScreen < PM::Screen
232
- title "RedPotion"
233
- stylesheet HomeStylesheet
234
-
235
- def on_load
236
- end
237
- end
238
- ```
239
-
240
- ### rmq_build can now be called on_load
241
-
242
- You can use either rmq_build or on_load, they do exactly the same thing. You can only use one or the other. `on_load` is preferred as it matches the screen's onload.
243
-
244
- ```ruby
245
- class Section < UIView
246
- def on_load
247
- apply_style :section
248
-
249
- append(UIButton, :section_button).on(:touch) do
250
- mp "Button touched"
251
- end
252
- end
253
- end
254
- ```
255
-
256
- ### Remote image loading for UIImageView styler
257
-
258
- You can set `remote_image` to a URL string or an instance of `NSURL` and it will automatically fetch the image and set the image (with caching) using the power of [JMImageCache](https://github.com/jakemarsh/JMImageCache).
259
-
260
- ```ruby
261
- class MyStylesheet < ApplicationStylesheet
262
- def my_ui_image_view(st)
263
- # placeholder_image= is just an alias to image=
264
- # Set the placeholder image you want from your resources directory
265
- st.placeholder_image = image.resource("my_placeholder")
266
- # Set the remote URL. It will be applied to the UIImageView
267
- # when downloaded or retrieved from the local cache.
268
- st.remote_image = "http://www.rubymotion.com/img/rubymotion-logo.png"
269
- # or st.remote_image = NSURL.urlWithString(...)
270
- end
271
- end
272
- ```
273
-
274
- In order to use this feature, you must add the `JMIMageCache` cocoapod to your project (this is included in a new project):
275
-
276
- ```ruby
277
- app.pods do
278
- pod 'JMImageCache'
279
- end
280
- ```
281
-
282
- ## New features for ProMotion
283
-
284
- ProMotion 2.2.0 added on_load and on_styled to match RedPotion
285
-
286
- ## RedPotion specific features
287
-
288
- UIColor has a `with` method. Allowing you to build a color from an existing color easily
289
-
290
- ```ruby
291
- # for example that time you want your existing color, but with a slight change
292
- color.my_custom_color.with(a: 0.5)
293
- ```
294
-
295
- PM::DataTableScreen - added a clean way to integrate a table screen with a custom cell, and data backed model
296
-
297
- ```ruby
298
- class ContributerScreen < PM::DataTableScreen
299
- title "RedPotion Contributers"
300
- refreshable
301
- stylesheet ContributerScreenStylesheet
302
- model Contributer
303
- end
304
-
305
- class Contributer < CDQManagedObject
306
- def cell
307
- {
308
- cell_class: ContributerCell,
309
- properties: {
310
- name: name
311
- }
312
- }
313
- end
314
- end
315
-
316
- class ContributerCell < ProMotion::TableViewCell
317
- def on_load
318
- apply_style :cell
319
-
320
- find(self.contentView).tap do |q|
321
- @title = q.append!(UILabel, :cell_title)
322
- end
323
- end
324
-
325
- def name=(value)
326
- @title.text = value
327
- end
328
- end
329
- ```
330
-
331
- ## Full listing of Gems and Pods for RedPotion
332
- **Gems**
333
- * [RMQ](http://rubymotionquery.com/)
334
- * [ProMotion](https://github.com/clearsightstudio/ProMotion)
335
- * [CDQ](https://github.com/infinitered/cdq)
336
- * [AFMotion](https://github.com/clayallsopp/afmotion)
337
- * [motion_print](https://github.com/OTGApps/motion_print)
338
- * [motion-cocoapods](https://github.com/HipByte/motion-cocoapods)
339
- * (DEV) [webstub](https://github.com/nathankot/webstub)
340
- * (DEV) [newclear](https://github.com/IconoclastLabs/newclear)
341
-
342
- **Pods**
343
- * [JMImageCache](https://github.com/jakemarsh/JMImageCache)
344
-
345
46
  ## Contributing
346
47
 
347
48
  0. Create an issue in GitHub to make sure your PR will be accepted.
data/bin/potion CHANGED
@@ -19,6 +19,7 @@ class PotionCommandLine
19
19
  > potion create screen foo
20
20
  > potion create table_screen foo
21
21
  > potion create metal_table_screen foo
22
+ > potion create collection_view_screen
22
23
  > potion create view bar
23
24
  > potion create shared some_class_used_app_wide
24
25
  > potion create lib some_class_used_by_multiple_apps
@@ -48,6 +49,7 @@ class PotionCommandLine
48
49
  :screen, :table_screen,
49
50
  :model, :controller,
50
51
  :metal_table_screen,
52
+ :collection_view_screen,
51
53
  :view,
52
54
  :shared,
53
55
  :lib,
@@ -153,7 +155,7 @@ class PotionCommandLine
153
155
 
154
156
  def insert_from_template(template_name, name)
155
157
  # TODO refactor this, it's less than wonderful
156
- if %w{metal_table_screen view}.include? template_name
158
+ if %w{metal_table_screen view collection_view_screen}.include? template_name
157
159
  # Do nothing
158
160
  elsif template_name =~ /.*screen/
159
161
  @screen_base = template_name.split('_').collect(&:capitalize).join
@@ -86,8 +86,4 @@ class UIView
86
86
  def stylesheet=(value)
87
87
  rmq.stylesheet = value
88
88
  end
89
-
90
- def find(*args)
91
- rmq(self).find(*args)
92
- end
93
89
  end
@@ -51,10 +51,6 @@ class UIViewController
51
51
  rmq.stylesheet = value
52
52
  end
53
53
 
54
- def find(*args)
55
- rmq(self.view).find(*args)
56
- end
57
-
58
54
  def self.stylesheet(style_sheet_class)
59
55
  @rmq_style_sheet_class = style_sheet_class
60
56
  end
@@ -74,7 +70,7 @@ class UIViewController
74
70
  def viewDidLoad
75
71
  if self.class.rmq_style_sheet_class
76
72
  self.rmq.stylesheet = self.class.rmq_style_sheet_class
77
- self.view.rmq.apply_style :root_view
73
+ self.view.rmq.apply_style(:root_view) if self.rmq.stylesheet.respond_to?(:root_view)
78
74
  end
79
75
 
80
76
  self.originalViewDidLoad
@@ -161,6 +157,6 @@ class UIViewController
161
157
  private
162
158
 
163
159
  def pm_handles_delegates?
164
- self.is_a?(ProMotion::ViewController) || self.is_a?(ProMotion::TableScreen)
160
+ self.is_a?(ProMotion::ViewController) || self.is_a?(ProMotion::TableViewController)
165
161
  end
166
162
  end
@@ -1,3 +1,3 @@
1
1
  module RedPotion
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -0,0 +1,54 @@
1
+ class <%= @name_camel_case %>Screen < UICollectionViewController
2
+ include ProMotion::ScreenModule
3
+
4
+ title "Your title here"
5
+ stylesheet <%= @name_camel_case %>ScreenStylesheet
6
+
7
+ <%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell"
8
+
9
+ def self.new(args = {})
10
+ # Set layout
11
+ layout = UICollectionViewFlowLayout.alloc.init
12
+ s = self.alloc.initWithCollectionViewLayout(layout)
13
+ s.screen_init(args) if s.respond_to?(:screen_init)
14
+ s
15
+ end
16
+
17
+ def on_load
18
+ collectionView.tap do |cv|
19
+ cv.registerClass(<%= @name_camel_case %>Cell, forCellWithReuseIdentifier: <%= @name.upcase %>_CELL_ID)
20
+ cv.delegate = self
21
+ cv.dataSource = self
22
+ cv.allowsSelection = true
23
+ cv.allowsMultipleSelection = false
24
+ find(cv).apply_style :collection_view
25
+ end
26
+ end
27
+
28
+ # Remove the following if you're only using portrait
29
+ def will_animate_rotate(orientation, duration)
30
+ reapply_styles
31
+ end
32
+
33
+ def numberOfSectionsInCollectionView(view)
34
+ 1
35
+ end
36
+
37
+ def collectionView(view, numberOfItemsInSection: section)
38
+ 200
39
+ end
40
+
41
+ def collectionView(view, cellForItemAtIndexPath: index_path)
42
+ view.dequeueReusableCellWithReuseIdentifier(<%= @name.upcase %>_CELL_ID, forIndexPath: index_path).tap do |cell|
43
+ build(cell) unless cell.reused
44
+
45
+ # Update cell's data here
46
+ end
47
+ end
48
+
49
+ def collectionView(view, didSelectItemAtIndexPath: index_path)
50
+ cell = view.cellForItemAtIndexPath(index_path)
51
+ puts "Selected at section: #{index_path.section}, row: #{index_path.row}"
52
+ end
53
+
54
+ end
@@ -0,0 +1,13 @@
1
+ module <%= @name_camel_case %>CellStylesheet
2
+ def cell_size
3
+ {w: 96, h: 96}
4
+ end
5
+
6
+ def <%= @name %>_cell(st)
7
+ st.frame = cell_size
8
+ st.background_color = color.random
9
+
10
+ # Style overall view here
11
+ end
12
+
13
+ end
@@ -0,0 +1,25 @@
1
+ class <%= @name_camel_case %>ScreenStylesheet < ApplicationStylesheet
2
+
3
+ include <%= @name_camel_case %>CellStylesheet
4
+
5
+ def setup
6
+ # Add stylesheet specific setup stuff here.
7
+ # Add application specific setup stuff in application_stylesheet.rb
8
+
9
+ @margin = ipad? ? 12 : 8
10
+ end
11
+
12
+ def collection_view(st)
13
+ st.view.contentInset = [@margin, @margin, @margin, @margin]
14
+ st.background_color = color.white
15
+
16
+ st.view.collectionViewLayout.tap do |cl|
17
+ cl.itemSize = [cell_size[:w], cell_size[:h]]
18
+ #cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
19
+ #cl.headerReferenceSize = [cell_size[:w], cell_size[:h]]
20
+ cl.minimumInteritemSpacing = @margin
21
+ cl.minimumLineSpacing = @margin
22
+ #cl.sectionInset = [0,0,0,0]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ class <%= @name_camel_case %>Cell < UICollectionViewCell
2
+ attr_reader :reused
3
+
4
+ def on_load
5
+ find(self).apply_style :<%= @name %>_cell
6
+
7
+ q = find(self.contentView)
8
+ # Add your subviews, init stuff here
9
+ # @foo = q.append!(UILabel, :foo)
10
+ end
11
+
12
+ def prepareForReuse
13
+ @reused = true
14
+ end
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ describe '<%= @name_camel_case %>Screen' do
2
+
3
+ before do
4
+ end
5
+
6
+ after do
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ describe '<%= @name_camel_case %>Cell' do
2
+
3
+ before do
4
+ end
5
+
6
+ after do
7
+ end
8
+
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redpotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfiniteRed
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-20 00:00:00.000000000 Z
12
+ date: 2015-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby_motion_query
@@ -133,6 +133,12 @@ files:
133
133
  - lib/project/ruby_motion_query/traverse.rb
134
134
  - lib/project/version.rb
135
135
  - lib/redpotion.rb
136
+ - templates/collection_view_screen/app/screens/name_screen.rb
137
+ - templates/collection_view_screen/app/stylesheets/name_cell_stylesheet.rb
138
+ - templates/collection_view_screen/app/stylesheets/name_screen_stylesheet.rb
139
+ - templates/collection_view_screen/app/views/name_cell.rb
140
+ - templates/collection_view_screen/spec/screens/name_screen_spec.rb
141
+ - templates/collection_view_screen/spec/views/name_cell_spec.rb
136
142
  - templates/metal_table_screen/app/screens/name_screen.rb
137
143
  - templates/metal_table_screen/app/stylesheets/name_screen_stylesheet.rb
138
144
  - templates/metal_table_screen/app/views/name_cell.rb