Class: TMBundle
- Inherits:
-
Object
- Object
- TMBundle
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/tm_bundle.rb,
lib/tm_bundle/item.rb,
lib/tm_bundle/menu.rb
Defined Under Namespace
Classes: Action, Command, Macro, Menu, Snippet
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#data ⇒ Object
Returns the value of attribute data.
-
#menu ⇒ Object
Returns the value of attribute menu.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #fill_missing_menu_names! ⇒ Object
- #fix_names! ⇒ Object
-
#initialize(path = nil) ⇒ TMBundle
constructor
A new instance of TMBundle.
- #locate_actions ⇒ Object
- #menu_export!(prefix) ⇒ Object
- #process_xml_output(xml) ⇒ Object
- #save_plist!(type = :default) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ TMBundle
Returns a new instance of TMBundle.
47 48 49 50 51 52 53 54 55 |
# File 'lib/tm_bundle.rb', line 47 def initialize(path = nil) self.path = path ? Pathname.new(path) : Pathname.pwd self.data = Plutil.load_json(@path/'info.plist') self. = Menu.new(data['mainMenu'], @path) self.actions = [] locate_actions # menu.write_yaml_hierarchy! end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
45 46 47 |
# File 'lib/tm_bundle.rb', line 45 def actions @actions end |
#data ⇒ Object
Returns the value of attribute data.
45 46 47 |
# File 'lib/tm_bundle.rb', line 45 def data @data end |
#menu ⇒ Object
Returns the value of attribute menu.
45 46 47 |
# File 'lib/tm_bundle.rb', line 45 def @menu end |
#path ⇒ Object
Returns the value of attribute path.
45 46 47 |
# File 'lib/tm_bundle.rb', line 45 def path @path end |
Instance Method Details
#fill_missing_menu_names! ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/tm_bundle.rb', line 74 def actions.each do |action| if item = .uuids[action.uuid] item.name ||= action.name else Menu.find_or_create_new_item(action.uuid, 0, name: action.name) end end end |
#fix_names! ⇒ Object
68 69 70 71 72 |
# File 'lib/tm_bundle.rb', line 68 def fix_names! actions.select(&:unmatching_path?).each do |action| action.path.rename(action.path.dirname/action.expected_path) end end |
#locate_actions ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tm_bundle.rb', line 57 def locate_actions Pathname.glob("#{path}/{Commands,Snippets,Macros}/*.{plist,tm{Command,Snippet}}") .group_by {|p| p.dirname.basename.to_s } .each do |group, files| # p group.downcase.to_sym, actions files.each do |pathname| actions << TMBundle.const_get(group.singularize.to_sym).new(pathname) end end end |
#menu_export!(prefix) ⇒ Object
84 85 86 87 |
# File 'lib/tm_bundle.rb', line 84 def (prefix) .write_yaml_hierarchy!(prefix && "-#{prefix}") end |
#process_xml_output(xml) ⇒ Object
102 103 104 105 106 |
# File 'lib/tm_bundle.rb', line 102 def process_xml_output(xml) xml.lines[3...-1] .join .gsub(/(?<=$\n|\t)\t/, "\n\t" => "\n", "\t" => " ") end |
#save_plist!(type = :default) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tm_bundle.rb', line 89 def save_plist!(type = :default) file = case type when :last then Pathname.glob((path/"menu-*.yml").to_s).last when String then path/"menu-#{type}.yml" else path/"menu.yml" end hash = .read_yaml_hieararchy! file xml = process_xml_output Plutil::JSON.dump(hash) puts Plutil.replace(@path/'info.plist', 'mainMenu', xml, &:read) end |