ovaltine 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +17 -0
  3. data/CHANGELOG.md +3 -0
  4. data/LICENSE +22 -0
  5. data/README.md +15 -0
  6. data/Rakefile +5 -0
  7. data/TODO.md +6 -0
  8. data/bin/ovaltine +54 -0
  9. data/features/fixtures/Sample/Sample/Base.lproj/Main.storyboard +125 -0
  10. data/features/fixtures/Sample/Sample/DMMAppDelegate.h +15 -0
  11. data/features/fixtures/Sample/Sample/DMMAppDelegate.m +46 -0
  12. data/features/fixtures/Sample/Sample/DMMViewController.h +13 -0
  13. data/features/fixtures/Sample/Sample/DMMViewController.m +29 -0
  14. data/features/fixtures/Sample/Sample/Images.xcassets/AppIcon.appiconset/Contents.json +23 -0
  15. data/features/fixtures/Sample/Sample/Images.xcassets/LaunchImage.launchimage/Contents.json +23 -0
  16. data/features/fixtures/Sample/Sample/Sample-Info.plist +40 -0
  17. data/features/fixtures/Sample/Sample/Sample-Prefix.pch +16 -0
  18. data/features/fixtures/Sample/Sample/en.lproj/InfoPlist.strings +2 -0
  19. data/features/fixtures/Sample/Sample/main.m +18 -0
  20. data/features/fixtures/Sample/Sample.xcodeproj/project.pbxproj +472 -0
  21. data/features/fixtures/Sample/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  22. data/features/fixtures/Sample/SampleTests/SampleTests-Info.plist +22 -0
  23. data/features/fixtures/Sample/SampleTests/SampleTests.m +34 -0
  24. data/features/fixtures/Sample/SampleTests/en.lproj/InfoPlist.strings +2 -0
  25. data/lib/ovaltine/objc/storyboard_formatter.rb +139 -0
  26. data/lib/ovaltine/objc/storyboard_templates.rb +59 -0
  27. data/lib/ovaltine/storyboard.rb +51 -0
  28. data/lib/ovaltine/version.rb +3 -0
  29. data/lib/ovaltine.rb +51 -0
  30. data/ovaltine.gemspec +28 -0
  31. data/specs/storyboard_formatter_spec.rb +29 -0
  32. data/specs/storyboard_spec.rb +36 -0
  33. metadata +134 -0
@@ -0,0 +1,59 @@
1
+
2
+ module Ovaltine
3
+ class StoryboardTemplates
4
+
5
+ VIEW_CONTROLLER_DEFINITION_TEMPLATE='+(UIViewController *)instantiate{IDENTIFIER};'
6
+ VIEW_CONTROLLER_IMPLEMENTATION_TEMPLATE='+(UIViewController *)instantiate{CAPITALIZED_IDENTIFIER} { return [[self storyboard] instantiateViewControllerWithIdentifier:{IDENTIFIER}]; }'
7
+
8
+ STATIC_IDENTIFIER_TEMPLATE='static NSString *const {IDENTIFIER_CONSTANT_NAME} = @"{IDENTIFIER}";'
9
+ SEGUE_DEFINITION_TEMPLATE='+(NSString *){IDENTIFIER};'
10
+ SEGUE_IMPLEMENTATION_TEMPLATE='+(NSString *){IDENTIFIER} { return {IDENTIFIER_CONSTANT_NAME}; }'
11
+
12
+ REUSE_DEFINITION_TEMPLATE='+(NSString *){IDENTIFIER};'
13
+ REUSE_IMPLEMENTATION_TEMPLATE='+(NSString *){IDENTIFIER} { return {IDENTIFIER_CONSTANT_NAME}; }'
14
+ STORYBOARD_IMPLEMENTATION_TEMPLATE='[UIStoryboard storyboardWithName:{IDENTIFIER_CONSTANT_NAME} bundle:[NSBundle mainBundle]]'
15
+ STORYBOARD_SECTION_TITLE_TEMPLATE="/** {TITLE} */"
16
+
17
+ HEADER_TEMPLATE='''//
18
+ // {FILENAME}
19
+ // File generated using Ovaltine
20
+
21
+ #import <Foundation/Foundation.h>
22
+
23
+ @interface {CLASS_NAME}
24
+
25
+ +(UIStoryboard *)storyboard;
26
+
27
+ {REUSE_IDENTIFIERS}
28
+
29
+ {SEGUE_IDENTIFIERS}
30
+
31
+ {VIEW_CONTROLLERS}
32
+
33
+ @end
34
+ '''
35
+
36
+ IMPLEMENTATION_TEMPLATE='''//
37
+ // {FILENAME}
38
+ // File generated using Ovaltine
39
+
40
+ #import <UIKit/UIKit.h>
41
+ #import "{CLASS_NAME}.h"
42
+
43
+ static UIStoryboard* _storyboard = nil;
44
+ {STATIC_VARIABLES}
45
+
46
+ @implementation {CLASS_NAME}
47
+
48
+ +(UIStoryboard *)storyboard { return _storyboard ?: (_storyboard = {STORYBOARD}); }
49
+
50
+ {REUSE_IDENTIFIERS}
51
+
52
+ {SEGUE_IDENTIFIERS}
53
+
54
+ {VIEW_CONTROLLERS}
55
+
56
+ @end
57
+ '''
58
+ end
59
+ end
@@ -0,0 +1,51 @@
1
+
2
+ module Ovaltine
3
+ class Storyboard
4
+ attr_reader :name, :filepaths, :cell_reuse_identifiers,
5
+ :view_controller_identifiers, :segue_identifiers
6
+
7
+ def initialize name, filepaths
8
+ @name, @filepaths = name, filepaths
9
+ @cell_reuse_identifiers = []
10
+ @segue_identifiers = []
11
+ @view_controller_identifiers = []
12
+ filepaths.each {|f| parse(File.expand_path(f))}
13
+ end
14
+
15
+ def parse path
16
+ load_dependencies
17
+ document = REXML::Document.new(File.new(path))
18
+ document.get_elements('//').each do |node|
19
+ parse_identifiers(node)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def load_dependencies
26
+ unless @@loaded ||= false
27
+ require 'fileutils'
28
+ require 'pathname'
29
+ require 'rexml/document'
30
+ @@loaded = true
31
+ end
32
+ end
33
+
34
+ def parse_identifiers node
35
+ case node.name
36
+ when 'segue'
37
+ if identifier = node.attributes["identifier"]
38
+ segue_identifiers << identifier
39
+ end
40
+ when /viewcontroller/i
41
+ if identifier = node.attributes["storyboardIdentifier"]
42
+ view_controller_identifiers << identifier
43
+ end
44
+ when /cell/i
45
+ if identifier = node.attributes["reuseIdentifier"]
46
+ cell_reuse_identifiers << identifier
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Ovaltine
2
+ VERSION = "1.0.0"
3
+ end
data/lib/ovaltine.rb ADDED
@@ -0,0 +1,51 @@
1
+
2
+ require 'ovaltine/storyboard'
3
+ require 'ovaltine/objc/storyboard_formatter'
4
+ require 'ovaltine/objc/storyboard_templates'
5
+ require 'ovaltine/version'
6
+
7
+ module Ovaltine
8
+
9
+ def self.create_constant_files(path, options)
10
+ files = Dir.glob("#{path}/**/*.storyboard")
11
+ groups = files.group_by {|f| File.basename(f).sub('.storyboard','')}
12
+ formatters = groups.map do |name, paths|
13
+ storyboard = Storyboard.new(name, paths)
14
+ StoryboardFormatter.new(storyboard, options[:prefix], options[:output_directory])
15
+ end
16
+ generated_paths = formatters.map(&:output_paths).flatten
17
+ if path = generated_paths.detect {|p| File.exist?(p)} and !options[:auto_replace]
18
+ if prompt("Some generated files already exist. Overwrite? (Y/n)", 'y')
19
+ write_files(formatters)
20
+ end
21
+ else
22
+ write_files(formatters)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def self.write_files formatters
29
+ files = []
30
+ formatters.each do |formatter|
31
+ formatter.write
32
+ files += formatter.output_paths
33
+ end
34
+ files.each do |path|
35
+ puts " * #{File.basename(path)}"
36
+ end
37
+ puts "\n#{files.size} files generated"
38
+ end
39
+
40
+ def self.prompt title, default_answer
41
+ puts title
42
+ answer = STDIN.gets.chomp
43
+ if answer.length == 0
44
+ default_answer == 'y'
45
+ elsif !['y','n'].include?(answer.downcase)
46
+ false
47
+ else
48
+ answer.downcase == 'y'
49
+ end
50
+ end
51
+ end
data/ovaltine.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ovaltine/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ovaltine"
8
+ spec.version = Ovaltine::VERSION
9
+ spec.authors = ["Delisa Mason"]
10
+ spec.email = ["iskanamagus@gmail.com"]
11
+ spec.required_ruby_version = '>= 1.8.7'
12
+ spec.description =
13
+ %q{
14
+ Constant generator for identifiers in Cocoa app storyboards
15
+ }
16
+ spec.summary = %q{Cocoa app constant generator}
17
+ spec.homepage = "https://github.com/kattrali/ovaltine"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake", '~> 10.0'
27
+ spec.add_development_dependency "bacon", '~> 1.2'
28
+ end
@@ -0,0 +1,29 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'bacon'
4
+ require 'ovaltine'
5
+
6
+ describe 'StoryboardFormatter' do
7
+
8
+ it 'writes valid output paths' do
9
+ storyboard = Ovaltine::Storyboard.new('Main?P', [])
10
+ formatter = Ovaltine::StoryboardFormatter.new(storyboard, '', '.')
11
+ names = formatter.output_paths.map {|p| File.basename(p)}
12
+ names.should.include 'Main_PStoryboard.m'
13
+ names.should.include 'Main_PStoryboard.h'
14
+ end
15
+
16
+ it 'uses the prefix in output paths' do
17
+ storyboard = Ovaltine::Storyboard.new('Main_iPhone', [])
18
+ formatter = Ovaltine::StoryboardFormatter.new(storyboard, 'ABC', '.')
19
+ names = formatter.output_paths.map {|p| File.basename(p)}
20
+ names.should.include 'ABCMain_iPhoneStoryboard.m'
21
+ names.should.include 'ABCMain_iPhoneStoryboard.h'
22
+ end
23
+
24
+ it 'uses the prefix in the generated class name' do
25
+ storyboard = Ovaltine::Storyboard.new('Onboarding', [])
26
+ formatter = Ovaltine::StoryboardFormatter.new(storyboard, 'DMU', '.')
27
+ formatter.classname.should.equal 'DMUOnboardingStoryboard'
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'bacon'
4
+ require 'ovaltine'
5
+
6
+ describe 'Storyboard' do
7
+
8
+ before do
9
+ @path = File.expand_path('features/fixtures/Sample/Sample/Base.lproj/Main.storyboard')
10
+ @storyboard = Ovaltine::Storyboard.new('Main', [@path])
11
+ end
12
+
13
+ it 'caches identifiers for generic view controllers' do
14
+ @storyboard.view_controller_identifiers.should.include "sampleViewController"
15
+ end
16
+
17
+ it 'caches identifiers for collection view controllers' do
18
+ @storyboard.view_controller_identifiers.should.include "collectionViewController"
19
+ end
20
+
21
+ it 'caches identifiers for table view controllers' do
22
+ @storyboard.view_controller_identifiers.should.include "listViewController"
23
+ end
24
+
25
+ it 'caches identifiers for named segues' do
26
+ @storyboard.segue_identifiers.should.include "starterSegueIdentifier"
27
+ end
28
+
29
+ it 'caches cell reuse identifiers for table view cells' do
30
+ @storyboard.cell_reuse_identifiers.should.include "sampleCellIdentifier"
31
+ end
32
+
33
+ it 'caches cell reuse identifiers for collection view cells' do
34
+ @storyboard.cell_reuse_identifiers.should.include "squareCellIdentifier"
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ovaltine
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Delisa Mason
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bacon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ description: "\n Constant generator for identifiers in Cocoa app storyboards\n "
56
+ email:
57
+ - iskanamagus@gmail.com
58
+ executables:
59
+ - ovaltine
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .travis.yml
64
+ - CHANGELOG.md
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - TODO.md
69
+ - bin/ovaltine
70
+ - features/fixtures/Sample/Sample.xcodeproj/project.pbxproj
71
+ - features/fixtures/Sample/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata
72
+ - features/fixtures/Sample/Sample/Base.lproj/Main.storyboard
73
+ - features/fixtures/Sample/Sample/DMMAppDelegate.h
74
+ - features/fixtures/Sample/Sample/DMMAppDelegate.m
75
+ - features/fixtures/Sample/Sample/DMMViewController.h
76
+ - features/fixtures/Sample/Sample/DMMViewController.m
77
+ - features/fixtures/Sample/Sample/Images.xcassets/AppIcon.appiconset/Contents.json
78
+ - features/fixtures/Sample/Sample/Images.xcassets/LaunchImage.launchimage/Contents.json
79
+ - features/fixtures/Sample/Sample/Sample-Info.plist
80
+ - features/fixtures/Sample/Sample/Sample-Prefix.pch
81
+ - features/fixtures/Sample/Sample/en.lproj/InfoPlist.strings
82
+ - features/fixtures/Sample/Sample/main.m
83
+ - features/fixtures/Sample/SampleTests/SampleTests-Info.plist
84
+ - features/fixtures/Sample/SampleTests/SampleTests.m
85
+ - features/fixtures/Sample/SampleTests/en.lproj/InfoPlist.strings
86
+ - lib/ovaltine.rb
87
+ - lib/ovaltine/objc/storyboard_formatter.rb
88
+ - lib/ovaltine/objc/storyboard_templates.rb
89
+ - lib/ovaltine/storyboard.rb
90
+ - lib/ovaltine/version.rb
91
+ - ovaltine.gemspec
92
+ - specs/storyboard_formatter_spec.rb
93
+ - specs/storyboard_spec.rb
94
+ homepage: https://github.com/kattrali/ovaltine
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: 1.8.7
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Cocoa app constant generator
118
+ test_files:
119
+ - features/fixtures/Sample/Sample.xcodeproj/project.pbxproj
120
+ - features/fixtures/Sample/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata
121
+ - features/fixtures/Sample/Sample/Base.lproj/Main.storyboard
122
+ - features/fixtures/Sample/Sample/DMMAppDelegate.h
123
+ - features/fixtures/Sample/Sample/DMMAppDelegate.m
124
+ - features/fixtures/Sample/Sample/DMMViewController.h
125
+ - features/fixtures/Sample/Sample/DMMViewController.m
126
+ - features/fixtures/Sample/Sample/Images.xcassets/AppIcon.appiconset/Contents.json
127
+ - features/fixtures/Sample/Sample/Images.xcassets/LaunchImage.launchimage/Contents.json
128
+ - features/fixtures/Sample/Sample/Sample-Info.plist
129
+ - features/fixtures/Sample/Sample/Sample-Prefix.pch
130
+ - features/fixtures/Sample/Sample/en.lproj/InfoPlist.strings
131
+ - features/fixtures/Sample/Sample/main.m
132
+ - features/fixtures/Sample/SampleTests/SampleTests-Info.plist
133
+ - features/fixtures/Sample/SampleTests/SampleTests.m
134
+ - features/fixtures/Sample/SampleTests/en.lproj/InfoPlist.strings