Skip to content

Commit

Permalink
generating title based off DSL configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Sep 10, 2012
1 parent e388000 commit 2cddaa0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/motion/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@

require "plist"

require "motion/settings/configuration"
require "motion/settings/generator"
require "motion/settings/version"

module Motion
module Settings
def self.setup
class << self
attr_accessor :generator

def setup(&block)
generator.configure(Configuration.new(&block))
end
end

def self.generate
generator = Generator.new(App.config.resources_dir)
generator.generate
end
self.generator = Generator.new(App.config.resources_dir)
end
end

desc "Generate a Settings.bundle"
task :settings do
Motion::Settings.generate
Motion::Settings.generator.generate
end

%w(build:simulator build:device).each do |build_task|
Expand Down
32 changes: 32 additions & 0 deletions lib/motion/settings/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Motion
module Settings
class Configuration
attr_reader :preferences

def initialize(&block)
@preferences = []
block.call(self)
end

def text(title, options = {})
puts "Text: #{title}"
end

def title(title, options = {})
@preferences << {"Title" => title, "Key" => options[:key], "DefaultValue" => options[:default], "Type" => "PSTitleValueSpecifier"}
end

def toggle(title, options = {})
puts "Toggle: #{title}"
end

def slider(title, options = {})
puts "Slider: #{title}"
end

def group(title, options = {})
puts "Group: #{title}"
end
end
end
end
8 changes: 5 additions & 3 deletions lib/motion/settings/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def initialize(resources_dir)
@root_path = File.join(resources_dir, "Settings.bundle")
end

def configure(configuration)
@configuration = configuration
end

def generate
directory @root_path

Expand All @@ -29,9 +33,7 @@ def generate
file.write({
"Title" => "Settings",
"StringsTable" => "Root",
"PreferenceSpecifiers" => [
{"Title" => "Read Only", "Key" => "readonlykey", "DefaultValue" => "Read Only Duh", "Type" => "PSTitleValueSpecifier"}
]
"PreferenceSpecifiers" => @configuration.preferences
}.to_plist)
end
end
Expand Down

0 comments on commit 2cddaa0

Please sign in to comment.