Giter Site home page Giter Site logo

sbconstants's People

Contributors

ashfurrow avatar davidlawson avatar jklausa avatar justmaku avatar kevboh avatar maquert avatar neonichu avatar orta avatar palleas avatar patoroco avatar paulsamuels avatar pmairoldi avatar raulriera avatar slangley avatar tonyarnold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbconstants's Issues

Generate empty enum if section contains no constants

I am using some helper methods and swift extensions to work with the enums provided by SBConstants.
However, if e.g. there is no segue identifier setup in the storyboard, the generated SBConstants file omits the enum altogether.

This of course breaks any custom code that directly references the enums, e.g. SegueIdentifier.

I think it would be fine to output the empty enum in case there are no constants defined.
Any opinions?

Enum naming convention

Currently sbconstants creates the enums in the format below
public enum SegueIdentifier : String
Most of the patterns and styleguides, and even Apple sample code recommend the format as below (no space between name and column)
public enum SegueIdentifier: String
Considering this is more of a stylistic and opinionated change, would it make sense to update swift_body.erb to match the common conventions? I can create a PR if so.

I know the templates directory parameter solves it for any tweaks users need, but I am guessing there would be a lot who prefer it without the extra space, because the rest of the lines do follow common convention - so this comment

invalid byte sequence in US-ASCII when adding SBConstants in run scrip

Hi there,

so generating the constants from the terminal works fine. However trying to run the same command from a run script added to the build phases gives me this ruby error which seems cryptic to me as I don't know anything about the language. Do you have an idea?

/Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:79:in `[]': invalid byte sequence in US-ASCII (ArgumentError)
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:79:in `block (3 levels) in parse_storyboards'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:78:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:78:in `block (2 levels) in parse_storyboards'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:77:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:77:in `each_with_index'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:77:in `block in parse_storyboards'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:69:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:69:in `each_with_index'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:69:in `parse_storyboards'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:18:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/lib/sbconstants/cli.rb:8:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/sbconstants-1.1.2/bin/sbconstants:5:in `<top (required)>'
    from /usr/local/bin/sbconstants:23:in `load'
    from /usr/local/bin/sbconstants:23:in `<main>'
Command /bin/sh failed with exit code 1

Constants with static let?

Hi, I would like to suggest a change from enums to structs

#swift_body.erb
// Auto generated file from SBConstants - any changes may be lost
<%% sections.each do |section| %>

public struct <%%= section.pretty_title %> {
<%% section.constants.each do |constant| %>
<%% if options.verbose %>
//
<%% constants[constant].each do |location| %>
//    info: <%%= location.debug %>
// context: <%%= location.context %>
//
<%% end %>
<%% end %>
<%= @body %>
<%% end %>
}
<%% end %>
#swift_constant_writer.rb
def write
      head = %Q{\nimport Foundation"\n}
      body = %Q{    static let <%= sanitise_key(constant) %> = "<%= constant %>"\n}
      @swift_out.puts template_with_file head, body
end

That way the resulting .swift file will be something like this, and will allow us to use them without calling .rawValue on each of them

public struct SegueIdentifiers {
        static let AttachmentsScreen = "AttachmentsScreenSegue"
        static let TagsScreen = "TagsScreenSegue"
        static let TeamsScreen = "TeamsScreenSegue"
}

Unknown type name 'NSString' for objc code

.../Source/Storyboard/StoryboardIdentifiers.m:3:9: In file included from
error: unknown type name 'NSString' extern NSString * const SomeCell;

There is no Foundation import for generated objc file. If I add id manual it works

File Content

// Auto generated file - any changes will be lost


#pragma mark - tableViewCell.reuseIdentifier
extern NSString * const SomeCell;

Support XIB files

Hey, is it possible to use SBConstants to extract identifiers from .xib files?

It seems like it skips those, but I have lots of them for custom UITableViewCells and would love to use generated constants in my code.

Query format for YAML file

What is the format of the YAML file containing queries?

Perhaps the default query should be moved to YAML for consistency and reference.

Convienience methods to utilize constants

The code below is based on Reusable and uses the StoryboardNames generated to init VCs

Storyboard Methods
extension UIStoryboard {

    /// Convenience Initializers
    convenience init(storyboard: StoryboardNames, bundle: Bundle? = nil) {

        self.init(name: storyboard.rawValue, bundle: bundle)
    }

    /// Class Functions
    public static func storyboard(storyboard: StoryboardNames = .Main, bundle: Bundle? = nil) -> UIStoryboard {

        return UIStoryboard(name: storyboard.rawValue, bundle: bundle)
    }

    /// View Controller Instantiation from Generics
    func instantiateViewController<T: ViewControllerInitializer>(_: T.Type) -> T {

        guard let viewController = self.instantiateViewController(withIdentifier: T.storyboardIdentifier) as? T else {
            fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
        }

        return viewController
    }
}

Usage: let vc = UIStoryboard(storyboard: .Main)

ViewController Methods
extension UIViewController {
    
    public static func instantiateFromStoryboard(name storyboard: StoryboardNames = .Main) -> Self {
        
        func instantiateFromStoryboard<T: UIViewController>(_: T.Type) -> T {
            
            let sb = UIStoryboard(storyboard: storyboard)
            return sb.instantiateViewController(withIdentifier: String(describing: T.self)) as! T
        }
        
        return instantiateFromStoryboard(self)
    }
}

Usage: let vc = SearchViewController.instantiateFromStoryboard(name: .Main)

I'm new to ruby or I'd make the PR myself, leaving the idea here if anyone does want to implement it.

Add file name if it doesn't match the tokenised version

I've noticed that when sbconstants encounters a file with spaces in the name, it tokenises it to strip whitespace, like so:

New Document.storyboard โ†’ StoryboardNames.NewDocument

That's great, but it results in an unusable enum entry. It would be great if this were handled automatically, i.e.:

public enum StoryboardNames: String {
    case NewDocument = "New Document"
}

Exclude storyboard names

Hi there,

I'm using a .yml as parameter to exclude everything else but the segue identifier.

The .yml looks simply like this:
segue: identifier

Unfortunately I always end up having the storyboard names as constants in the header. Is there any way to exclude storyboard names from parsing?

Thanks for your effort! I love this tool so far.

Blog post in README

The blog post linked to from the README is currently inaccessible. Maybe, once the site is back, we could copy common use cases from the post into the README?

With rvm sbconstants doesn't run

I have tried everything to make this part of my build phases with no luck.
If I run this outside Xcode it works as expected; but running it like this will fail:

sbconstants destinationFile.h

This will fail with: sbconstants command not found.

If I run it like this:

`which sbconstants` destinationFile.h

The build phase won't fail but no data will be generated to destinationFile.h.

After reading your blog post you say it needs to be installed as "System Ruby" but since I have rvm in theory I don't have access to "System Ruby"; but running it with which should actually generate something (unless I'm missing something).

I tried different options with no luck; even adding -v won't produce any output to the build phase.

Add support for different formatting for different nodes

Hi, is it possible to have custom formatting for the different nodes as well?
Something like this for eg:

pragma mark - segue.identifier

NSString * const PSBMasterToDetail = @"PSBMasterToDetail-Segue";
NSString * const PSBMasterToSettings = @"PSBMasterToSettings-Segue";

pragma mark - storyboardNames

NSString * const Main = @"Main-Name";

pragma mark - tableViewCell.reuseIdentifier

NSString * const PSBAwesomeCell = @"PSBAwesomeCell-ReuseIdentifier";

also, thanks for the awesome project!

Storyboard names

I don't fully understand the template format yet, so I don't know if this only requires a template update.

Could we include constants for the storyboard name?
As used in + (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil

Verbose option crash

The Objective-C templates will crash when -v or --verbose option is used:

(erb):9:in `block (2 levels) in method_missing': undefined local variable or method `constant' for #<SBConstants::ObjcConstantWriter:0x007fbdb3a6c200> (NameError)
    from (erb):6:in `each'
    from (erb):6:in `block in method_missing'
    from (erb):4:in `each'
    from (erb):4:in `method_missing'
    from /usr/local/var/rbenv/versions/2.1.3/lib/ruby/2.1.0/erb.rb:850:in `eval'
    from /usr/local/var/rbenv/versions/2.1.3/lib/ruby/2.1.0/erb.rb:850:in `result'
    from /Users/X/.gem/gems/sbconstants-1.1.0/lib/sbconstants/objc_constant_writer.rb:37:in `template_with_file'
    from /Users/X/.gem/gems/sbconstants-1.1.0/lib/sbconstants/objc_constant_writer.rb:25:in `header'
    from /Users/X/.gem/gems/sbconstants-1.1.0/lib/sbconstants/objc_constant_writer.rb:16:in `write'
    from /Users/X/.gem/gems/sbconstants-1.1.0/lib/sbconstants/cli.rb:94:in `write'
    from /Users/X/.gem/gems/sbconstants-1.1.0/lib/sbconstants/cli.rb:19:in `run'
    from /Users/X/.gem/gems/sbconstants-1.1.0/lib/sbconstants/cli.rb:8:in `run'
    from /Users/X/.gem/gems/sbconstants-1.1.0/bin/sbconstants:5:in `<top (required)>'
    from /Users/X/.gem/bin/sbconstants:23:in `load'
    from /Users/X/.gem/bin/sbconstants:23:in `<main>'

What are queries?

SBConstants take a query cli parameter, but I can't seem to find any docs describing what it does.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.