motion-settings-bundle 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,24 +23,27 @@ Add a chunk of code into your project's `Rakefile` like so:
23
23
  ``` ruby
24
24
  require 'motion-settings-bundle'
25
25
 
26
- Motion::SettingsBundle.setup do |bundle|
26
+ Motion::SettingsBundle.setup do |app|
27
27
  # A text field. Allows configuration of a string.
28
- bundle.text "Name", key: "username", default: "Paul Atreides"
28
+ app.text "Name", key: "username", default: "Paul Atreides"
29
+ app.text "E-mail", key: "email", keyboard: "EmailAddress", autocapitalization: "None"
30
+ app.text "Password", key: "password", secure: true
29
31
 
30
32
  # 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"
33
+ app.title "Year of Birth", key: "yearOfBirth", default: "10,175 AG"
32
34
 
33
35
  # An on/off switch. Turn something on or off. Default is `false` (off).
34
- bundle.toggle "Kwisatz Haderach?", key: "superpowersEnabled", default: true
36
+ app.toggle "Kwisatz Haderach?", key: "superpowersEnabled", default: true
35
37
 
36
38
  # 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"
39
+ app.slider "Spice Level", key: "spiceLevel", default: 50, min: 1, max: 100
40
+
41
+ # Child pane to display licenses in
42
+ app.child "Acknowledgements" do |ack|
43
+ ack.child "AwesomeOSSLibrary" do |lic|
44
+ lic.group "Copyright 2013 AwesomeOSSContributor"
45
+ lic.group "More license text that is terribly formatted but fulfills legal requirements"
46
+ end
44
47
  end
45
48
  end
46
49
  ```
data/Rakefile CHANGED
@@ -27,6 +27,8 @@ require 'motion-settings-bundle'
27
27
  Motion::SettingsBundle.setup do |app|
28
28
  # A text field. Allows configuration of a string.
29
29
  app.text "Name", key: "username", default: "Paul Atreides"
30
+ app.text "E-mail", key: "email", keyboard: "EmailAddress", autocapitalization: "None"
31
+ app.text "Password", key: "password", secure: true
30
32
 
31
33
  # A read-only text field. Use for showing a small chunk of text, maybe a version number
32
34
  app.title "Year of Birth", key: "yearOfBirth", default: "10,175 AG"
@@ -37,11 +39,12 @@ Motion::SettingsBundle.setup do |app|
37
39
  # A slider, configure volume or something linear
38
40
  app.slider "Spice Level", key: "spiceLevel", default: 50, min: 1, max: 100
39
41
 
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"
42
+ # Child pane to display licenses in
43
+ app.child "Acknowledgements" do |ack|
44
+ ack.child "AwesomeOSSLibrary" do |lic|
45
+ lic.group "Copyright 2013 AwesomeOSSContributor"
46
+ lic.group "More license text that is terribly formatted but fulfills legal requirements"
47
+ end
45
48
  end
46
49
  end
47
50
  EOF
@@ -1,19 +1,20 @@
1
1
  module Motion
2
2
  module SettingsBundle
3
3
  class Configuration
4
- attr_reader :preferences
4
+ attr_reader :preferences, :children
5
5
 
6
6
  def initialize(&block)
7
7
  @preferences = []
8
+ @children = {}
8
9
  block.call(self)
9
10
  end
10
11
 
11
12
  def text(title, options = {})
12
13
  preference(title, "PSTextFieldSpecifier", options, {
13
- "IsSecure" => false,
14
- "KeyboardType" => "Alphabet",
15
- "AutoCapitalizationType" => "Sentences",
16
- "AutocorrectionType" => "Default"
14
+ "IsSecure" => options[:secure] || false,
15
+ "KeyboardType" => options[:keyboard] || "Alphabet",
16
+ "AutocapitalizationType" => options[:autocapitalization] || "Sentences",
17
+ "AutocorrectionType" => options[:autocorrection] || "Default"
17
18
  })
18
19
  end
19
20
 
@@ -35,7 +36,15 @@ module Motion
35
36
  })
36
37
  end
37
38
 
38
- def options(title, options = {})
39
+ def group(title, options = {})
40
+ group = {"Title" => title, "Type" => "PSGroupSpecifier"}
41
+ group["FooterText"] = options[:footer] if options[:footer]
42
+ @preferences << group
43
+ end
44
+
45
+ def child(title, options = {}, &block)
46
+ @preferences << {"Title" => title, "File" => title, "Type" => "PSChildPaneSpecifier"}.merge(options)
47
+ @children[title] = Configuration.new(&block)
39
48
  end
40
49
 
41
50
  private
@@ -16,8 +16,8 @@ module Motion
16
16
  directory strings_path
17
17
 
18
18
  strings_file_path = File.join(strings_path, "Root.strings")
19
- file strings_file_path do |file|
20
- file.write <<-EOF
19
+ file strings_file_path do |io|
20
+ io.write <<-EOF
21
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
22
 
23
23
  "Group" = "Group";
@@ -29,17 +29,33 @@ EOF
29
29
 
30
30
  plist_file_path = File.join(@root_path, "Root.plist")
31
31
 
32
- file(plist_file_path, true) do |file|
33
- file.write({
32
+ file(plist_file_path, true) do |io|
33
+ io.write({
34
34
  "Title" => "Settings",
35
35
  "StringsTable" => "Root",
36
36
  "PreferenceSpecifiers" => @configuration.preferences
37
37
  }.to_plist)
38
38
  end
39
+
40
+ generate_children(@configuration.children)
39
41
  end
40
42
 
41
43
  private
42
44
 
45
+ def generate_children(children)
46
+ children.each do |title, child|
47
+ file(File.join(@root_path, "#{title}.plist"), true) do |io|
48
+ io.write({
49
+ "Title" => title,
50
+ "StringsTable" => title,
51
+ "PreferenceSpecifiers" => child.preferences
52
+ }.to_plist)
53
+ end
54
+
55
+ generate_children(child.children)
56
+ end
57
+ end
58
+
43
59
  def directory(path)
44
60
  unless File.exist?(path)
45
61
  FileUtils.mkdir(path)
@@ -49,8 +65,8 @@ EOF
49
65
 
50
66
  def file(path, force = false)
51
67
  if force || !File.exist?(path)
52
- File.open(path, "w") do |file|
53
- yield file
68
+ File.open(path, "w") do |io|
69
+ yield io
54
70
  end
55
71
  App.info "Create", path
56
72
  end
@@ -1,5 +1,5 @@
1
1
  module Motion
2
2
  module SettingsBundle
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-settings-bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-10 00:00:00.000000000 Z
12
+ date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plist
@@ -88,4 +88,3 @@ specification_version: 3
88
88
  summary: Create a Settings.bundle for your RubyMotion app. This allows your app to
89
89
  have a "global" settings entry in the Settings app.
90
90
  test_files: []
91
- has_rdoc: