motion-prime 0.4.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +14 -6
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile.lock +1 -1
  5. data/README.md +10 -8
  6. data/ROADMAP.md +9 -10
  7. data/Rakefile +1 -1
  8. data/doc/code/getting_started.rb +3 -3
  9. data/doc/code/screens.rb +25 -10
  10. data/doc/code/sections.rb +41 -0
  11. data/doc/docs/getting_started.html +8 -3
  12. data/doc/docs/screens.html +58 -19
  13. data/doc/docs/sections.html +134 -0
  14. data/files/Gemfile +7 -1
  15. data/files/Gemfile.lock +18 -9
  16. data/files/Rakefile +2 -11
  17. data/files/app/app_delegate.rb +2 -2
  18. data/files/app/config/base.rb +0 -4
  19. data/files/app/screens/application_screen.rb +2 -2
  20. data/files/app/screens/home_screen.rb +2 -0
  21. data/files/app/screens/sidebar_screen.rb +3 -3
  22. data/files/app/sections/home/section.rb +3 -0
  23. data/files/app/sections/sidebar/action.rb +1 -1
  24. data/files/app/styles/home.rb +9 -0
  25. data/files/app/styles/sidebar.rb +3 -3
  26. data/lib/motion-prime.rb +9 -0
  27. data/motion-prime/api_client.rb +5 -1
  28. data/motion-prime/app_delegate.rb +40 -45
  29. data/motion-prime/core_ext/kernel.rb +8 -0
  30. data/motion-prime/elements/_content_text_mixin.rb +3 -1
  31. data/motion-prime/elements/_text_mixin.rb +1 -1
  32. data/motion-prime/elements/base_element.rb +6 -5
  33. data/motion-prime/elements/draw/image.rb +6 -1
  34. data/motion-prime/elements/view_with_section.rb +7 -0
  35. data/motion-prime/helpers/has_style_chain_builder.rb +4 -1
  36. data/motion-prime/models/_association_mixin.rb +139 -0
  37. data/motion-prime/models/_base_mixin.rb +184 -0
  38. data/motion-prime/models/_dirty_mixin.rb +31 -0
  39. data/motion-prime/models/_finder_mixin.rb +208 -0
  40. data/motion-prime/models/{bag.rb → _nano_bag_mixin.rb} +4 -4
  41. data/motion-prime/models/{sync.rb → _sync_mixin.rb} +75 -76
  42. data/motion-prime/models/json.rb +6 -9
  43. data/motion-prime/models/model.rb +24 -172
  44. data/motion-prime/{mp.rb → prime.rb} +0 -1
  45. data/motion-prime/screens/_base_mixin.rb +9 -10
  46. data/motion-prime/screens/_navigation_mixin.rb +12 -17
  47. data/motion-prime/screens/extensions/_indicators_mixin.rb +1 -1
  48. data/motion-prime/screens/extensions/_navigation_bar_mixin.rb +3 -3
  49. data/motion-prime/screens/{base_screen.rb → screen.rb} +11 -5
  50. data/motion-prime/sections/_cell_section_mixin.rb +13 -0
  51. data/motion-prime/sections/_draw_section_mixin.rb +17 -0
  52. data/motion-prime/sections/base_section.rb +51 -16
  53. data/motion-prime/sections/form/base_field_section.rb +27 -16
  54. data/motion-prime/sections/form/base_header_section.rb +4 -3
  55. data/motion-prime/sections/form/password_field_section.rb +4 -0
  56. data/motion-prime/sections/form/select_field_section.rb +4 -0
  57. data/motion-prime/sections/form/string_field_section.rb +4 -0
  58. data/motion-prime/sections/form/submit_field_section.rb +4 -0
  59. data/motion-prime/sections/form/text_field_section.rb +4 -0
  60. data/motion-prime/sections/form.rb +7 -1
  61. data/motion-prime/sections/tabbed.rb +1 -1
  62. data/motion-prime/sections/table/table_delegate.rb +5 -0
  63. data/motion-prime/sections/table.rb +71 -51
  64. data/motion-prime/services/logger.rb +37 -0
  65. data/motion-prime/support/mp_cell_with_section.rb +9 -4
  66. data/motion-prime/support/tab_bar_controller.rb +2 -1
  67. data/motion-prime/version.rb +1 -1
  68. data/motion-prime/views/layout.rb +1 -1
  69. data/motion-prime/views/view_builder.rb +7 -0
  70. data/motion-prime.gemspec +1 -1
  71. data/spec/delegate/{base_delegate_spec.rb → delegate_spec.rb} +1 -1
  72. data/spec/helpers/{base_delegate.rb → delegates.rb} +0 -0
  73. data/spec/helpers/models.rb +11 -18
  74. data/spec/helpers/{base_screen.rb → screens.rb} +1 -1
  75. data/spec/models/{association_spec.rb → associations_spec.rb} +1 -1
  76. data/spec/models/bag_spec.rb +1 -1
  77. data/spec/models/errors_spec.rb +1 -1
  78. data/spec/models/finder_spec.rb +1 -1
  79. data/spec/models/json.rb +87 -0
  80. data/spec/models/model_spec.rb +23 -3
  81. data/spec/models/store_extension_spec.rb +1 -1
  82. data/spec/models/store_spec.rb +1 -1
  83. data/spec/screens/{base_screen_spec.rb → screen_spec.rb} +5 -1
  84. metadata +52 -43
  85. data/motion-prime/models/association.rb +0 -134
  86. data/motion-prime/models/base.rb +0 -27
  87. data/motion-prime/models/finder.rb +0 -202
  88. data/motion-prime/screens/sidebar_container_screen.rb +0 -80
@@ -0,0 +1,134 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sections.rb</title>
6
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
7
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
8
+ <link rel="stylesheet" media="all" href="docco.css" />
9
+ </head>
10
+ <body>
11
+ <div id="container">
12
+ <div id="background"></div>
13
+
14
+ <ul id="jump_to">
15
+ <li>
16
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
17
+ <a class="small" href="javascript:void(0);">+</a>
18
+ <div id="jump_wrapper">
19
+ <div id="jump_page">
20
+
21
+
22
+ <a class="source" href="getting_started.html">
23
+ getting_started.rb
24
+ </a>
25
+
26
+
27
+ <a class="source" href="screens.html">
28
+ screens.rb
29
+ </a>
30
+
31
+
32
+ <a class="source" href="sections.html">
33
+ sections.rb
34
+ </a>
35
+
36
+ </div>
37
+ </li>
38
+ </ul>
39
+
40
+ <ul class="sections">
41
+
42
+ <li id="title">
43
+ <div class="annotation">
44
+ <h1>sections.rb</h1>
45
+ </div>
46
+ </li>
47
+
48
+
49
+
50
+ <li id="section-1">
51
+ <div class="annotation">
52
+
53
+ <div class="pilwrap ">
54
+ <a class="pilcrow" href="#section-1">&#182;</a>
55
+ </div>
56
+ <p><strong> What is a Section? </strong></p>
57
+ <p>&quot;Section&quot; is something like &quot;partial&quot; which you may know from RubyOnRails.
58
+ In the first look it&#39;s just a list of elements which will be added to the &quot;Screen&quot;.
59
+ But the magic is inside.
60
+ When you add &quot;Element&quot; to a &quot;Section&quot;, e.g. image or label,
61
+ it will try to draw it using CALayer/CGContext/etc, instead of adding new UIView.
62
+ That way increases application speed (especially on Table elements) by 5-10 times.</p>
63
+ <p>Let&#39;s get started.</p>
64
+
65
+ </div>
66
+
67
+ <div class="content"><div class='highlight'><pre>---</pre></div></div>
68
+
69
+ </li>
70
+
71
+
72
+ <li id="section-2">
73
+ <div class="annotation">
74
+
75
+ <div class="pilwrap ">
76
+ <a class="pilcrow" href="#section-2">&#182;</a>
77
+ </div>
78
+ <p><strong> Create a section. </strong></p>
79
+ <p>Just inherit it from <code>Prime::Section</code>.</p>
80
+
81
+ </div>
82
+
83
+ <div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">FooSection</span> <span class="inheritance">&lt; <span class="parent">Prime::Section</span></span></span>
84
+ <span class="keyword">end</span></pre></div></div>
85
+
86
+ </li>
87
+
88
+
89
+ <li id="section-3">
90
+ <div class="annotation">
91
+
92
+ <div class="pilwrap ">
93
+ <a class="pilcrow" href="#section-3">&#182;</a>
94
+ </div>
95
+ <p><strong> Add some elements to the section. </strong></p>
96
+ <p>Each element should have name and type: &quot;image&quot;, &quot;label&quot;, &quot;button&quot;, etc.
97
+ When you send <code>:text</code> option, type will be &quot;label&quot; by default.
98
+ When you send <code>:image</code> option, type will be &quot;image&quot; by default.</p>
99
+
100
+ </div>
101
+
102
+ <div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">FooSection</span> <span class="inheritance">&lt; <span class="parent">Prime::Section</span></span></span>
103
+ element <span class="symbol">:welcome</span>, <span class="symbol">text:</span> <span class="string">'Hello World!'</span>
104
+ element <span class="symbol">:avatar</span>, <span class="symbol">image:</span> <span class="string">'images/users/avatar.jpg'</span>
105
+ element <span class="symbol">:cheer</span>, <span class="symbol">type:</span> <span class="symbol">:button</span>
106
+ <span class="keyword">end</span></pre></div></div>
107
+
108
+ </li>
109
+
110
+
111
+ <li id="section-4">
112
+ <div class="annotation">
113
+
114
+ <div class="pilwrap ">
115
+ <a class="pilcrow" href="#section-4">&#182;</a>
116
+ </div>
117
+ <p><strong> Render Section in Screen </strong></p>
118
+ <p>NOTE: You must send &quot;screen&quot; option on section initialization.</p>
119
+
120
+ </div>
121
+
122
+ <div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">FooScreen</span> <span class="inheritance">&lt; <span class="parent">Prime::Screen</span></span></span>
123
+ <span class="function"><span class="keyword">def</span> <span class="title">render</span></span>
124
+ <span class="variable">@main_section</span> = <span class="constant">FooSection</span>.new(<span class="symbol">screen:</span> <span class="keyword">self</span>)
125
+ <span class="variable">@main_section</span>.render
126
+ <span class="keyword">end</span>
127
+ <span class="keyword">end</span></pre></div></div>
128
+
129
+ </li>
130
+
131
+ </ul>
132
+ </div>
133
+ </body>
134
+ </html>
data/files/Gemfile CHANGED
@@ -5,4 +5,10 @@ gem 'motion-support', '~> 0.2.4'
5
5
  gem 'sugarcube', '~> 1.3.7', require: 'sugarcube-classic'
6
6
  gem 'bubble-wrap', '~> 1.3.0'
7
7
 
8
- gem 'motion-prime', '~> 0.4.4'
8
+ gem 'motion-prime', '~> 0.5.0.beta', path: '../'
9
+
10
+ # add reside menu for sidebar support
11
+ gem 'prime_reside_menu', '~> 0.1.0'
12
+
13
+ # or add sliding menu for sidebar support
14
+ # gem 'prime_sliding_menu', '~> 0.1.0'
data/files/Gemfile.lock CHANGED
@@ -1,3 +1,15 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ motion-prime (0.5.0.beta)
5
+ bubble-wrap
6
+ cocoapods
7
+ methadone
8
+ motion-cocoapods
9
+ motion-require
10
+ motion-support
11
+ sugarcube
12
+
1
13
  GEM
2
14
  remote: http://rubygems.org/
3
15
  specs:
@@ -32,20 +44,16 @@ GEM
32
44
  bundler
33
45
  motion-cocoapods (1.4.0)
34
46
  cocoapods (>= 0.26.2)
35
- motion-prime (0.4.4)
36
- bubble-wrap
37
- cocoapods
38
- methadone
39
- motion-cocoapods
40
- motion-require
41
- motion-support
42
- sugarcube
43
47
  motion-require (0.0.7)
44
48
  motion-support (0.2.5)
45
49
  motion-require (>= 0.0.6)
46
50
  multi_json (1.8.2)
47
51
  nap (0.6.0)
48
52
  open4 (1.3.0)
53
+ prime_reside_menu (0.1.0)
54
+ cocoapods
55
+ motion-cocoapods
56
+ motion-require
49
57
  rake (10.1.1)
50
58
  sugarcube (1.3.11)
51
59
  xcodeproj (0.14.1)
@@ -59,6 +67,7 @@ PLATFORMS
59
67
  DEPENDENCIES
60
68
  bubble-wrap (~> 1.3.0)
61
69
  motion-cocoapods (~> 1.4.0)
62
- motion-prime (~> 0.4.4)
70
+ motion-prime (~> 0.5.0.beta)!
63
71
  motion-support (~> 0.2.4)
72
+ prime_reside_menu (~> 0.1.0)
64
73
  sugarcube (~> 1.3.7)
data/files/Rakefile CHANGED
@@ -6,21 +6,12 @@ require 'motion-cocoapods'
6
6
  require 'bundler'
7
7
  Bundler.require
8
8
  require 'sugarcube-common'
9
+ require 'bubble-wrap/reactor'
9
10
  require 'motion-prime'
10
11
 
11
12
  Motion::Project::App.setup do |app|
12
13
  # Use `rake config' to see complete project settings.
13
- app.name = 'MotionPrimeProject'
14
-
15
- app.pods do
16
- pod 'NanoStore', '~> 2.7.7'
17
- pod 'SDWebImage'
18
- pod 'SVPullToRefresh'
19
- pod 'MBAlertView'
20
- pod 'SDSegmentedControl'
21
- pod 'RESideMenu', git: 'https://github.com/feklistov/RESideMenu.git'
22
- pod 'MBProgressHUD'
23
- end
14
+ app.name = 'Prime Project'
24
15
 
25
16
  app.version = '0.0.1'
26
17
  app.icons = %w{Icon.png}
@@ -1,7 +1,7 @@
1
1
  class AppDelegate < Prime::BaseAppDelegate
2
2
  def on_load(app, options)
3
3
  setup_navigation_styles
4
- open_screen HomeScreen.new(navigation: true), sidebar: SidebarScreen.new
4
+ open_screen HomeScreen.new, sidebar: SidebarScreen.new(navigation: false)
5
5
  end
6
6
 
7
7
  def setup_navigation_styles
@@ -9,7 +9,7 @@ class AppDelegate < Prime::BaseAppDelegate
9
9
  bar_appearance.barTintColor = Prime::Config.color.dark.uicolor
10
10
 
11
11
  settings = {
12
- UITextAttributeFont => MP::Config.font.name.uifont(17),
12
+ UITextAttributeFont => Prime::Config.font.name.uifont(17),
13
13
  UITextAttributeTextColor => :white.uicolor
14
14
  }
15
15
  bar_appearance.setTitleTextAttributes(settings)
@@ -9,10 +9,6 @@ Prime::Config.api do |api|
9
9
  api.client_secret = ""
10
10
  end
11
11
 
12
- Prime::Config.sidebar do |sidebar|
13
- sidebar.background_image = "images/sidebar/bg.jpg".uiimage
14
- end
15
-
16
12
  Prime::Config.font.name = "Ubuntu"
17
13
 
18
14
  # setup model's store
@@ -1,7 +1,7 @@
1
- class ApplicationScreen < Prime::BaseScreen
1
+ class ApplicationScreen < Prime::Screen
2
2
  before_load :setup_navigation
3
3
 
4
4
  def setup_navigation
5
- set_navigation_left_button 'menu', image: 'images/menu_button.png', action: :show_sidebar
5
+ set_navigation_left_button 'menu', image: 'images/menu_button.png', action: :toggle_sidebar
6
6
  end
7
7
  end
@@ -2,5 +2,7 @@ class HomeScreen < ApplicationScreen
2
2
  title 'Home'
3
3
 
4
4
  def render
5
+ @main_section = HomeSection.new(screen: self)
6
+ @main_section.render
5
7
  end
6
8
  end
@@ -1,14 +1,14 @@
1
- class SidebarScreen < Prime::BaseScreen
1
+ class SidebarScreen < Prime::Screen
2
2
  def render
3
3
  @main_section = SidebarTableSection.new(screen: self)
4
4
  @main_section.render
5
5
  end
6
6
 
7
7
  def open_home
8
- open_screen HomeScreen.new(navigation: true)
8
+ app_delegate.open_screen HomeScreen.new
9
9
  end
10
10
 
11
11
  def open_help
12
- open_screen HelpScreen.new(navigation: true)
12
+ app_delegate.open_screen HelpScreen.new
13
13
  end
14
14
  end
@@ -0,0 +1,3 @@
1
+ class HomeSection < Prime::Section
2
+ element :date, text: proc { Time.now.strftime("%A, %B %d") }
3
+ end
@@ -1,4 +1,4 @@
1
- class SidebarActionSection < Prime::BaseSection
1
+ class SidebarActionSection < Prime::Section
2
2
  container height: 43
3
3
  element :title, text: proc { model[:title] }
4
4
  element :arrow, type: :image
@@ -0,0 +1,9 @@
1
+ Prime::Styles.define :home do
2
+ style :date,
3
+ text_color: :black,
4
+ top: 100,
5
+ width: 320,
6
+ font: proc { :system.uifont(20) },
7
+ size_to_fit: true,
8
+ left: 20,
9
+ end
@@ -1,6 +1,7 @@
1
1
  Prime::Styles.define :sidebar do
2
2
  style :screen,
3
3
  background_color: proc { Prime::Config.color.dark }
4
+
4
5
  style :table,
5
6
  top: 150,
6
7
  left: 0,
@@ -14,10 +15,9 @@ Prime::Styles.define :sidebar do
14
15
 
15
16
  style :action_title,
16
17
  text_color: :white,
18
+ left: 20,
17
19
  top: 10,
18
20
  width: 320,
19
21
  font: proc { :system.uifont(20) },
20
- size_to_fit: true,
21
- left: 20,
22
- text_color: :white
22
+ size_to_fit: true
23
23
  end
data/lib/motion-prime.rb CHANGED
@@ -4,4 +4,13 @@ Motion::Require.all(Dir.glob(File.expand_path('../../motion-prime/**/*.rb', __FI
4
4
 
5
5
  Motion::Project::App.setup do |app|
6
6
  app.detect_dependencies = false
7
+
8
+ app.pods do
9
+ pod 'NanoStore', '~> 2.7.7'
10
+ pod 'SDWebImage'
11
+ pod 'SVPullToRefresh'
12
+ pod 'MBAlertView'
13
+ pod 'SDSegmentedControl'
14
+ pod 'MBProgressHUD'
15
+ end
7
16
  end
@@ -6,7 +6,7 @@ class ApiClient
6
6
  end
7
7
 
8
8
  def parse_json(text)
9
- BW::JSON.parse(text)
9
+ Prime::JSON.parse(text)
10
10
  rescue
11
11
  NSLog("Can't parse json: #{text}")
12
12
  false
@@ -51,6 +51,10 @@ class ApiClient
51
51
  "#{MotionPrime::Config.api.base}/api/v1#{path}"
52
52
  end
53
53
 
54
+ def page_url(path)
55
+ "#{MotionPrime::Config.api.base}/#{path}"
56
+ end
57
+
54
58
  def resource_url(path)
55
59
  # return if path.blank?
56
60
  base = Prime::Config.api.resource_base.present? ? Prime::Config.api.resource_base : Prime::Config.api.base
@@ -1,9 +1,10 @@
1
1
  motion_require './helpers/has_authorization'
2
+ motion_require './helpers/has_class_factory'
2
3
  module MotionPrime
3
4
  class BaseAppDelegate
4
- include MotionPrime::HasAuthorization
5
+ include HasAuthorization
5
6
 
6
- attr_accessor :window, :sidebar_container
7
+ attr_accessor :window
7
8
 
8
9
  def application(application, willFinishLaunchingWithOptions:opts)
9
10
  application.setStatusBarStyle UIStatusBarStyleLightContent
@@ -15,60 +16,33 @@ module MotionPrime
15
16
  true
16
17
  end
17
18
 
18
- def app_window
19
- self.app_delegate.window
19
+ def application(application, didRegisterForRemoteNotificationsWithDeviceToken: token)
20
+ on_apn_register_success(application, token)
20
21
  end
21
-
22
- def open_screen(screen, options = {})
23
- screen = create_tab_bar(screen) if screen.is_a?(Array)
24
- if options[:sidebar]
25
- open_with_sidebar(screen, options.delete(:sidebar), options)
26
- elsif options[:root] || !self.window
27
- open_root_screen(screen)
28
- else
29
- open_content_screen(screen)
30
- end
22
+ def application(application, didFailToRegisterForRemoteNotificationsWithError: error)
23
+ on_apn_register_fail(application, error)
31
24
  end
32
25
 
33
- # TODO: move to private methods
34
- def open_root_screen(screen)
35
- screen.send(:on_screen_load) if screen.respond_to?(:on_screen_load)
36
- screen.wrap_in_navigation if screen.respond_to?(:wrap_in_navigation)
37
-
38
- screen = screen.main_controller if screen.respond_to?(:main_controller)
39
-
40
- self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
41
- self.window.rootViewController = screen
42
- self.window.makeKeyAndVisible
43
- screen
44
- end
45
-
46
- # TODO: move to private methods
47
- def open_content_screen(screen)
48
- if sidebar?
49
- sidebar_container.content_controller = screen
50
- else
51
- open_root_screen(screen)
52
- end
26
+ def on_load(application, launch_options)
53
27
  end
54
28
 
55
- # TODO: move to private methods
56
- def open_with_sidebar(content, sidebar, options={})
57
- self.sidebar_container = SidebarContainerScreen.new(sidebar, content, options)
58
- self.sidebar_container.delegate = self
59
- open_root_screen(sidebar_container)
29
+ def on_apn_register_success(application, token)
60
30
  end
61
31
 
62
- def sidebar?
63
- self.window && self.window.rootViewController.is_a?(SidebarContainerScreen)
32
+ def on_apn_register_fail(application, error)
64
33
  end
65
34
 
66
- def show_sidebar
67
- sidebar_container.show_sidebar
35
+ def app_window
36
+ self.app_delegate.window
68
37
  end
69
38
 
70
- def hide_sidebar
71
- sidebar_container.hide_sidebar
39
+ def open_screen(screen, options = {})
40
+ screen = prepare_screen_for_open(screen, options)
41
+ if options[:root] || !self.window
42
+ open_root_screen(screen)
43
+ else
44
+ open_content_screen(screen)
45
+ end
72
46
  end
73
47
 
74
48
  def current_user
@@ -84,6 +58,27 @@ module MotionPrime
84
58
  end
85
59
 
86
60
  private
61
+ def prepare_screen_for_open(screen, options = {})
62
+ screen = create_tab_bar(screen) if screen.is_a?(Array)
63
+ Screen.create_with_options(screen, true, options)
64
+ end
65
+
66
+ def open_root_screen(screen, options = {})
67
+ screen.send(:on_screen_load) if screen.respond_to?(:on_screen_load)
68
+ screen.wrap_in_navigation if screen.respond_to?(:wrap_in_navigation)
69
+
70
+ screen = screen.main_controller if screen.respond_to?(:main_controller)
71
+
72
+ self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
73
+ self.window.rootViewController = screen
74
+ self.window.makeKeyAndVisible
75
+ screen
76
+ end
77
+
78
+ def open_content_screen(screen, options = {})
79
+ open_root_screen(screen)
80
+ end
81
+
87
82
  def create_tab_bar(screens)
88
83
  MotionPrime::TabBarController.new(screens)
89
84
  end
@@ -10,4 +10,12 @@ class Kernel
10
10
  def weak_ref
11
11
  WeakRef.new(self)
12
12
  end
13
+
14
+ def clear_instance_variables(options = {})
15
+ ivars = self.instance_variables.clone
16
+ ivars.each do |ivar|
17
+ next if Array.wrap(options[:except]).include?(ivar[1..-1])
18
+ self.instance_variable_set(ivar, nil)
19
+ end
20
+ end
13
21
  end
@@ -70,8 +70,10 @@ module MotionPrime
70
70
  input_value_text.blank? ? input_placeholder_text : input_value_text
71
71
  end
72
72
 
73
+ # TODO: normalize_object will not be required after refactoring computed options.
73
74
  def input_content_font
74
- input_value_text.blank? ? computed_options[:placeholder_font] : computed_options[:font]
75
+ font = input_value_text.blank? ? computed_options[:placeholder_font] : computed_options[:font]
76
+ normalize_object(font, section || self)
75
77
  end
76
78
 
77
79
  def input_value_text
@@ -42,7 +42,7 @@ module MotionPrime
42
42
  attributes[NSForegroundColorAttributeName] = options[:text_color]
43
43
  attributes[NSFontAttributeName] = options[:font]
44
44
 
45
- prepared_text = NSMutableAttributedString.alloc.initWithString(options[:text], attributes: attributes)
45
+ prepared_text = NSMutableAttributedString.alloc.initWithString(options[:text] || '', attributes: attributes)
46
46
  if underline_range = options[:underline]
47
47
  # FIXME
48
48
  # prepared_text = NSMutableAttributedString.alloc.initWithAttributedString(prepared_text)
@@ -28,10 +28,10 @@ module MotionPrime
28
28
  @view_name = self.class_name_without_kvo.demodulize.underscore.gsub(/(_draw)?_element/, '')
29
29
  end
30
30
 
31
- # def dealloc
32
- # pp 'deallocating elemenet', self.name, self.to_s, section.to_s
33
- # super
34
- # end
31
+ def dealloc
32
+ # pp 'deallocating elemenet', self.name, self.to_s, view_class, view.try(:to_s)
33
+ super
34
+ end
35
35
 
36
36
  def add_target(target = nil, action = 'on_click:', event = :touch)
37
37
  return false unless self.view
@@ -153,7 +153,8 @@ module MotionPrime
153
153
  # table element: categories_table_cell_icon, categories_table_title_icon
154
154
  @styles += build_styles_chain(base_styles[:specific], suffixes[:specific])
155
155
  end
156
- if section && section.name.present? && name.present?
156
+ # don't use present? here, it's slower, while this method should be very fast
157
+ if section && section.name && section.name != '' && name && name != ''
157
158
  # using for base sections
158
159
  @styles << [section.name, name].join('_').to_sym
159
160
  end
@@ -4,6 +4,11 @@ module MotionPrime
4
4
  include DrawBackgroundMixin
5
5
  attr_accessor :image_data
6
6
 
7
+ def dealloc
8
+ @break_async_block = true
9
+ super
10
+ end
11
+
7
12
  def draw_options
8
13
  image = image_data || computed_options[:image]
9
14
  image ||= computed_options[:default] if computed_options[:url]
@@ -72,7 +77,7 @@ module MotionPrime
72
77
  options: 0,
73
78
  progress: lambda{ |r_size, e_size| },
74
79
  completed: lambda{ |image, error, type, finished|
75
- break unless image && section
80
+ break if @break_async_block || !image
76
81
  self.image_data = image
77
82
 
78
83
  section.cached_draw_image = nil
@@ -0,0 +1,7 @@
1
+ module MotionPrime
2
+ class ViewWithSectionElement < BaseElement
3
+ def view_class
4
+ "MPViewWithSection"
5
+ end
6
+ end
7
+ end
@@ -5,7 +5,10 @@ module MotionPrime
5
5
  [*base_styles].each do |base_style|
6
6
  [*suffixes].each do |suffix|
7
7
  components = []
8
- styles << [base_style.to_s, suffix.to_s].join('_').to_sym if base_style.present? && suffix.present?
8
+ # don't use present? here, it's slower, while this method should be very fast
9
+ if base_style && base_style != '' && suffix && suffix != ''
10
+ styles << [base_style.to_s, suffix.to_s].join('_').to_sym
11
+ end
9
12
  end
10
13
  end
11
14
  styles