redbreast 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +5 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +39 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/exe/redbreast +31 -0
  14. data/lib/redbreast/commands/image_generator.rb +53 -0
  15. data/lib/redbreast/commands/setup.rb +116 -0
  16. data/lib/redbreast/commands/test_generator.rb +56 -0
  17. data/lib/redbreast/crawlers/image_crawler.rb +18 -0
  18. data/lib/redbreast/error_handler.rb +24 -0
  19. data/lib/redbreast/helpers/general.rb +67 -0
  20. data/lib/redbreast/helpers/hash.rb +10 -0
  21. data/lib/redbreast/helpers/terminal.rb +17 -0
  22. data/lib/redbreast/io/config.rb +19 -0
  23. data/lib/redbreast/serializers/objc_serializer.rb +27 -0
  24. data/lib/redbreast/serializers/serializer.rb +18 -0
  25. data/lib/redbreast/serializers/swift_serializer.rb +18 -0
  26. data/lib/redbreast/template_generators/images/objc_images_template_generator.rb +49 -0
  27. data/lib/redbreast/template_generators/images/swift_images_template_generator.rb +28 -0
  28. data/lib/redbreast/template_generators/objc_template_generator.rb +24 -0
  29. data/lib/redbreast/template_generators/swift_template_generator.rb +12 -0
  30. data/lib/redbreast/template_generators/tests/objc_tests_template_generator.rb +39 -0
  31. data/lib/redbreast/template_generators/tests/swift_tests_template_generator.rb +31 -0
  32. data/lib/redbreast/version.rb +3 -0
  33. data/lib/redbreast.rb +43 -0
  34. data/redbreast.gemspec +40 -0
  35. metadata +163 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: acb449e6185cec29a8b5db4b37b9c2d1171a8cee
4
+ data.tar.gz: ed1ca1fae6e110d58b10bf64368a3292fa60d213
5
+ SHA512:
6
+ metadata.gz: caeabd7ec6255affe9e59c2e5c56bd9bba1ada4bc0ae62a8294385df7cd141fedcdbe7995ed56b607b71f0215f7fec6668c9f4007914a2971551a22693ced72f
7
+ data.tar.gz: 89e95780148d0e1ce307d1ac2965c96612663a9c1ac7910b3acfa686f4efd2a65033f5ac95930e6cba0c5d0879554e47cd232947e51ee947861a8e388d807e7e
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at vlaho.poluta@infinum.hr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redbreast.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Vlaho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Redbreast
2
+
3
+ ![](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/Turdus-migratorius-002.jpg/440px-Turdus-migratorius-002.jpg)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'redbreast'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install redbreast
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/infinum/redbreast. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "redbreast"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/redbreast ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander'
5
+ require 'commander/import'
6
+ require 'redbreast'
7
+
8
+ program :name, 'redbreast'
9
+ program :version, Redbreast::VERSION
10
+ program :description, 'An iOS client for safe and strong resources.'
11
+
12
+ command :init do |c|
13
+ c.syntax = 'redbreast init'
14
+ c.description = 'Sets up a redbreast.yml config for selected project.'
15
+ c.action do |_args, options|
16
+ Redbreast::ErrorHandler.rescuable do
17
+ Redbreast::Command::Setup.init
18
+ end
19
+ end
20
+ end
21
+
22
+ command :generate do |c|
23
+ c.syntax = 'redbreast generate'
24
+ c.description = 'Generate images strong reference files.'
25
+ c.action do |_args, options|
26
+ Redbreast::ErrorHandler.rescuable do
27
+ Redbreast::Command::ImageGenerator.init
28
+ Redbreast::Command::TestGenerator.init
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,53 @@
1
+ module Redbreast
2
+ module Command
3
+ class ImageGenerator
4
+ include Helper::Terminal
5
+ include Helper::General
6
+
7
+ def self.init
8
+ new.call
9
+ end
10
+
11
+ def call
12
+ prompt.say("Generating image resources...")
13
+ generate_image_sources(bundles, programming_language)
14
+ success("Image resources generated!")
15
+ end
16
+
17
+ private
18
+
19
+ def generate_image_sources(bundles, programming_language)
20
+ bundles.each do |bundle|
21
+ image_names = pull_asset_names(bundle[:assetsSearchPath])
22
+
23
+ write_images(image_names, bundle, programming_language)
24
+ end
25
+ end
26
+
27
+ # Serializing data
28
+
29
+ def write_images(image_names, bundle, programming_language)
30
+ output_path = bundle[:outputSourcePath]
31
+ return if output_path.to_s.empty?
32
+ case programming_language.downcase
33
+ when "objc"
34
+ serializer = Redbreast::Serializer::ObjC
35
+ template_generator = Redbreast::TemplateGenerator::Image::ObjC
36
+ when "swift"
37
+ serializer = Redbreast::Serializer::Swift
38
+ template_generator = Redbreast::TemplateGenerator::Image::Swift
39
+ end
40
+ serializer.new(image_names, bundle).save(output_path, template_generator.new)
41
+ end
42
+
43
+ # Pulling data
44
+
45
+ def pull_asset_names(assetsSearchPath)
46
+ Redbreast::Crawler::Image
47
+ .image_names_uniq(assetsSearchPath)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,116 @@
1
+ require 'commander/blank'
2
+ require 'commander/command'
3
+
4
+ module Redbreast
5
+ module Command
6
+ class Setup
7
+ include Helper::Terminal
8
+ include Helper::General
9
+ include Helper::Hash
10
+
11
+ def self.init(options = Commander::Command::Options.new)
12
+ new(options).call
13
+ end
14
+
15
+ def initialize(options = Commander::Command::Options.new)
16
+ @options = options
17
+ end
18
+
19
+ def call
20
+ language = language_prompt
21
+ bundle_names = bundle_names_prompt(language).split(" ")
22
+ bundles = bundle_names.map do |bundle|
23
+ reference = bundle_reference(bundle, language)
24
+ assets_search_path = assets_search_path_prompt(bundle)
25
+ output_source_path = images_sources_path_prompt(bundle, language)
26
+ include_tests = create_tests_path_prompt?(bundle)
27
+ {
28
+ name: bundle,
29
+ reference: reference,
30
+ assetsSearchPath: assets_search_path,
31
+ outputSourcePath: output_source_path,
32
+ outputTestPath: include_tests ? tests_path_prompt(bundle, language) : nil,
33
+ testableImport: include_tests ? testable_import_prompt(bundle, language) : nil
34
+ }.compact
35
+ end
36
+ config = {
37
+ language: language,
38
+ bundles: bundles
39
+ }
40
+ Redbreast::IO::Config.write(config)
41
+ success
42
+ end
43
+
44
+ private
45
+
46
+ # Language
47
+
48
+ def language_prompt
49
+ languages = {'Swift' => 'swift', 'Objective-C' => 'objc'}
50
+ prompt.select('Choose a language: ', languages)
51
+ end
52
+
53
+ # Assets source path
54
+
55
+ def assets_search_path_prompt(bundle)
56
+ prompt.ask("Please enter assets folder search paths for bundle #{bundle}?", default: '**/*.xcassets')
57
+ end
58
+
59
+ # Bundle names promt
60
+
61
+ def bundle_names_prompt(language)
62
+ case language
63
+ when "objc"
64
+ prompt.ask('Please enter bundle names that you use separated by spaces', default: 'mainBundle')
65
+ when "swift"
66
+ prompt.ask('Please enter bundle names that you use separated by spaces', default: 'main')
67
+ end
68
+ end
69
+
70
+ def bundle_reference(bundle_name, language)
71
+ case language
72
+ when "objc"
73
+ "[NSBundle #{bundle_name}]"
74
+ when "swift"
75
+ ".#{bundle_name}"
76
+ end
77
+ end
78
+
79
+ # Images source path
80
+
81
+ def images_sources_path_prompt(bundle, language)
82
+ case language
83
+ when "objc"
84
+ prompt.ask("Where would you like to store images resources files for bundle #{bundle}?", default: './Common/Categories/Images')
85
+ when "swift"
86
+ prompt.ask("Where would you like to store images resources files for bundle #{bundle}?", default: './Common/Extensions/UIImageExtension.swift')
87
+ end
88
+ end
89
+
90
+ # Tests
91
+
92
+ def create_tests_path_prompt?(bundle)
93
+ prompt.yes?("Would you like to create tests for bundle #{bundle}?")
94
+ end
95
+
96
+ def tests_path_prompt(bundle, language)
97
+ case language
98
+ when "objc"
99
+ prompt.ask("Where would you like to store tests for bundle #{bundle}?", default: './Common/Categories/ImagesTest')
100
+ when "swift"
101
+ prompt.ask("Where would you like to store tests for bundle #{bundle}?", default: './Common/Extensions/UIImageExtensionTest.swift')
102
+ end
103
+ end
104
+
105
+ def testable_import_prompt(bundle, language)
106
+ case language
107
+ when "objc"
108
+ nil
109
+ when "swift"
110
+ prompt.ask("Please enter testable import name for bundle #{bundle}?", required: true)
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,56 @@
1
+ module Redbreast
2
+ module Command
3
+ class TestGenerator
4
+ include Helper::Terminal
5
+ include Helper::General
6
+
7
+ def self.init
8
+ new.call
9
+ end
10
+
11
+ def call
12
+ filtered_bundles = bundles.select { |bundle| bundle[:outputTestPath] }
13
+ return if filtered_bundles.empty?
14
+
15
+ prompt.say("Generating test resources...")
16
+ generate_test_sources(bundles, programming_language)
17
+ success("Test resources generated!")
18
+ end
19
+
20
+ private
21
+
22
+ def generate_test_sources(bundles, programming_language)
23
+ bundles.each do |bundle|
24
+ image_names = pull_asset_names(bundle[:assetsSearchPath])
25
+
26
+ write_tests(image_names, bundle, programming_language)
27
+ end
28
+ end
29
+
30
+ # Serializing data
31
+
32
+ def write_tests(image_names, bundle, programming_language)
33
+ output_path = bundle[:outputTestPath]
34
+ return if output_path.to_s.empty?
35
+ case programming_language.downcase
36
+ when "objc"
37
+ serializer = Redbreast::Serializer::ObjC
38
+ template_generator = Redbreast::TemplateGenerator::Test::ObjC
39
+ when "swift"
40
+ serializer = Redbreast::Serializer::Swift
41
+ template_generator = Redbreast::TemplateGenerator::Test::Swift
42
+ end
43
+ serializer.new(image_names, bundle).save(output_path, template_generator.new)
44
+ end
45
+
46
+ # Pulling data
47
+
48
+ def pull_asset_names(assetsSearchPath)
49
+ Redbreast::Crawler::Image
50
+ .image_names_uniq(assetsSearchPath)
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,18 @@
1
+ module Redbreast
2
+ module Crawler
3
+ class Image
4
+
5
+ def self.image_names_uniq(assets_search_path)
6
+ Dir.glob(assets_search_path).flat_map { |asset_folder|
7
+ Dir.glob("#{asset_folder}/**/*.imageset").map { |image_name|
8
+ image_name.split("/")[-1].chomp(".imageset")
9
+ }
10
+ }
11
+ .uniq
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,24 @@
1
+ module Redbreast
2
+ class ErrorHandler
3
+ extend Helper::Terminal
4
+
5
+ class << self
6
+ def rescuable
7
+ yield
8
+ rescue => e
9
+ handle(e)
10
+ end
11
+
12
+ def handle(e)
13
+ prompt.error(
14
+ case e
15
+ when Errno::ENOENT
16
+ "We could not find a file that we need:\n\n#{e.message}"
17
+ else
18
+ "An error happened. This might help:\n\n#{e.message}"
19
+ end
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,67 @@
1
+ module Redbreast
2
+ module Helper
3
+ module General
4
+ ESCAPE_KEYWORDS = ["associatedtype", "class", "deinit", "enum", "extension", "fileprivate", "func",
5
+ "import", "init", "inout", "internal", "let", "operator", "private", "protocol",
6
+ "public", "static", "struct", "subscript", "typealias", "var", "break", "case",
7
+ "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if",
8
+ "in", "repeat", "return", "switch", "where", "while", "as", "Any", "catch", "false",
9
+ "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws", "true", "try", "_"]
10
+
11
+ def config
12
+ @config ||= Redbreast::IO::Config.read
13
+ end
14
+
15
+ def programming_language
16
+ @programming_language ||= config[:language]
17
+ end
18
+
19
+ def bundles
20
+ @bundles ||= config[:bundles]
21
+ end
22
+
23
+ def indent(level = 0, initial = "")
24
+ (1..level)
25
+ .to_a.reduce("") { |result, value| result + " " }
26
+ .concat(initial)
27
+ end
28
+
29
+ def clean_enum_name(name)
30
+ clean_name = name
31
+ .split(/[^0-9a-zA-Z]/)
32
+ .reject { |c| c.empty? }
33
+ .map { |value| value.capitalize }
34
+ .join
35
+
36
+ escape_with_underscore_if_needed(clean_name)
37
+ end
38
+
39
+ def clean_case_name(name)
40
+ clean_variable_name(name)
41
+ end
42
+
43
+ def clean_variable_name(name)
44
+ clean_name = name
45
+ .split(/[^0-9a-zA-Z]/)
46
+ .reject { |c| c.empty? }
47
+ .each_with_index
48
+ .map { |value, index| index == 0 ? value.downcase : value.capitalize }
49
+ .join
50
+
51
+ escaped_underscore = escape_with_underscore_if_needed(clean_name)
52
+ escape_keyword_if_needed(escaped_underscore)
53
+ end
54
+
55
+ def escape_with_underscore_if_needed(name)
56
+ return name if name.match(/^[A-Za-z_]/)
57
+ "_" + name
58
+ end
59
+
60
+ def escape_keyword_if_needed(name)
61
+ return name if !ESCAPE_KEYWORDS.include? name
62
+ "`#{name}`"
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module Redbreast
3
+ module Helper
4
+ module Hash
5
+ def compact
6
+ delete_if { |k, v| v.nil? }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require 'tty-prompt'
2
+
3
+ module Redbreast
4
+ module Helper
5
+ module Terminal
6
+
7
+ def success(message = 'Success!')
8
+ prompt.ok(message)
9
+ end
10
+
11
+ def prompt
12
+ @prompt ||= TTY::Prompt.new(interrupt: :exit)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Redbreast
2
+ module IO
3
+ class Config
4
+
5
+ CONFIG_FILE_PATH = "#{Dir.pwd}/.redbrest.yml".freeze
6
+
7
+ class << self
8
+ def write(data)
9
+ File.open(CONFIG_FILE_PATH, 'w') { |file| YAML.dump(data, file) }
10
+ end
11
+
12
+ def read
13
+ YAML.load_file(CONFIG_FILE_PATH)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'serializer'
2
+
3
+ module Redbreast
4
+ module Serializer
5
+ class ObjC < Base
6
+ include Helper::General
7
+
8
+ def save(output_source_path, template_generator)
9
+ FileUtils.mkdir_p output_source_path unless File.exist? output_source_path
10
+
11
+ name = File.basename(output_source_path)
12
+
13
+ if template_generator.h_template
14
+ h_file = ERB.new(template_generator.h_template, nil, '-').result(binding)
15
+ File.write(File.join(output_source_path, "UIImage+#{name}.h"), h_file)
16
+ end
17
+
18
+ if template_generator.m_template
19
+ m_file = ERB.new(template_generator.m_template, nil, '-').result(binding)
20
+ File.write(File.join(output_source_path, "UIImage+#{name}.m"), m_file)
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module Redbreast
2
+ module Serializer
3
+ class Base
4
+ include ERB::Util
5
+ attr_accessor :image_names, :bundle
6
+
7
+ def initialize(image_names, bundle)
8
+ @image_names = image_names
9
+ @bundle = bundle
10
+ end
11
+
12
+ def save(path)
13
+ fail NotImplementedError, 'Abstract Method'
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'serializer'
2
+
3
+ module Redbreast
4
+ module Serializer
5
+ class Swift < Base
6
+ include Helper::General
7
+
8
+ def save(output_source_path, template_generator)
9
+ directory = File.dirname(output_source_path)
10
+ FileUtils.mkdir_p directory unless File.exist? directory
11
+
12
+ file = ERB.new(template_generator.template, nil, '-').result(binding)
13
+ File.write(output_source_path, file)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../objc_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module Image
6
+ class ObjC < Redbreast::TemplateGenerator::ObjC
7
+ include ERB::Util
8
+
9
+ def h_template()
10
+ <<-TEMPLATE
11
+
12
+ #import <UIKit/UIKit.h>
13
+
14
+ //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
15
+ @interface UIImage (<%= File.basename(bundle[:outputSourcePath]) %>)
16
+
17
+ <%- image_names.each do |name| -%>
18
+ + (instancetype)<%= clean_variable_name(name) %>;
19
+ <%- end -%>
20
+
21
+ @end
22
+
23
+ TEMPLATE
24
+ end
25
+
26
+ def m_template()
27
+ <<-TEMPLATE
28
+
29
+ #import <UIKit/UIKit.h>
30
+
31
+ //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
32
+ @implementation UIImage (<%= File.basename(bundle[:outputSourcePath]) %>)
33
+
34
+ <%- image_names.each do |name| -%>
35
+ +(instancetype)<%= clean_variable_name(name) %>
36
+ {
37
+ [UIImage imageNamed:@"<%= name %>" inBundle:<%= bundle[:reference] %> compatibleWithTraitCollection:nil];
38
+ }
39
+ <%- end -%>
40
+
41
+ @end
42
+
43
+ TEMPLATE
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ require_relative '../swift_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module Image
6
+ class Swift < TemplateGenerator::Swift
7
+ include ERB::Util
8
+
9
+ def template()
10
+ <<-TEMPLATE
11
+
12
+ import UIKit
13
+
14
+ //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
15
+ extension UIImage {
16
+
17
+ <%- image_names.each do |name| -%>
18
+ static var <%= clean_variable_name(name) %>: UIImage { return UIImage(named: "<%= name %>", in: <%= bundle[:reference] %>, compatibleWith: nil)! }
19
+ <%- end -%>
20
+
21
+ }
22
+
23
+ TEMPLATE
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module Redbreast
2
+ module TemplateGenerator
3
+ class ObjC
4
+ include ERB::Util
5
+
6
+ def h_filename()
7
+ fail NotImplementedError, 'Abstract Method'
8
+ end
9
+
10
+ def m_filename()
11
+ fail NotImplementedError, 'Abstract Method'
12
+ end
13
+
14
+ def h_template()
15
+ fail NotImplementedError, 'Abstract Method'
16
+ end
17
+
18
+ def m_template()
19
+ fail NotImplementedError, 'Abstract Method'
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module Redbreast
2
+ module TemplateGenerator
3
+ class Swift
4
+ include ERB::Util
5
+
6
+ def template()
7
+ fail NotImplementedError, 'Abstract Method'
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../objc_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module Test
6
+ class ObjC < TemplateGenerator::ObjC
7
+ include ERB::Util
8
+
9
+ def h_template()
10
+ nil
11
+ end
12
+
13
+ def m_template()
14
+ <<-TEMPLATE
15
+
16
+ #import <XCTest/XCTest.h>
17
+ #import <"UIImage+<%= File.basename(bundle[:outputSourcePath]) %>.h">
18
+
19
+ @interface <%= File.basename(bundle[:outputTestPath]) %> : XCTestCase
20
+
21
+ @end
22
+
23
+ @implementation Test
24
+
25
+ - (void)testExample {
26
+ <%- image_names.each do |name| -%>
27
+ [UIImage clean_variable_name(name)];
28
+ <%- end -%>
29
+ }
30
+
31
+ @end
32
+
33
+ TEMPLATE
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../swift_template_generator'
2
+
3
+ module Redbreast
4
+ module TemplateGenerator
5
+ module Test
6
+ class Swift < TemplateGenerator::Swift
7
+ include ERB::Util
8
+
9
+ def template()
10
+ <<-TEMPLATE
11
+
12
+ import UIKit
13
+ @testable import <%= bundle[:testableImport] %>
14
+
15
+ //THIS FILE IS AUTOGENERATED, DO NOT EDIT BY HAND
16
+ class <%= File.basename(bundle[:outputTestPath], ".*") %>: XCTestCase {
17
+
18
+ func testIfImagesArePresent() {
19
+ <%- image_names.each do |name| -%>
20
+ _ = UIImage.<%= clean_variable_name(name) %>
21
+ <%- end -%>
22
+ }
23
+
24
+ }
25
+
26
+ TEMPLATE
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Redbreast
2
+ VERSION = "0.1.0"
3
+ end
data/lib/redbreast.rb ADDED
@@ -0,0 +1,43 @@
1
+ # Parsing
2
+ require "yaml"
3
+ require "erb"
4
+
5
+ # Helpers
6
+ require "redbreast/helpers/terminal"
7
+ require "redbreast/helpers/general"
8
+ require "redbreast/helpers/hash"
9
+
10
+ # Commands
11
+ require "redbreast/commands/setup"
12
+ require "redbreast/commands/image_generator"
13
+ require "redbreast/commands/test_generator"
14
+
15
+ # File Accessors
16
+ require "redbreast/io/config"
17
+
18
+ # Crawlers
19
+ require "redbreast/crawlers/image_crawler"
20
+
21
+ # Serializers
22
+ require 'redbreast/serializers/serializer'
23
+ require 'redbreast/serializers/objc_serializer'
24
+ require 'redbreast/serializers/swift_serializer'
25
+
26
+ # Template generators
27
+ require 'redbreast/template_generators/objc_template_generator'
28
+ require 'redbreast/template_generators/swift_template_generator'
29
+ require 'redbreast/template_generators/images/objc_images_template_generator'
30
+ require 'redbreast/template_generators/images/swift_images_template_generator'
31
+ require 'redbreast/template_generators/tests/objc_tests_template_generator'
32
+ require 'redbreast/template_generators/tests/swift_tests_template_generator'
33
+
34
+ # Error Handler
35
+ require "redbreast/error_handler"
36
+
37
+ # Version
38
+ require "redbreast/version"
39
+
40
+
41
+ module Redbreast
42
+
43
+ end
data/redbreast.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redbreast/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redbreast"
8
+ spec.version = Redbreast::VERSION
9
+ spec.authors = ["Vlaho"]
10
+ spec.email = ["vlaho.poluta@infinum.hr"]
11
+
12
+ spec.summary = "A CLI for safe and strongly typed resources"
13
+ spec.homepage = "https://github.com/infinum/redbreast"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+
36
+ spec.add_dependency 'tty-prompt'
37
+ spec.add_dependency 'commander'
38
+ spec.add_dependency 'activesupport'
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redbreast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vlaho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-31 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-prompt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: commander
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - vlaho.poluta@infinum.hr
100
+ executables:
101
+ - redbreast
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".DS_Store"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - exe/redbreast
117
+ - lib/redbreast.rb
118
+ - lib/redbreast/commands/image_generator.rb
119
+ - lib/redbreast/commands/setup.rb
120
+ - lib/redbreast/commands/test_generator.rb
121
+ - lib/redbreast/crawlers/image_crawler.rb
122
+ - lib/redbreast/error_handler.rb
123
+ - lib/redbreast/helpers/general.rb
124
+ - lib/redbreast/helpers/hash.rb
125
+ - lib/redbreast/helpers/terminal.rb
126
+ - lib/redbreast/io/config.rb
127
+ - lib/redbreast/serializers/objc_serializer.rb
128
+ - lib/redbreast/serializers/serializer.rb
129
+ - lib/redbreast/serializers/swift_serializer.rb
130
+ - lib/redbreast/template_generators/images/objc_images_template_generator.rb
131
+ - lib/redbreast/template_generators/images/swift_images_template_generator.rb
132
+ - lib/redbreast/template_generators/objc_template_generator.rb
133
+ - lib/redbreast/template_generators/swift_template_generator.rb
134
+ - lib/redbreast/template_generators/tests/objc_tests_template_generator.rb
135
+ - lib/redbreast/template_generators/tests/swift_tests_template_generator.rb
136
+ - lib/redbreast/version.rb
137
+ - redbreast.gemspec
138
+ homepage: https://github.com/infinum/redbreast
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ allowed_push_host: https://rubygems.org
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.6.11
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: A CLI for safe and strongly typed resources
163
+ test_files: []