motion-prime 0.8.12 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +4 -1
- data/ROADMAP.md +3 -6
- data/bin/prime +14 -4
- data/files/Gemfile +1 -1
- data/generators/generator.rb +29 -0
- data/generators/model_generator.rb +7 -0
- data/generators/scaffold_generator.rb +17 -0
- data/generators/screen_generator.rb +8 -0
- data/generators/table_generator.rb +10 -0
- data/generators/templates/cell.rb +3 -0
- data/generators/templates/model.rb +4 -0
- data/generators/templates/scaffold/cell.rb +4 -0
- data/generators/templates/scaffold/form.rb +18 -0
- data/generators/templates/scaffold/model.rb +4 -0
- data/generators/templates/scaffold/screen.rb +45 -0
- data/generators/templates/scaffold/show.rb +3 -0
- data/generators/templates/scaffold/styles.rb +18 -0
- data/generators/templates/scaffold/table.rb +12 -0
- data/generators/templates/screen.rb +7 -0
- data/generators/templates/table.rb +8 -0
- data/lib/motion-prime.rb +1 -0
- data/motion-prime.gemspec +2 -0
- data/motion-prime/delegate/_base_mixin.rb +32 -0
- data/motion-prime/delegate/_navigation_mixin.rb +41 -0
- data/motion-prime/delegate/app_delegate.rb +28 -0
- data/motion-prime/screens/_base_mixin.rb +12 -4
- data/motion-prime/screens/_sections_mixin.rb +9 -4
- data/motion-prime/screens/extensions/_navigation_bar_mixin.rb +16 -12
- data/motion-prime/screens/screen.rb +4 -2
- data/motion-prime/version.rb +1 -1
- data/spec/features/screens/open_screen.rb +51 -0
- data/spec/helpers/delegates.rb +7 -0
- data/spec/helpers/screens.rb +9 -0
- data/spec/helpers/sections.rb +3 -0
- data/spec/{config → unit/config}/store_spec.rb +0 -0
- data/spec/{delegate → unit/delegate}/delegate_spec.rb +1 -1
- data/spec/{models → unit/models}/association_collection_spec.rb +0 -0
- data/spec/{models → unit/models}/associations_spec.rb +0 -0
- data/spec/{models → unit/models}/bag_spec.rb +0 -0
- data/spec/{models → unit/models}/dirty_spec.rb +0 -0
- data/spec/{models → unit/models}/errors_spec.rb +0 -0
- data/spec/{models → unit/models}/finder_spec.rb +0 -0
- data/spec/{models → unit/models}/json.rb +0 -0
- data/spec/{models → unit/models}/model_spec.rb +0 -0
- data/spec/{models → unit/models}/store_extension_spec.rb +0 -0
- data/spec/{models → unit/models}/store_spec.rb +0 -0
- data/spec/{prime → unit/prime}/env.rb +0 -0
- data/spec/{screens → unit/screens}/screen_spec.rb +0 -0
- metadata +80 -30
- data/motion-prime/app_delegate.rb +0 -92
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGI3OGI3YjIzZmQ5OWNlZGU5MzdhOGQ0MjE3NjdlYTU2OGQ5NzlkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDIxOTFhMGFlM2Y4ZTgxM2VjZjQwMmM3MmJhNmQzNmU4MTcxNjk1Ng==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWViNmQ2Yjg5OTlmZGU2ZmZiMjljYzQ1YWQwMjk3MDRiOWU5MWM3Mzc1ZWUx
|
10
|
+
MmEwZDRlMzIwZDU3OWI3NzZkZmIzZTFmOGI0NjZiMjlhYThmY2I5M2Q0YjM2
|
11
|
+
MTYyYzFiOGJkYzE2YjU1YTQ5OTdiOWM3ZWFkNjFmMmNmYjdhZTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzE3Zjc2YmJkM2Y0ODlhNzJlZGE3NmU4NjY3OGU4OGZjYmJmZjU1N2IzNDJm
|
14
|
+
MWQ4ZTE5NmY3ZDc4Zjc5NGUzYzMyNmI2ZGQ2MDZhZmFhNGYwODc5YjgxMjU1
|
15
|
+
MDI0ZTQ2MDMzMDE1ZGE4OGQ0OWQ0YzkwZTIwZDdlMmM4ZjIyYzE=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.9.0
|
2
|
+
* Added generators for model/screen/table.
|
3
|
+
* Added scaffold generator.
|
4
|
+
* Added ability to open screen with action.
|
5
|
+
|
6
|
+
=== 0.8.13
|
7
|
+
* Fix issue with deallocating screen if no sidebar is used.
|
8
|
+
* motion_require now works inside application.
|
9
|
+
|
1
10
|
=== 0.8.11 - 0.8.12
|
2
11
|
* Ability to send block to after_render/before_render
|
3
12
|
* Added ability to get all form field values via `field_values`
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
motion-prime (0.
|
4
|
+
motion-prime (0.9.0)
|
5
|
+
activesupport
|
5
6
|
afmotion (~> 2.0.0)
|
6
7
|
bubble-wrap (~> 1.5.0)
|
7
8
|
cocoapods
|
@@ -11,6 +12,7 @@ PATH
|
|
11
12
|
motion-support (~> 0.2.6)
|
12
13
|
rm-digest
|
13
14
|
sugarcube (~> 1.5.2)
|
15
|
+
thor
|
14
16
|
|
15
17
|
GEM
|
16
18
|
remote: http://rubygems.org/
|
@@ -62,6 +64,7 @@ GEM
|
|
62
64
|
rake (10.1.1)
|
63
65
|
rm-digest (0.0.2)
|
64
66
|
sugarcube (1.5.4)
|
67
|
+
thor (0.18.1)
|
65
68
|
xcodeproj (0.14.1)
|
66
69
|
activesupport (~> 3.0)
|
67
70
|
colored (~> 1.2)
|
data/ROADMAP.md
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
=== 0.9.0
|
2
|
-
* Move api_client and model sync mixin to prime_api gem.
|
3
|
-
* Move bind keyboard events to forms.
|
4
|
-
|
5
1
|
=== 1.0.0
|
6
2
|
* bug: content_vertical_alignment conflicts with padding.
|
7
3
|
* bug: content_vertical_alignment has not ideal centering.
|
@@ -10,7 +6,6 @@
|
|
10
6
|
* bug: bind_keyboard_close breaks bind_guesture
|
11
7
|
* bug: dealloc of Prime::Section will not be called for cell created in table_data using #map.
|
12
8
|
* bug: images does not render after reload table if using draw_with_layer (prerender not enabled).
|
13
|
-
* add clone to models to prevent problems when bag_key is overrided
|
14
9
|
* add dsl for push notifications
|
15
10
|
* add some extensions/middleware system, at least for networking.
|
16
11
|
* create "display_network_error" extension.
|
@@ -18,7 +13,9 @@
|
|
18
13
|
* add size_to_fit support for images.
|
19
14
|
|
20
15
|
=== 1.1.0
|
21
|
-
*
|
16
|
+
* Move api_client and model sync mixin to prime_model_sync gem.
|
17
|
+
* Move models to prime_model gem.
|
18
|
+
* Move bind keyboard events to forms.
|
22
19
|
|
23
20
|
=== 1.2.0
|
24
21
|
* add cell preload for reverse scrolling table.
|
data/bin/prime
CHANGED
@@ -3,16 +3,17 @@
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'methadone'
|
5
5
|
require_relative '../motion-prime/version'
|
6
|
-
|
7
6
|
class App
|
8
7
|
include Methadone::Main
|
9
8
|
include Methadone::CLILogging
|
10
9
|
include Methadone::SH
|
11
10
|
|
12
|
-
main do |command,
|
11
|
+
main do |command, *opts|
|
13
12
|
case command.to_sym
|
14
|
-
when :new then create_base(
|
15
|
-
when :bootstrap then create_bootstrap(
|
13
|
+
when :new then create_base(*opts)
|
14
|
+
when :bootstrap then create_bootstrap(*opts)
|
15
|
+
when :generate then generate(*opts)
|
16
|
+
when :g then generate(*opts)
|
16
17
|
else help
|
17
18
|
end
|
18
19
|
0
|
@@ -23,6 +24,10 @@ class App
|
|
23
24
|
info "Commands:"
|
24
25
|
info " new <appname>"
|
25
26
|
info " Creates a new MotionPrime app from a template."
|
27
|
+
info " generate scaffold <name>"
|
28
|
+
info " Creates a new MotionPrime scaffold from a template."
|
29
|
+
info " generate screen|model|table <name>"
|
30
|
+
info " Creates a new MotionPrime resource from a template."
|
26
31
|
end
|
27
32
|
|
28
33
|
def self.create_base(name)
|
@@ -50,6 +55,11 @@ class App
|
|
50
55
|
sh "cd ./#{name}; rake pod:install"
|
51
56
|
end
|
52
57
|
|
58
|
+
def self.generate(resource, name)
|
59
|
+
require_relative '../generators/generator'
|
60
|
+
MotionPrime::Generator.factory(resource).generate(name)
|
61
|
+
end
|
62
|
+
|
53
63
|
def self.home_path
|
54
64
|
ENV['HOME'].split('/')[0..2].join('/')
|
55
65
|
end
|
data/files/Gemfile
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'thor'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
class MotionPrime::Generator < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
File.dirname(__FILE__) + '/templates'
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def factory(resource)
|
13
|
+
case resource.to_sym
|
14
|
+
when :screen
|
15
|
+
require_relative './screen_generator'
|
16
|
+
MotionPrime::ScreenGenerator.new
|
17
|
+
when :model
|
18
|
+
require_relative './model_generator'
|
19
|
+
MotionPrime::ModelGenerator.new
|
20
|
+
when :table
|
21
|
+
require_relative './table_generator'
|
22
|
+
MotionPrime::TableGenerator.new
|
23
|
+
when :scaffold
|
24
|
+
require_relative './scaffold_generator'
|
25
|
+
MotionPrime::ScaffoldGenerator.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class MotionPrime::ScaffoldGenerator < MotionPrime::Generator
|
2
|
+
def generate(name)
|
3
|
+
@s_name = name.singularize.downcase
|
4
|
+
@p_name = name.pluralize.downcase
|
5
|
+
@s_title = @s_name.titleize
|
6
|
+
@p_title = @p_name.titleize
|
7
|
+
@s_class_name = @s_name.camelize
|
8
|
+
@p_class_name = @p_name.camelize
|
9
|
+
template 'scaffold/screen.rb', "app/screens/#{@p_name}.rb"
|
10
|
+
template 'scaffold/model.rb', "app/models/#{@s_name}.rb"
|
11
|
+
template 'scaffold/table.rb', "app/sections/#{@p_name}/table.rb"
|
12
|
+
template 'scaffold/cell.rb', "app/sections/#{@p_name}/cell.rb"
|
13
|
+
template 'scaffold/form.rb', "app/sections/#{@p_name}/form.rb"
|
14
|
+
template 'scaffold/show.rb', "app/sections/#{@p_name}/show.rb"
|
15
|
+
template 'scaffold/styles.rb', "app/styles/#{@p_name}.rb"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class MotionPrime::TableGenerator < MotionPrime::Generator
|
2
|
+
def generate(name)
|
3
|
+
@name = name.downcase.singularize
|
4
|
+
@model_class_name = "#{name.camelize}"
|
5
|
+
@table_class_name = "#{name.pluralize.camelize}TableSection"
|
6
|
+
@cell_class_name = "#{name.pluralize.camelize}CellSection"
|
7
|
+
template 'table.rb', "app/sections/#{name.pluralize}/table.rb"
|
8
|
+
template 'cell.rb', "app/sections/#{name.pluralize}/cell.rb"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class <%= @p_class_name %>FormSection < Prime::FormSection
|
2
|
+
field :title,
|
3
|
+
label: { text: 'Title' },
|
4
|
+
input: {
|
5
|
+
text: proc { form.model.title },
|
6
|
+
placeholder: "Enter title here"
|
7
|
+
}
|
8
|
+
|
9
|
+
field :submit, type: :submit,
|
10
|
+
button: { title: "Save" },
|
11
|
+
action: :on_submit
|
12
|
+
|
13
|
+
def on_submit
|
14
|
+
model.assign_attributes(field_values)
|
15
|
+
model.save
|
16
|
+
screen.back
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class <%= @p_class_name %>Screen < ApplicationScreen
|
2
|
+
title "<%= @p_title %>"
|
3
|
+
|
4
|
+
# open_screen "<%= @p_name %>#index"
|
5
|
+
def index
|
6
|
+
set_title "<%= @p_title %>"
|
7
|
+
set_navigation_right_button 'New' do
|
8
|
+
open_screen "<%= @p_name %>#new"
|
9
|
+
end
|
10
|
+
set_section :<%= @p_name %>_table
|
11
|
+
end
|
12
|
+
|
13
|
+
# open_screen "<%= @p_name %>#show"
|
14
|
+
def show
|
15
|
+
@model = params[:model]
|
16
|
+
set_title "Show <%= @s_title %>"
|
17
|
+
set_navigation_back_button 'Back'
|
18
|
+
set_navigation_right_button 'Edit' do
|
19
|
+
open_screen "<%= @p_name %>#edit", params: { model: @model }
|
20
|
+
end
|
21
|
+
set_section :<%= @p_name %>_show, model: @model
|
22
|
+
end
|
23
|
+
|
24
|
+
# open_screen "<%= @p_name %>#edit"
|
25
|
+
def edit
|
26
|
+
@model = params[:model]
|
27
|
+
set_title "Edit <%= @s_title %>"
|
28
|
+
set_navigation_back_button 'Cancel'
|
29
|
+
set_section :<%= @p_name %>_form, model: @model
|
30
|
+
end
|
31
|
+
|
32
|
+
# open_screen "<%= @p_name %>#new"
|
33
|
+
def new
|
34
|
+
@model = <%= @s_class_name %>.new
|
35
|
+
set_title "New <%= @s_title %>"
|
36
|
+
set_navigation_back_button 'Cancel'
|
37
|
+
set_section :<%= @p_name %>_form, model: @model
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_return
|
41
|
+
if action?(:index)
|
42
|
+
main_section.reload_data
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Prime::Styles.define :<%= @p_name %> do
|
2
|
+
style :cell do
|
3
|
+
style :title,
|
4
|
+
text_color: :app_base,
|
5
|
+
left: 20,
|
6
|
+
top: 10,
|
7
|
+
width: 280,
|
8
|
+
font: :app_base.uifont(16),
|
9
|
+
size_to_fit: true
|
10
|
+
end
|
11
|
+
style :show do
|
12
|
+
style :title,
|
13
|
+
top: 120,
|
14
|
+
left: 0,
|
15
|
+
right: 0,
|
16
|
+
text_alignment: :center
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class <%= @p_class_name %>TableSection < Prime::TableSection
|
2
|
+
def table_data
|
3
|
+
<%= @s_class_name %>.all.map do |model|
|
4
|
+
<%= @p_class_name %>CellSection.new(model: model)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_click(table, index)
|
9
|
+
section = data[index.row]
|
10
|
+
screen.open_screen '<%= @p_name %>#show', params: { model: section.model }
|
11
|
+
end
|
12
|
+
end
|
data/lib/motion-prime.rb
CHANGED
@@ -10,6 +10,7 @@ require File.expand_path('../../motion-prime/env.rb', __FILE__)
|
|
10
10
|
require File.expand_path('../../motion-prime/prime.rb', __FILE__)
|
11
11
|
|
12
12
|
Motion::Require.all(Dir.glob(File.expand_path('../../motion-prime/**/*.rb', __FILE__)))
|
13
|
+
Motion::Require.all
|
13
14
|
|
14
15
|
Motion::Project::App.setup do |app|
|
15
16
|
app.detect_dependencies = false
|
data/motion-prime.gemspec
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module MotionPrime
|
2
|
+
module DelegateBaseMixin
|
3
|
+
attr_accessor :window
|
4
|
+
|
5
|
+
def application(application, willFinishLaunchingWithOptions:opts)
|
6
|
+
MotionPrime::Config.configure!
|
7
|
+
MotionPrime::Styles.define!
|
8
|
+
Prime.logger.info "Loading Prime application with env: #{Prime.env}"
|
9
|
+
application.setStatusBarStyle UIStatusBarStyleLightContent
|
10
|
+
application.setStatusBarHidden false
|
11
|
+
end
|
12
|
+
|
13
|
+
def application(application, didFinishLaunchingWithOptions:launch_options)
|
14
|
+
on_load(application, launch_options)
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def application(application, didRegisterForRemoteNotificationsWithDeviceToken: token)
|
19
|
+
on_apn_register_success(application, token)
|
20
|
+
end
|
21
|
+
def application(application, didFailToRegisterForRemoteNotificationsWithError: error)
|
22
|
+
on_apn_register_fail(application, error)
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_load(application, launch_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def app_window
|
29
|
+
self.app_delegate.window
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MotionPrime
|
2
|
+
module DelegateNavigationMixin
|
3
|
+
def open_screen(screen, options = {})
|
4
|
+
screen = prepare_screen_for_open(screen, options)
|
5
|
+
if options[:root] || !self.window
|
6
|
+
open_root_screen(screen, options)
|
7
|
+
else
|
8
|
+
open_content_screen(screen, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def prepare_screen_for_open(screen, options = {})
|
14
|
+
Screen.create_with_options(screen, true, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def open_root_screen(screen, options = {})
|
18
|
+
screen.send(:on_screen_load) if screen.respond_to?(:on_screen_load)
|
19
|
+
screen.wrap_in_navigation if screen.respond_to?(:wrap_in_navigation)
|
20
|
+
|
21
|
+
screen = screen.main_controller.strong_ref if screen.respond_to?(:main_controller)
|
22
|
+
|
23
|
+
self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
24
|
+
if options[:animated]
|
25
|
+
UIView.transitionWithView self.window,
|
26
|
+
duration: 0.5,
|
27
|
+
options: UIViewAnimationOptionTransitionFlipFromLeft,
|
28
|
+
animations: proc { self.window.rootViewController = screen },
|
29
|
+
completion: nil
|
30
|
+
else
|
31
|
+
self.window.rootViewController = screen
|
32
|
+
end
|
33
|
+
self.window.makeKeyAndVisible
|
34
|
+
screen
|
35
|
+
end
|
36
|
+
|
37
|
+
def open_content_screen(screen, options = {})
|
38
|
+
open_root_screen(screen)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
motion_require '../helpers/has_authorization'
|
2
|
+
motion_require './_base_mixin'
|
3
|
+
motion_require './_navigation_mixin'
|
4
|
+
module MotionPrime
|
5
|
+
class BaseAppDelegate
|
6
|
+
include HasAuthorization
|
7
|
+
include DelegateBaseMixin
|
8
|
+
include DelegateNavigationMixin
|
9
|
+
|
10
|
+
def on_apn_register_success(application, token)
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_apn_register_fail(application, error)
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
@current_user ||= if defined?(User) && User.respond_to?(:current)
|
18
|
+
User.current
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset_current_user
|
23
|
+
user_was = @current_user
|
24
|
+
@current_user = nil
|
25
|
+
NSNotificationCenter.defaultCenter.postNotificationName(:on_current_user_reset, object: user_was)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -12,7 +12,7 @@ module MotionPrime
|
|
12
12
|
include MotionPrime::ScreenNavigationMixin
|
13
13
|
include MotionPrime::ScreenSectionsMixin
|
14
14
|
|
15
|
-
attr_accessor :parent_screen, :modal, :params, :options, :tab_bar
|
15
|
+
attr_accessor :parent_screen, :modal, :params, :options, :tab_bar, :action
|
16
16
|
class_attribute :current_screen
|
17
17
|
|
18
18
|
def app_delegate
|
@@ -30,7 +30,7 @@ module MotionPrime
|
|
30
30
|
unless self.is_a?(UIViewController)
|
31
31
|
raise StandardError.new("ERROR: Screens must extend UIViewController.")
|
32
32
|
end
|
33
|
-
|
33
|
+
options[:action] ||= 'render'
|
34
34
|
self.options = options
|
35
35
|
self.params = options[:params] || {}
|
36
36
|
options.each do |k, v|
|
@@ -39,6 +39,10 @@ module MotionPrime
|
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
|
+
def action?(action)
|
43
|
+
self.action == action.to_s
|
44
|
+
end
|
45
|
+
|
42
46
|
def modal?
|
43
47
|
!!self.modal
|
44
48
|
end
|
@@ -51,7 +55,9 @@ module MotionPrime
|
|
51
55
|
|
52
56
|
def title=(new_title)
|
53
57
|
self.class.title(new_title)
|
58
|
+
self.navigationItem.title = new_title
|
54
59
|
end
|
60
|
+
alias_method :set_title, :title=
|
55
61
|
|
56
62
|
def main_controller
|
57
63
|
has_navigation? ? navigation_controller : self
|
@@ -78,9 +84,11 @@ module MotionPrime
|
|
78
84
|
end
|
79
85
|
def create_with_options(screen, navigation = true, options = {})
|
80
86
|
screen = create_tab_bar(screen, options) if screen.is_a?(Array)
|
81
|
-
if screen.is_a?(Symbol)
|
87
|
+
if screen.is_a?(Symbol) || screen.is_a?(String)
|
88
|
+
screen_name, action_name = screen.to_s.split('#')
|
89
|
+
options[:action] ||= action_name || 'render'
|
82
90
|
options[:navigation] = navigation unless options.has_key?(:navigation)
|
83
|
-
screen = class_factory("#{
|
91
|
+
screen = class_factory("#{screen_name}_screen").new(options)
|
84
92
|
end
|
85
93
|
screen
|
86
94
|
end
|
@@ -24,17 +24,22 @@ module MotionPrime
|
|
24
24
|
return unless section_options
|
25
25
|
@sections = {}
|
26
26
|
section_options.map do |name, options|
|
27
|
-
section = create_section(options.clone)
|
27
|
+
section = create_section(name, options.clone)
|
28
28
|
@sections[name] = section if section
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def create_section(options)
|
33
|
-
section_class = class_factory("#{
|
32
|
+
def create_section(name, options)
|
33
|
+
section_class = class_factory("#{name}_section")
|
34
34
|
options = normalize_options(options).merge(screen: self)
|
35
35
|
!options.has_key?(:if) || options[:if] ? section_class.new(options) : nil
|
36
36
|
end
|
37
37
|
|
38
|
+
def set_section(name, options = {})
|
39
|
+
@main_section = create_section(name, options)
|
40
|
+
@main_section.render
|
41
|
+
end
|
42
|
+
|
38
43
|
def render_sections
|
39
44
|
return unless @sections
|
40
45
|
if all_sections.count > 1
|
@@ -52,7 +57,7 @@ module MotionPrime
|
|
52
57
|
module ClassMethods
|
53
58
|
def section(name, options = {})
|
54
59
|
self._section_options ||= {}
|
55
|
-
self._section_options[name.to_sym] = options
|
60
|
+
self._section_options[name.to_sym] = options
|
56
61
|
|
57
62
|
define_method name do
|
58
63
|
@sections[name]
|
@@ -12,12 +12,12 @@ module MotionPrime
|
|
12
12
|
navigationItem.setRightBarButtonItem(nil, animated: args[:animated])
|
13
13
|
end
|
14
14
|
|
15
|
-
def set_navigation_right_button(title, args = {})
|
16
|
-
navigationItem.rightBarButtonItem = create_navigation_button(title, args)
|
15
|
+
def set_navigation_right_button(title, args = {}, &block)
|
16
|
+
navigationItem.rightBarButtonItem = create_navigation_button(title, args, &block)
|
17
17
|
end
|
18
18
|
|
19
|
-
def set_navigation_left_button(title, args = {})
|
20
|
-
navigationItem.leftBarButtonItem = create_navigation_button(title, args)
|
19
|
+
def set_navigation_left_button(title, args = {}, &block)
|
20
|
+
navigationItem.leftBarButtonItem = create_navigation_button(title, args, &block)
|
21
21
|
end
|
22
22
|
|
23
23
|
def set_navigation_back_button(title, args = {})
|
@@ -40,9 +40,9 @@ module MotionPrime
|
|
40
40
|
navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithCustomView(view)
|
41
41
|
end
|
42
42
|
|
43
|
-
def create_navigation_button(title, args = {})
|
43
|
+
def create_navigation_button(title, args = {}, &block)
|
44
44
|
args[:style] ||= UIBarButtonItemStylePlain
|
45
|
-
args[:action] ||= nil
|
45
|
+
args[:action] ||= block || nil
|
46
46
|
# TODO: Find better place for this code, may be just create custom control
|
47
47
|
if title.is_a?(UIButton)
|
48
48
|
title.on :touch do
|
@@ -53,17 +53,21 @@ module MotionPrime
|
|
53
53
|
elsif args[:image]
|
54
54
|
create_navigation_button_with_image(title, args)
|
55
55
|
elsif args[:icon]
|
56
|
-
|
56
|
+
create_navigation_button_with_title(title, args)
|
57
57
|
else
|
58
|
-
|
59
|
-
|
58
|
+
if args[:action].is_a?(Proc)
|
59
|
+
create_navigation_button_with_title(title, args)
|
60
|
+
else
|
61
|
+
UIBarButtonItem.alloc.initWithTitle(title,
|
62
|
+
style: args[:style], target: args[:target] || self, action: args[:action])
|
63
|
+
end
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
63
|
-
def
|
64
|
-
image = args[:icon].uiimage
|
67
|
+
def create_navigation_button_with_title(title, args)
|
68
|
+
image = args[:icon].uiimage if args[:icon]
|
65
69
|
face = UIButton.buttonWithType UIButtonTypeCustom
|
66
|
-
face.setImage(image, forState: UIControlStateNormal)
|
70
|
+
face.setImage(image, forState: UIControlStateNormal) if args[:icon]
|
67
71
|
face.setTitle(title, forState: UIControlStateNormal)
|
68
72
|
face.setContentHorizontalAlignment UIControlContentHorizontalAlignmentLeft
|
69
73
|
face.sizeToFit
|
@@ -36,7 +36,9 @@ module MotionPrime
|
|
36
36
|
@on_appear_happened ||= {}
|
37
37
|
unless @on_appear_happened[view.object_id]
|
38
38
|
setup view, styles: default_styles do
|
39
|
-
run_callbacks :render
|
39
|
+
run_callbacks :render do
|
40
|
+
send((action).to_sym)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
42
44
|
@on_appear_happened[view.object_id] = true
|
@@ -58,7 +60,7 @@ module MotionPrime
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def visible?
|
61
|
-
|
63
|
+
!!@visible
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
data/motion-prime/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
describe "open screen" do
|
2
|
+
describe "from app delegate with default options" do
|
3
|
+
before do
|
4
|
+
App.delegate.open_screen :sample
|
5
|
+
@controller = App.delegate.window.rootViewController
|
6
|
+
end
|
7
|
+
it "should open with navigation by default" do
|
8
|
+
@controller.is_a?(UINavigationController).should.be.true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should open screen" do
|
12
|
+
@controller.childViewControllers.first.is_a?(SampleScreen).should.be.true
|
13
|
+
@controller.childViewControllers.first.visible?.should.be.true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "from app delegate with navigation false" do
|
18
|
+
before do
|
19
|
+
App.delegate.open_screen :sample, navigation: false
|
20
|
+
@controller = App.delegate.window.rootViewController
|
21
|
+
end
|
22
|
+
it "should open screen" do
|
23
|
+
@controller.is_a?(SampleScreen).should.be.true
|
24
|
+
@controller.visible?.should.be.true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "from another screen with navigation: true" do
|
29
|
+
before do
|
30
|
+
@parent_screen = SampleScreen.new(navigation: true)
|
31
|
+
@child_screen = SampleScreen.new(navigation: true)
|
32
|
+
|
33
|
+
App.delegate.open_screen @parent_screen
|
34
|
+
@parent_screen.open_screen @child_screen
|
35
|
+
@controller = App.delegate.window.rootViewController
|
36
|
+
|
37
|
+
# we should call it because will_appear will happen async
|
38
|
+
@child_screen.will_appear
|
39
|
+
@parent_screen.will_disappear
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should open child screen navigational" do
|
43
|
+
@controller.childViewControllers.last.should == @child_screen
|
44
|
+
@child_screen.visible?.should.be.true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should make parent screen invisible" do
|
48
|
+
@parent_screen.visible?.should.be.false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/helpers/delegates.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# motion_require '../../motion-prime/helpers/has_authorization'
|
2
|
+
# motion_require './../motion-prime/delegate/_base_mixin'
|
3
|
+
# motion_require './../motion-prime/delegate/_navigation_mixin'
|
4
|
+
AppDelegate.send :include, MotionPrime::HasAuthorization
|
5
|
+
AppDelegate.send :include, MotionPrime::DelegateBaseMixin
|
6
|
+
AppDelegate.send :include, MotionPrime::DelegateNavigationMixin
|
7
|
+
|
1
8
|
class BaseDelegate < MotionPrime::BaseAppDelegate
|
2
9
|
def on_load(app, options)
|
3
10
|
self.was_loaded = true
|
data/spec/helpers/screens.rb
CHANGED
@@ -6,4 +6,13 @@ class BaseScreen < MotionPrime::Screen
|
|
6
6
|
self.was_rendered = true
|
7
7
|
set_navigation_right_button "Test", action: :test, type: UIBarButtonItemStyleDone
|
8
8
|
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class SampleScreen < MotionPrime::Screen
|
12
|
+
title 'Sample'
|
13
|
+
|
14
|
+
def render
|
15
|
+
@main_section = SampleSection.new(screen: self)
|
16
|
+
@main_section.render
|
17
|
+
end
|
9
18
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-prime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Haziev
|
@@ -179,6 +179,34 @@ dependencies:
|
|
179
179
|
- - ! '>='
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: thor
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
type: :runtime
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ! '>='
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
- !ruby/object:Gem::Dependency
|
197
|
+
name: activesupport
|
198
|
+
requirement: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ! '>='
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
type: :runtime
|
204
|
+
prerelease: false
|
205
|
+
version_requirements: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ! '>='
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
182
210
|
description: RubyMotion apps development framework
|
183
211
|
email:
|
184
212
|
- gvalmon@gmail.com
|
@@ -240,14 +268,32 @@ files:
|
|
240
268
|
- files/resources/Default.png
|
241
269
|
- files/resources/Default@2x.png
|
242
270
|
- files/resources/Icon.png
|
271
|
+
- generators/generator.rb
|
272
|
+
- generators/model_generator.rb
|
273
|
+
- generators/scaffold_generator.rb
|
274
|
+
- generators/screen_generator.rb
|
275
|
+
- generators/table_generator.rb
|
276
|
+
- generators/templates/cell.rb
|
277
|
+
- generators/templates/model.rb
|
278
|
+
- generators/templates/scaffold/cell.rb
|
279
|
+
- generators/templates/scaffold/form.rb
|
280
|
+
- generators/templates/scaffold/model.rb
|
281
|
+
- generators/templates/scaffold/screen.rb
|
282
|
+
- generators/templates/scaffold/show.rb
|
283
|
+
- generators/templates/scaffold/styles.rb
|
284
|
+
- generators/templates/scaffold/table.rb
|
285
|
+
- generators/templates/screen.rb
|
286
|
+
- generators/templates/table.rb
|
243
287
|
- lib/motion-prime.rb
|
244
288
|
- motion-prime.gemspec
|
245
289
|
- motion-prime/api_client.rb
|
246
|
-
- motion-prime/app_delegate.rb
|
247
290
|
- motion-prime/config/base.rb
|
248
291
|
- motion-prime/config/config.rb
|
249
292
|
- motion-prime/core_ext/kernel.rb
|
250
293
|
- motion-prime/core_ext/time.rb
|
294
|
+
- motion-prime/delegate/_base_mixin.rb
|
295
|
+
- motion-prime/delegate/_navigation_mixin.rb
|
296
|
+
- motion-prime/delegate/app_delegate.rb
|
251
297
|
- motion-prime/elements/_content_padding_mixin.rb
|
252
298
|
- motion-prime/elements/_content_text_mixin.rb
|
253
299
|
- motion-prime/elements/_text_mixin.rb
|
@@ -357,24 +403,26 @@ files:
|
|
357
403
|
- motion-prime/views/view_styler.rb
|
358
404
|
- resources/Default-568h@2x.png
|
359
405
|
- resources/Icon.png
|
360
|
-
- spec/
|
361
|
-
- spec/delegate/delegate_spec.rb
|
406
|
+
- spec/features/screens/open_screen.rb
|
362
407
|
- spec/helpers/delegates.rb
|
363
408
|
- spec/helpers/init.rb
|
364
409
|
- spec/helpers/models.rb
|
365
410
|
- spec/helpers/screens.rb
|
366
|
-
- spec/
|
367
|
-
- spec/
|
368
|
-
- spec/
|
369
|
-
- spec/models/
|
370
|
-
- spec/models/
|
371
|
-
- spec/models/
|
372
|
-
- spec/models/
|
373
|
-
- spec/models/
|
374
|
-
- spec/models/
|
375
|
-
- spec/models/
|
376
|
-
- spec/
|
377
|
-
- spec/
|
411
|
+
- spec/helpers/sections.rb
|
412
|
+
- spec/unit/config/store_spec.rb
|
413
|
+
- spec/unit/delegate/delegate_spec.rb
|
414
|
+
- spec/unit/models/association_collection_spec.rb
|
415
|
+
- spec/unit/models/associations_spec.rb
|
416
|
+
- spec/unit/models/bag_spec.rb
|
417
|
+
- spec/unit/models/dirty_spec.rb
|
418
|
+
- spec/unit/models/errors_spec.rb
|
419
|
+
- spec/unit/models/finder_spec.rb
|
420
|
+
- spec/unit/models/json.rb
|
421
|
+
- spec/unit/models/model_spec.rb
|
422
|
+
- spec/unit/models/store_extension_spec.rb
|
423
|
+
- spec/unit/models/store_spec.rb
|
424
|
+
- spec/unit/prime/env.rb
|
425
|
+
- spec/unit/screens/screen_spec.rb
|
378
426
|
- travis.sh
|
379
427
|
homepage: ''
|
380
428
|
licenses:
|
@@ -401,21 +449,23 @@ signing_key:
|
|
401
449
|
specification_version: 4
|
402
450
|
summary: RubyMotion apps development framework
|
403
451
|
test_files:
|
404
|
-
- spec/
|
405
|
-
- spec/delegate/delegate_spec.rb
|
452
|
+
- spec/features/screens/open_screen.rb
|
406
453
|
- spec/helpers/delegates.rb
|
407
454
|
- spec/helpers/init.rb
|
408
455
|
- spec/helpers/models.rb
|
409
456
|
- spec/helpers/screens.rb
|
410
|
-
- spec/
|
411
|
-
- spec/
|
412
|
-
- spec/
|
413
|
-
- spec/models/
|
414
|
-
- spec/models/
|
415
|
-
- spec/models/
|
416
|
-
- spec/models/
|
417
|
-
- spec/models/
|
418
|
-
- spec/models/
|
419
|
-
- spec/models/
|
420
|
-
- spec/
|
421
|
-
- spec/
|
457
|
+
- spec/helpers/sections.rb
|
458
|
+
- spec/unit/config/store_spec.rb
|
459
|
+
- spec/unit/delegate/delegate_spec.rb
|
460
|
+
- spec/unit/models/association_collection_spec.rb
|
461
|
+
- spec/unit/models/associations_spec.rb
|
462
|
+
- spec/unit/models/bag_spec.rb
|
463
|
+
- spec/unit/models/dirty_spec.rb
|
464
|
+
- spec/unit/models/errors_spec.rb
|
465
|
+
- spec/unit/models/finder_spec.rb
|
466
|
+
- spec/unit/models/json.rb
|
467
|
+
- spec/unit/models/model_spec.rb
|
468
|
+
- spec/unit/models/store_extension_spec.rb
|
469
|
+
- spec/unit/models/store_spec.rb
|
470
|
+
- spec/unit/prime/env.rb
|
471
|
+
- spec/unit/screens/screen_spec.rb
|
@@ -1,92 +0,0 @@
|
|
1
|
-
motion_require './helpers/has_authorization'
|
2
|
-
motion_require './helpers/has_class_factory'
|
3
|
-
module MotionPrime
|
4
|
-
class BaseAppDelegate
|
5
|
-
include HasAuthorization
|
6
|
-
|
7
|
-
attr_accessor :window
|
8
|
-
|
9
|
-
def application(application, willFinishLaunchingWithOptions:opts)
|
10
|
-
MotionPrime::Config.configure!
|
11
|
-
MotionPrime::Styles.define!
|
12
|
-
Prime.logger.info "Loading Prime application with env: #{Prime.env}"
|
13
|
-
application.setStatusBarStyle UIStatusBarStyleLightContent
|
14
|
-
application.setStatusBarHidden false
|
15
|
-
end
|
16
|
-
|
17
|
-
def application(application, didFinishLaunchingWithOptions:launch_options)
|
18
|
-
on_load(application, launch_options)
|
19
|
-
true
|
20
|
-
end
|
21
|
-
|
22
|
-
def application(application, didRegisterForRemoteNotificationsWithDeviceToken: token)
|
23
|
-
on_apn_register_success(application, token)
|
24
|
-
end
|
25
|
-
def application(application, didFailToRegisterForRemoteNotificationsWithError: error)
|
26
|
-
on_apn_register_fail(application, error)
|
27
|
-
end
|
28
|
-
|
29
|
-
def on_load(application, launch_options)
|
30
|
-
end
|
31
|
-
|
32
|
-
def on_apn_register_success(application, token)
|
33
|
-
end
|
34
|
-
|
35
|
-
def on_apn_register_fail(application, error)
|
36
|
-
end
|
37
|
-
|
38
|
-
def app_window
|
39
|
-
self.app_delegate.window
|
40
|
-
end
|
41
|
-
|
42
|
-
def open_screen(screen, options = {})
|
43
|
-
screen = prepare_screen_for_open(screen, options)
|
44
|
-
if options[:root] || !self.window
|
45
|
-
open_root_screen(screen, options)
|
46
|
-
else
|
47
|
-
open_content_screen(screen, options)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def current_user
|
52
|
-
@current_user ||= if defined?(User) && User.respond_to?(:current)
|
53
|
-
User.current
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def reset_current_user
|
58
|
-
user_was = @current_user
|
59
|
-
@current_user = nil
|
60
|
-
NSNotificationCenter.defaultCenter.postNotificationName(:on_current_user_reset, object: user_was)
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
def prepare_screen_for_open(screen, options = {})
|
65
|
-
Screen.create_with_options(screen, true, options)
|
66
|
-
end
|
67
|
-
|
68
|
-
def open_root_screen(screen, options = {})
|
69
|
-
screen.send(:on_screen_load) if screen.respond_to?(:on_screen_load)
|
70
|
-
screen.wrap_in_navigation if screen.respond_to?(:wrap_in_navigation)
|
71
|
-
|
72
|
-
screen = screen.main_controller if screen.respond_to?(:main_controller)
|
73
|
-
|
74
|
-
self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
75
|
-
if options[:animated]
|
76
|
-
UIView.transitionWithView self.window,
|
77
|
-
duration: 0.5,
|
78
|
-
options: UIViewAnimationOptionTransitionFlipFromLeft,
|
79
|
-
animations: proc { self.window.rootViewController = screen },
|
80
|
-
completion: nil
|
81
|
-
else
|
82
|
-
self.window.rootViewController = screen
|
83
|
-
end
|
84
|
-
self.window.makeKeyAndVisible
|
85
|
-
screen
|
86
|
-
end
|
87
|
-
|
88
|
-
def open_content_screen(screen, options = {})
|
89
|
-
open_root_screen(screen)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|