motion-settings-bundle 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +87 -0
- data/Rakefile +55 -0
- data/lib/motion-settings-bundle.rb +34 -0
- data/lib/motion-settings-bundle/configuration.rb +48 -0
- data/lib/motion-settings-bundle/generator.rb +60 -0
- data/lib/motion-settings-bundle/version.rb +5 -0
- data/motion-settings-bundle.gemspec +20 -0
- data/screenshot.png +0 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012, Nick Quaranto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# motion-settings-bundle
|
2
|
+
|
3
|
+
Create a Settings.bundle for your RubyMotion app. This allows your app to have a "global" settings entry in the Settings app.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'motion-settings-bundle'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
gem install motion-settings-bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add a chunk of code into your project's `Rakefile` like so:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
require 'motion-settings-bundle'
|
25
|
+
|
26
|
+
Motion::SettingsBundle.setup do |bundle|
|
27
|
+
# A text field. Allows configuration of a string.
|
28
|
+
bundle.text "Name", key: "username", default: "Paul Atreides"
|
29
|
+
|
30
|
+
# A read-only text field. Use for showing a small chunk of text, maybe a version number
|
31
|
+
bundle.title "Year of Birth", key: "yearOfBirth", default: "10,175 AG"
|
32
|
+
|
33
|
+
# An on/off switch. Turn something on or off. Default is `false` (off).
|
34
|
+
bundle.toggle "Kwisatz Haderach?", key: "superpowersEnabled", default: true
|
35
|
+
|
36
|
+
# A slider, configure volume or something linear
|
37
|
+
bundle.slider "Spice Level", key: "spiceLevel", default: 50, min: 1, max: 100
|
38
|
+
|
39
|
+
# Jump to a screen and choose from a list of options
|
40
|
+
bundle.options "Occupation", key: "occupation" do |group|
|
41
|
+
group.option "Padishah Emperor"
|
42
|
+
group.option "Mentat", default: true
|
43
|
+
group.option "Duke of House Atreides"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Now just run `rake` as normal!
|
49
|
+
|
50
|
+
This should now add a `Settings.bundle` folder into your `resources` directory. Make sure to commit it! If you ever change the data in the `Settings.setup` block, it will be re-built on the next `rake` run. You'll end up with something like this:
|
51
|
+
|
52
|
+

|
53
|
+
|
54
|
+
If you're wondering how to access this in code, it's pretty easy:
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
NSUserDefaults.standardUserDefaults["username"]
|
58
|
+
# returns "Paul Atreides"
|
59
|
+
```
|
60
|
+
|
61
|
+
And so on. Just remember, the defaults aren't populated until your user actually opens the Settings app, so make sure to handle all of your setting entries being `nil`.
|
62
|
+
|
63
|
+
## TODO
|
64
|
+
|
65
|
+
This project really solely exists to avoid creating/editing the Settings.bundle in XCode. The specs for it so far have been based off [mordaroso/rubymotion-settings-bundle](https://github/mordaroso/rubymotion-settings-bundle). Please feel free to contribute more ways to generate settings!
|
66
|
+
|
67
|
+
* Make `options` entry work
|
68
|
+
* Add a big chunk of text, like licensing info
|
69
|
+
* Add a custom label, "Settings for Blah"
|
70
|
+
* Don't re-create files every time
|
71
|
+
* Slider default level doesn't seem to work yet
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
I couldn't figure out how to test this automatically. Run `bundle` to get the gems you need, and then `rake` to generate a RubyMotion app in the iOS simulator, and then open the Settings app.
|
76
|
+
|
77
|
+
If you've added a setting it would be really nice if you could update `screenshot.png` as well!
|
78
|
+
|
79
|
+
1. Fork it
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create new Pull Request
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
MIT. See `LICENSE`.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
desc "Test by generating an app"
|
5
|
+
task :default do
|
6
|
+
dir = "MotionSettingsTest"
|
7
|
+
`rm -rf #{dir}`
|
8
|
+
`motion create #{dir}`
|
9
|
+
Dir.chdir(dir) do
|
10
|
+
File.open("Gemfile", "w") do |f|
|
11
|
+
f.write <<-EOF
|
12
|
+
source :rubygems
|
13
|
+
gem "motion-settings-bundle", :path => ".."
|
14
|
+
EOF
|
15
|
+
end
|
16
|
+
|
17
|
+
`bundle --local`
|
18
|
+
|
19
|
+
File.open("Rakefile", "a") do |f|
|
20
|
+
f.write <<-EOF
|
21
|
+
|
22
|
+
require 'bundler'
|
23
|
+
Bundler.setup
|
24
|
+
|
25
|
+
require 'motion-settings-bundle'
|
26
|
+
|
27
|
+
Motion::SettingsBundle.setup do |app|
|
28
|
+
# A text field. Allows configuration of a string.
|
29
|
+
app.text "Name", key: "username", default: "Paul Atreides"
|
30
|
+
|
31
|
+
# A read-only text field. Use for showing a small chunk of text, maybe a version number
|
32
|
+
app.title "Year of Birth", key: "yearOfBirth", default: "10,175 AG"
|
33
|
+
|
34
|
+
# An on/off switch. Turn something on or off. Default is `false` (off).
|
35
|
+
app.toggle "Kwisatz Haderach?", key: "superpowersEnabled", default: true
|
36
|
+
|
37
|
+
# A slider, configure volume or something linear
|
38
|
+
app.slider "Spice Level", key: "spiceLevel", default: 50, min: 1, max: 100
|
39
|
+
|
40
|
+
# Jump to a screen and choose from a list of options
|
41
|
+
app.options "Occupation", key: "occupation" do |group|
|
42
|
+
group.option "Padishah Emperor"
|
43
|
+
group.option "Mentat", default: true
|
44
|
+
group.option "Duke of House Atreides"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
EOF
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "*" * 80
|
51
|
+
puts "Booting up the simulator! Jump to the Settings app once booted and open '#{dir}'."
|
52
|
+
puts "*" * 80
|
53
|
+
sh "rake"
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
require "plist"
|
8
|
+
|
9
|
+
require "motion-settings-bundle/configuration"
|
10
|
+
require "motion-settings-bundle/generator"
|
11
|
+
require "motion-settings-bundle/version"
|
12
|
+
|
13
|
+
module Motion
|
14
|
+
module SettingsBundle
|
15
|
+
class << self
|
16
|
+
attr_accessor :generator
|
17
|
+
|
18
|
+
def setup(&block)
|
19
|
+
generator.configure(Configuration.new(&block))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
self.generator = Generator.new(App.config.resources_dir)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Generate a Settings.bundle"
|
28
|
+
task :settings do
|
29
|
+
Motion::SettingsBundle.generator.generate
|
30
|
+
end
|
31
|
+
|
32
|
+
%w(build:simulator build:device).each do |build_task|
|
33
|
+
Rake::Task[build_task].enhance([:settings])
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Motion
|
2
|
+
module SettingsBundle
|
3
|
+
class Configuration
|
4
|
+
attr_reader :preferences
|
5
|
+
|
6
|
+
def initialize(&block)
|
7
|
+
@preferences = []
|
8
|
+
block.call(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def text(title, options = {})
|
12
|
+
preference(title, "PSTextFieldSpecifier", options, {
|
13
|
+
"IsSecure" => false,
|
14
|
+
"KeyboardType" => "Alphabet",
|
15
|
+
"AutoCapitalizationType" => "Sentences",
|
16
|
+
"AutocorrectionType" => "Default"
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
def title(title, options = {})
|
21
|
+
preference(title, "PSTitleValueSpecifier", options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def toggle(title, options = {})
|
25
|
+
preference(title, "PSToggleSwitchSpecifier", options, {
|
26
|
+
"TrueValue" => true,
|
27
|
+
"FalseValue" => false
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
def slider(title, options = {})
|
32
|
+
preference(title, "PSSliderSpecifier", options, {
|
33
|
+
"MinimumValue" => options[:min],
|
34
|
+
"MaximumValue" => options[:max]
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def options(title, options = {})
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def preference(title, type, options, extras = {})
|
44
|
+
@preferences << {"Title" => title, "Key" => options[:key], "DefaultValue" => options[:default], "Type" => type}.merge(extras)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Motion
|
2
|
+
module SettingsBundle
|
3
|
+
class Generator
|
4
|
+
def initialize(resources_dir)
|
5
|
+
@root_path = File.join(resources_dir, "Settings.bundle")
|
6
|
+
end
|
7
|
+
|
8
|
+
def configure(configuration)
|
9
|
+
@configuration = configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
directory @root_path
|
14
|
+
|
15
|
+
strings_path = File.join(@root_path, "en.lproj")
|
16
|
+
directory strings_path
|
17
|
+
|
18
|
+
strings_file_path = File.join(strings_path, "Root.strings")
|
19
|
+
file strings_file_path do |file|
|
20
|
+
file.write <<-EOF
|
21
|
+
/* A single strings file, whose title is specified in your preferences schema. The strings files provide the localized content to display to the user for each of your preferences. */
|
22
|
+
|
23
|
+
"Group" = "Group";
|
24
|
+
"Name" = "Name";
|
25
|
+
"none given" = "none given";
|
26
|
+
"Enabled" = "Enabled";
|
27
|
+
EOF
|
28
|
+
end
|
29
|
+
|
30
|
+
plist_file_path = File.join(@root_path, "Root.plist")
|
31
|
+
|
32
|
+
file(plist_file_path, true) do |file|
|
33
|
+
file.write({
|
34
|
+
"Title" => "Settings",
|
35
|
+
"StringsTable" => "Root",
|
36
|
+
"PreferenceSpecifiers" => @configuration.preferences
|
37
|
+
}.to_plist)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def directory(path)
|
44
|
+
unless File.exist?(path)
|
45
|
+
FileUtils.mkdir(path)
|
46
|
+
App.info "Create", path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def file(path, force = false)
|
51
|
+
if force || !File.exist?(path)
|
52
|
+
File.open(path, "w") do |file|
|
53
|
+
yield file
|
54
|
+
end
|
55
|
+
App.info "Create", path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/motion-settings-bundle/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Nick Quaranto"]
|
6
|
+
gem.email = ["nick@quaran.to"]
|
7
|
+
gem.summary = gem.description =
|
8
|
+
%{Create a Settings.bundle for your RubyMotion app. This allows your app to have a "global" settings entry in the Settings app.}
|
9
|
+
gem.homepage = "https://github.com/qrush/motion-settings-bundle"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "motion-settings-bundle"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Motion::SettingsBundle::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'plist', '~> 3.1.0'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
end
|
data/screenshot.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-settings-bundle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Quaranto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: plist
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Create a Settings.bundle for your RubyMotion app. This allows your app
|
47
|
+
to have a "global" settings entry in the Settings app.
|
48
|
+
email:
|
49
|
+
- nick@quaran.to
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/motion-settings-bundle.rb
|
60
|
+
- lib/motion-settings-bundle/configuration.rb
|
61
|
+
- lib/motion-settings-bundle/generator.rb
|
62
|
+
- lib/motion-settings-bundle/version.rb
|
63
|
+
- motion-settings-bundle.gemspec
|
64
|
+
- screenshot.png
|
65
|
+
homepage: https://github.com/qrush/motion-settings-bundle
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.23
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Create a Settings.bundle for your RubyMotion app. This allows your app to
|
89
|
+
have a "global" settings entry in the Settings app.
|
90
|
+
test_files: []
|
91
|
+
has_rdoc:
|