Skip to content

Commit

Permalink
Merge pull request #82 from venmo/marklarr/sort_by_type
Browse files Browse the repository at this point in the history
When synx'ing, also sort entries by if they are a group/file, then name.
  • Loading branch information
marklarr committed Aug 21, 2015
2 parents 2cbec47 + 9efde01 commit 0d6fc1e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
14 changes: 6 additions & 8 deletions lib/synx/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def sync(options={})
Synx::Tabber.puts "\n\n"
Synx::Tabber.puts "Syncing files that are not included in Xcode project..".bold.white
main_group.all_groups.each(&:move_entries_not_in_xcodeproj)
main_group.sort_by_name
transplant_work_project
Synx::Tabber.decrease
save
Expand Down Expand Up @@ -67,7 +68,7 @@ def root_pathname
end

def work_root_pathname
if @work_root_pathname
if @work_root_pathname
@work_root_pathname
else
@work_root_pathname = Pathname(File.join(SYNXRONIZE_DIR, root_pathname.basename.to_s))
Expand Down Expand Up @@ -111,17 +112,14 @@ def group_exclusions=(new_exclusions)

def has_object_for_pathname?(pathname)
@unmodified_project ||= Synx::Project.open(path)
@unmodified_project.objects.any? do |o|
@unmodified_project.objects.any? do |o|
begin
o.real_path.cleanpath == pathname.cleanpath
rescue
false
o.real_path.cleanpath == pathname.cleanpath
rescue
false
end
end
end

end
end



15 changes: 15 additions & 0 deletions lib/synx/xcodeproj_ext/project/object/pbx_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def sync(group)
group.sync(self)
end
sync_path
sort_by_name

Synx::Tabber.decrease
end
Expand All @@ -33,6 +34,20 @@ def excluded_from_sync?
project.group_exclusions.include?(hierarchy_path)
end

def sort_by_name
children.sort! do |x, y|
if x.isa == 'PBXGroup' && !(y.isa == 'PBXGroup')
-1
elsif !(x.isa == 'PBXGroup') && y.isa == 'PBXGroup'
1
elsif x.display_name && y.display_name
x.display_name <=> y.display_name
else
0
end
end
end

def move_entries_not_in_xcodeproj
if excluded_from_sync?
Synx::Tabber.puts "#{basename}/ (excluded)".yellow
Expand Down
27 changes: 14 additions & 13 deletions spec/synx/expected_group_structure.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Frameworks:
Products:
dummy:
FolderWithGroupNotLinked:
data.json:
Resources:
image.png:
AlreadySynced:
Core Data.xcdatamodeld:
Core Data.xcdatamodel:
Expand All @@ -17,25 +15,28 @@ dummy:
NSObject+abc.m:
Woot.h:
Woot.m:
FolderWithGroupNotLinked:
data.json:
GroupThatDoubleReferencesFile:
ManyFiles.h:
ManyFiles.m:
Supporting Files:
dummy-Prefix.pch:
en.lproj:
Localizable.strings:
dummy.h:
dummy.m:
Resources:
image.png:
SuchGroup:
Wow.h:
Wow.m:
VeryChildGroup:
Wowwww.h:
Wowwww.m:
Wow.h:
Wow.m:
Supporting Files:
Localizable.strings:
dummy-Prefix.pch:
dummy.h:
dummy.m:
dummyTests:
Other Files:
InfoPlist.strings:
Supporting Files:
dummyTests-Prefix.pch:
dummyTests-Info.plist:
dummyTests-prefix.pch:
dummyTests.m:
8 changes: 5 additions & 3 deletions spec/synx/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def except!(*keys)
describe "#sync" do

def verify_group_structure(group, expected_structure)
expected_structure.each do |object_name, object_children|
expected_structure.each_with_index do |(object_name, object_children), index|
failure_message = "expected group `#{group.basename}` to have child `#{object_name}`"
object = group.children.detect { |child| child.basename == object_name }
object = group.children[index]
expect(object.basename).to eq(object_name)
expect(group).to_not be_nil, failure_message
next if ["Products", "Frameworks"].include?(object.display_name)

if object.instance_of?(Xcodeproj::Project::Object::PBXGroup)
object_children ||= {}
Expand Down Expand Up @@ -235,4 +237,4 @@ def expected_group_structure
expect(value).to eq(expected)
end
end
end
end

0 comments on commit 0d6fc1e

Please sign in to comment.