Class: Motion::SettingsBundle::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-settings-bundle/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(resources_dir) ⇒ Generator

Returns a new instance of Generator.



4
5
6
# File 'lib/motion-settings-bundle/generator.rb', line 4

def initialize(resources_dir)
  @root_path = File.join(resources_dir, "Settings.bundle")
end

Instance Method Details

#configure(configuration) ⇒ Object



8
9
10
# File 'lib/motion-settings-bundle/generator.rb', line 8

def configure(configuration)
  @configuration = configuration
end

#generateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/motion-settings-bundle/generator.rb', line 12

def generate
  directory @root_path

  strings_path = File.join(@root_path, "en.lproj")
  directory strings_path

  strings_file_path = File.join(strings_path, "Root.strings")
  file strings_file_path do |io|
    io.write <<-EOF
/* 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. */

"Group" = "Group";
"Name" = "Name";
"none given" = "none given";
"Enabled" = "Enabled";
EOF
  end

  plist_file_path = File.join(@root_path, "Root.plist")

  file(plist_file_path, true) do |io|
    io.write({
      "Title"                => "Settings",
      "StringsTable"         => "Root",
      "PreferenceSpecifiers" => @configuration.preferences
    }.to_plist)
  end

  generate_children(@configuration.children)
end