motion-prime 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +6 -0
  3. data/Gemfile +5 -10
  4. data/Gemfile.lock +10 -7
  5. data/README.md +15 -7
  6. data/Rakefile +3 -2
  7. data/files/Gemfile +8 -1
  8. data/files/Rakefile +2 -0
  9. data/files/app/app_delegate.rb +10 -0
  10. data/files/app/config/base.rb +6 -0
  11. data/files/app/models/.gitkeep +0 -0
  12. data/files/app/screens/application_screen.rb +4 -0
  13. data/files/app/screens/help_screen.rb +5 -0
  14. data/files/app/screens/home_screen.rb +5 -0
  15. data/files/app/screens/sidebar_screen.rb +14 -0
  16. data/files/app/sections/sidebar/action.rb +5 -0
  17. data/files/app/sections/sidebar/table.rb +20 -0
  18. data/files/app/styles/sidebar.rb +38 -0
  19. data/files/resources/images/navigation/bg.png +0 -0
  20. data/files/resources/images/navigation/bg@2x.png +0 -0
  21. data/files/resources/images/navigation/button.png +0 -0
  22. data/files/resources/images/navigation/button@2x.png +0 -0
  23. data/lib/motion-prime.rb +1 -1
  24. data/motion-prime.gemspec +3 -0
  25. data/motion-prime/config/base.rb +8 -0
  26. data/motion-prime/config/config.rb +49 -0
  27. data/motion-prime/elements/draw/label.rb +1 -1
  28. data/motion-prime/models/association.rb +115 -0
  29. data/motion-prime/models/bag.rb +129 -0
  30. data/motion-prime/models/base.rb +15 -65
  31. data/motion-prime/models/errors.rb +3 -0
  32. data/motion-prime/models/finder.rb +189 -0
  33. data/motion-prime/models/json.rb +45 -0
  34. data/motion-prime/models/model.rb +118 -0
  35. data/motion-prime/models/store.rb +53 -0
  36. data/motion-prime/models/store_extension.rb +159 -0
  37. data/motion-prime/styles/{forms.rb → base.rb} +4 -0
  38. data/motion-prime/support/dm_view_controller.rb +1 -1
  39. data/motion-prime/version.rb +1 -1
  40. data/spec/config/store_spec.rb +73 -0
  41. data/spec/delegate/base_delegate_spec.rb +12 -0
  42. data/spec/helpers/base_delegate.rb +5 -0
  43. data/spec/helpers/base_screen.rb +9 -0
  44. data/spec/helpers/models.rb +53 -0
  45. data/spec/models/association_spec.rb +49 -0
  46. data/spec/models/bag_spec.rb +92 -0
  47. data/spec/models/base_model_spec.rb +158 -0
  48. data/spec/models/finder_spec.rb +183 -0
  49. data/spec/models/store_extension_spec.rb +120 -0
  50. data/spec/models/store_spec.rb +51 -0
  51. data/spec/screens/base_screen_spec.rb +77 -0
  52. metadata +84 -8
  53. data/lib/view_styler.rb +0 -141
  54. data/spec/main_spec.rb +0 -9
data/.gitignore CHANGED
@@ -14,4 +14,5 @@ nbproject
14
14
  .eprj
15
15
  .sass-cache
16
16
  .idea
17
- vendor
17
+ vendor
18
+ pkg
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: objective-c
2
+ gemfile:
3
+ - Gemfile
4
+ before_script: bundle install
5
+ script: bundle exec rake spec
6
+ bump: 5
data/Gemfile CHANGED
@@ -1,13 +1,8 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'cocoapods', '0.19.1'
4
- gem 'motion-cocoapods', '1.3.2'
5
-
6
- # ruby sugar
7
- gem 'sugarcube', '0.20.23'
8
- gem 'motion-support', '0.2.4'
9
- gem 'bubble-wrap', '1.3.0'
10
-
11
- # modelds
12
- gem 'nano-store', '0.6.3'
3
+ gem 'cocoapods', '~> 0.19.1'
4
+ gem 'motion-cocoapods', '~> 1.3.2'
5
+ gem 'motion-support', '~> 0.2.4'
6
+ gem 'sugarcube', '~> 0.20.23'
7
+ gem 'bubble-wrap', '~> 1.3.0'
13
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- motion-prime (0.1.0)
4
+ motion-prime (0.1.1)
5
5
  bubble-wrap
6
6
  cocoapods
7
7
  motion-cocoapods
@@ -47,7 +47,9 @@ GEM
47
47
  json (1.7.7)
48
48
  motion-cocoapods (1.3.2)
49
49
  cocoapods (>= 0.17.0)
50
+ motion-redgreen (0.1.0)
50
51
  motion-require (0.0.7)
52
+ motion-stump (0.3.0)
51
53
  motion-support (0.2.4)
52
54
  motion-require (>= 0.0.6)
53
55
  multi_json (1.7.7)
@@ -73,11 +75,12 @@ PLATFORMS
73
75
  ruby
74
76
 
75
77
  DEPENDENCIES
76
- bubble-wrap (= 1.3.0)
77
- cocoapods (= 0.19.1)
78
- motion-cocoapods (= 1.3.2)
78
+ bubble-wrap (~> 1.3.0)
79
+ cocoapods (~> 0.19.1)
80
+ motion-cocoapods (~> 1.3.2)
79
81
  motion-prime!
80
- motion-support (= 0.2.4)
81
- nano-store (= 0.6.3)
82
+ motion-redgreen
83
+ motion-stump
84
+ motion-support (~> 0.2.4)
82
85
  rake
83
- sugarcube (= 0.20.23)
86
+ sugarcube (~> 0.20.23)
data/README.md CHANGED
@@ -1,21 +1,29 @@
1
- # MotionPrime
1
+ # MotionPrime [![Build Status](https://travis-ci.org/droidlans/motion-prime.png)](https://travis-ci.org/clearsightstudio/ProMotion)
2
2
 
3
3
  ![Prime](https://s3-us-west-2.amazonaws.com/webmate/assets/prime.jpg)
4
4
 
5
5
  MotionPrime is yet another framework written on RubyMotion.
6
6
 
7
- The main feature of MotionPrime is one more level on UI elements: Section.
7
+ The main feature of MotionPrime is one more layer on UI elements: Section.
8
8
  "Section" is something like "Partial" in Ruby On Rails, but it's smarter and will help you build application UI.
9
9
 
10
10
  ## Getting Started
11
11
 
12
- Add this line to your application's Gemfile:
12
+ ### 1. Create MotionPrime project:
13
13
 
14
- gem 'motion-prime'
14
+ $ motion create --template=git@github.com:droidlabs/motion-prime.git myapp
15
15
 
16
- Or create MotionPrime project:
16
+ ### 2. Install gems
17
17
 
18
- $ motion create --template=git@github.com:droidlabs/motion-prime.git myapp
18
+ $ bundle
19
+
20
+ ### 3. Setup application
21
+
22
+ # edit Rakefile
23
+
24
+ ### $. Run application
25
+
26
+ $ rake
19
27
 
20
28
  ## Hello World (Sample)
21
29
 
@@ -38,7 +46,7 @@ Or create MotionPrime project:
38
46
 
39
47
  # app/sections/my_profile.rb
40
48
  class MyProfileSection < MotionPrime::BaseSection
41
- element :title, text: proc { Hello World }
49
+ element :title, text: "Hello World"
42
50
  element :avatar, image: "images/avatar.png", type: :image
43
51
  end
44
52
 
data/Rakefile CHANGED
@@ -8,14 +8,15 @@ require 'motion-cocoapods'
8
8
  Bundler.setup
9
9
  Bundler.require
10
10
  require 'motion-support'
11
- require 'nano-store'
12
11
  require 'motion-prime'
12
+ require 'motion-stump'
13
+ require 'motion-redgreen'
13
14
 
14
15
  Motion::Project::App.setup do |app|
15
16
  app.name = 'MotionPrime'
16
17
  app.pods do
17
18
  pod 'PKRevealController'
18
- pod 'NanoStore', '~> 2.6.0'
19
+ pod 'NanoStore', '~> 2.7.7'
19
20
  pod 'SDWebImage'
20
21
  pod 'SVPullToRefresh'
21
22
  pod 'MBAlertView'
data/files/Gemfile CHANGED
@@ -1,3 +1,10 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'motion-prime'
3
+ gem 'cocoapods', '~> 0.19.1'
4
+ gem 'motion-cocoapods', '~> 1.3.2'
5
+ gem 'motion-support', '~> 0.2.4'
6
+ gem 'sugarcube', '~> 0.20.23'
7
+ gem 'bubble-wrap', '~> 1.3.0'
8
+ gem 'nano-store', '~> 0.6.3'
9
+
10
+ gem 'motion-prime', :path => '../motion-prime'
data/files/Rakefile CHANGED
@@ -2,8 +2,10 @@
2
2
  $:.unshift("/Library/RubyMotion/lib")
3
3
  require 'motion/project/template/ios'
4
4
  require "rubygems"
5
+ require 'motion-cocoapods'
5
6
  require 'bundler'
6
7
  Bundler.require
8
+ require 'sugarcube-568'
7
9
  require 'motion-prime'
8
10
 
9
11
  Motion::Project::App.setup do |app|
@@ -1,4 +1,14 @@
1
1
  class AppDelegate < MotionPrime::BaseAppDelegate
2
2
  def on_load(app, options)
3
+ setup_navigation_styles
4
+ open_with_sidebar HomeScreen.new(navigation: true), SidebarScreen.new
5
+ end
6
+
7
+ def setup_navigation_styles
8
+ # set navigation bar and button backgrounds
9
+ UINavigationBar.appearance.setBackgroundImage "images/navigation/bg.png".uiimage,
10
+ forBarMetrics: UIBarMetricsDefault
11
+ UIBarButtonItem.appearance.setBackgroundImage "images/navigation/button.png".uiimage,
12
+ forState: UIControlStateNormal, barMetrics:UIBarMetricsDefault
3
13
  end
4
14
  end
@@ -0,0 +1,6 @@
1
+ APP_CONFIG = {}
2
+ APP_CONFIG[:css_color_base] = 0x3aa9b6
3
+ APP_CONFIG[:css_color_dark] = 0x41929c
4
+
5
+ # setup model's store
6
+ MotionPrime::Store.connect
File without changes
@@ -1,3 +1,7 @@
1
1
  class ApplicationScreen < MotionPrime::BaseScreen
2
+ before_load :setup_navigation
2
3
 
4
+ def setup_navigation
5
+ set_navigation_left_button 'menu', action: :show_sidebar
6
+ end
3
7
  end
@@ -0,0 +1,5 @@
1
+ class HelpScreen < ApplicationScreen
2
+ def render
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class HomeScreen < ApplicationScreen
2
+ def render
3
+
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ class SidebarScreen < MotionPrime::BaseScreen
2
+ def render
3
+ @main_section = SidebarTableSection.new()
4
+ @main_section.render(to: self)
5
+ end
6
+
7
+ def open_home
8
+ open_screen HomeScreen.new(navigation: true)
9
+ end
10
+
11
+ def open_help
12
+ open_screen HelpScreen.new(navigation: true)
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class SidebarActionSection < MotionPrime::BaseSection
2
+ container height: 43
3
+ element :title, text: proc { model[:title] }
4
+ element :arrow, type: :image
5
+ end
@@ -0,0 +1,20 @@
1
+ class SidebarTableSection < MotionPrime::TableSection
2
+ def sidebar_items
3
+ [
4
+ {title: 'Home Screen', action: :open_home},
5
+ {title: 'Help Screen', action: :open_help}
6
+ ]
7
+ end
8
+
9
+ def table_data
10
+ sidebar_items.map do |model|
11
+ SidebarActionSection.new(model: model)
12
+ end
13
+ end
14
+
15
+ def on_click(table, index)
16
+ section = data[index.row]
17
+ return false if !section || !section.model[:action]
18
+ screen.send section.model[:action].to_sym
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ MotionPrime::Styles.define :sidebar do
2
+ # navigation layout
3
+ # ----------
4
+ style :screen,
5
+ background_color: APP_CONFIG[:css_color_base],
6
+ opaque: true
7
+
8
+ style :table,
9
+ top: 0,
10
+ left: 0,
11
+ width: 320,
12
+ bottom: 0,
13
+ background_color: APP_CONFIG[:css_color_base],
14
+ separator_color: APP_CONFIG[:css_color_dark],
15
+ opaque: true
16
+
17
+ style :table_cell,
18
+ selection_style: UITableViewCellSelectionStyleNone,
19
+ opaque: true
20
+
21
+ style :action_title,
22
+ background_color: APP_CONFIG[:css_color_base],
23
+ text_color: :white,
24
+ top: 10,
25
+ width: 320,
26
+ opaque: true,
27
+ font: proc { :system.uifont(20) },
28
+ size_to_fit: true,
29
+ left: 20,
30
+ text_color: :white
31
+
32
+ style :action_arrow,
33
+ width: 9,
34
+ height: 14,
35
+ right: 50,
36
+ top: 14,
37
+ image: "images/sidebar/icons/arrow.png"
38
+ end
data/lib/motion-prime.rb CHANGED
@@ -5,7 +5,7 @@ Motion::Require.all(Dir.glob(File.expand_path('../../motion-prime/**/*.rb', __FI
5
5
  Motion::Project::App.setup do |app|
6
6
  app.pods do
7
7
  pod 'PKRevealController'
8
- pod 'NanoStore', '~> 2.6.0'
8
+ pod 'NanoStore', '~> 2.7.7'
9
9
  pod 'SDWebImage'
10
10
  pod 'SVPullToRefresh'
11
11
  pod 'MBAlertView'
data/motion-prime.gemspec CHANGED
@@ -17,6 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_development_dependency "rake"
20
+ spec.add_development_dependency("motion-stump")
21
+ spec.add_development_dependency("motion-redgreen")
22
+
20
23
  spec.add_dependency "cocoapods"
21
24
  spec.add_dependency "motion-cocoapods"
22
25
  spec.add_dependency "motion-require"
@@ -0,0 +1,8 @@
1
+ motion_require './config.rb'
2
+ MotionPrime::Config.model do |model|
3
+ if RUBYMOTION_ENV == 'test'
4
+ model.store_type = :memory
5
+ else
6
+ model.store_type = :file
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+ module MotionPrime
2
+ class Config
3
+ def initialize(attributes = {})
4
+ @attributes = attributes || {}
5
+ end
6
+
7
+ def [](key)
8
+ fetch(key.to_sym) || store(key, self.class.new)
9
+ end
10
+
11
+ def store(key, value)
12
+ @attributes[key.to_sym] = value
13
+ end
14
+ alias :[]= :store
15
+
16
+ def fetch(key)
17
+ @attributes[key.to_sym]
18
+ end
19
+
20
+ def nil?
21
+ @attributes.empty?
22
+ end
23
+ alias :blank? :nil?
24
+
25
+ def has_key?(key)
26
+ !self[key].is_a?(self.class)
27
+ end
28
+
29
+ class << self
30
+ def method_missing(name, *args, &block)
31
+ @base_config ||= self.new()
32
+ @base_config.send(name.to_sym, *args, &block)
33
+ end
34
+ end
35
+
36
+ def method_missing(name, *args, &block)
37
+ if block_given?
38
+ yield self[name]
39
+ else
40
+ name = name.to_s
41
+ if /(.+)=$/.match(name)
42
+ return store($1, args[0])
43
+ else
44
+ return self[name]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -2,7 +2,7 @@ motion_require '../draw.rb'
2
2
  module MotionPrime
3
3
  class LabelDrawElement < DrawElement
4
4
  def draw_in(rect)
5
- color = computed_options[:color] || computed_options[:text_color]
5
+ color = computed_options[:text_color]
6
6
  color.uicolor.set if color
7
7
  computed_options[:text].to_s.drawAtPoint(
8
8
  CGPointMake(computed_left, computed_top),
@@ -0,0 +1,115 @@
1
+ module MotionPrime
2
+ module ModelAssociationMethods
3
+ def _bags
4
+ @_bags ||= {}
5
+ end
6
+
7
+ def save
8
+ _bags.values.each do |bag|
9
+ bag.store = self.store
10
+ bag.save
11
+ end
12
+ super
13
+ end
14
+ end
15
+ module ModelAssociationClassMethods
16
+
17
+ # Defines bag associated with model, creates accessor for bag
18
+ #
19
+ # @param [String] name - the name of bag
20
+ # @return [Nil]
21
+ def bag(name)
22
+ define_method(name) do |*args, &block|
23
+ return _bags[name] if _bags[name]
24
+
25
+ bag_key = self.info[name]
26
+ if bag_key.nil?
27
+ bag = Bag.bag
28
+ self.info[name] = bag.key
29
+ else
30
+ bag = self.class.store.bagsWithKeysInArray([bag_key]).first
31
+ end
32
+
33
+ _bags[name] = bag
34
+ end
35
+
36
+ define_method((name + "=").to_sym) do |*args, &block|
37
+ bag = self.send(name)
38
+ case args[0]
39
+ when Bag
40
+ bag.clear
41
+ bag += args[0].saved.values
42
+ when Array
43
+ bag.clear
44
+ bag += args[0]
45
+ else
46
+ raise StoreError, "Unexpected type assigned to bags, must be an Array or MotionPrime::Bag, now: #{args[0].class}"
47
+ end
48
+ bag
49
+ end
50
+ end
51
+
52
+ # Defines has one association for model, creates accessor for association
53
+ #
54
+ # @param [String] name - the name of association
55
+ # @return [Nil]
56
+ def has_one(association_name, options = {})
57
+ bag_name = "#{association_name.pluralize}_bag"
58
+ self.bag bag_name.to_sym
59
+
60
+ self._associations ||= {}
61
+ self._associations[association_name] = options.merge(type: :one)
62
+
63
+ define_method("#{association_name}=") do |value|
64
+ self.send(bag_name).clear
65
+
66
+ self.send(:"#{bag_name}") << value
67
+ value
68
+ end
69
+ define_method("#{association_name}_attributes=") do |value|
70
+ self.send(bag_name).clear
71
+
72
+ association = association_name.classify.constantize.new
73
+ association.sync_with_attributes(value)
74
+ association.save
75
+ self.send(:"#{bag_name}") << association
76
+ association
77
+ end
78
+ define_method("#{association_name}") do
79
+ self.send(:"#{bag_name}").to_a.first
80
+ end
81
+ end
82
+
83
+ # Defines has many association for model, creates accessor for association
84
+ #
85
+ # @param [String] name - the name of association
86
+ # @return [Nil]
87
+ def has_many(association_name, options = {})
88
+ bag_name = "#{association_name}_bag"
89
+ self.bag bag_name.to_sym
90
+
91
+ self._associations ||= {}
92
+ self._associations[association_name] = options.merge(type: :many)
93
+
94
+ define_method("#{association_name}_attributes=") do |value|
95
+ self.send(bag_name).clear
96
+
97
+ association = []
98
+ value.each do |attrs|
99
+ model = association_name.classify.constantize.new
100
+ model.sync_with_attributes(attrs)
101
+ association << model
102
+ end
103
+ self.send(:"#{bag_name}=", association)
104
+ association
105
+ end
106
+ define_method("#{association_name}=") do |value|
107
+ self.send(bag_name).clear
108
+ self.send(:"#{bag_name}=", value)
109
+ end
110
+ define_method("#{association_name}") do
111
+ self.send(:"#{bag_name}").to_a
112
+ end
113
+ end
114
+ end
115
+ end