pkluz / Swashbuckler

Swashbuckler is a tool to formalize and automate the styling of applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swashbuckler

Swashbuckler is a tool to formalize and automate the styling of applications.

Supported Properties

Swashbuckler allows you to generate any of the following properties as part of your style objects:

- Colors
- Fonts
- Booleans
- Numbers
- Sizes
- Rects

Style Classes

Similar to CSS, the swashbuckler allows you to define style classes. Style classes group style properties and automatically trigger the generation of extensions containing convenient accessors to style related information to structs and/or classes with the matching name.

.feedViewController
    backgroundColor #FF00CC
    defaultFont 12pt 'Helvetica-Neue'

The above swashbuckler stylesheet will emit the following Swift code on iOS:

public struct FeedViewControllerStyle {
    public let backgroundColor = UIColor(red: 255.0/255.0, green: 0.0/255.0, blue: 204.0/255.0, alpha: 255.0/255.0)
    public let defaultFont = UIFont(name: "Helvetica-Neue", size: 12.0)! // swiftlint:disable:this force_unwrap
}

extension FeedViewController {
    public var style: FeedViewControllerStyle {
        return FeedViewControllerStyle()
    }
}

Please note that your application will not compile if the style classes name couldn't be matched to an existing type. To resolve this issue you will need to adjust the name of your style class.

Nesting

Blocks can be nested, to allow for hierarchical structuring of your styles. Note the difference between defining a block for a style class and a style element. A style element will not attempt to extend an existing type, instead only a style struct will be generated.

.feedViewController
    backgroundColor #FF00CC
    defaultFont 12pt 'Helvetica-Neue'
    
    #headerView
        isTranslucent true

The above swashbuckler stylesheet will emit the following Swift code on iOS:

public struct FeedViewControllerStyle {

    public struct HeaderViewStyle {
        public var isTranslucent: Bool {
            return true
        }
    }

    public let headerViewStyle = HeaderViewStyle()
    public let backgroundColor = UIColor(red: 255.0/255.0, green: 0.0/255.0, blue: 204.0/255.0, alpha: 255.0/255.0)
    public let defaultFont = UIFont(name: "Helvetica-Neue", size: 12.0)! // swiftlint:disable:this force_unwrap
}

extension FeedViewController {
    public var style: FeedViewControllerStyle {
        return FeedViewControllerStyle()
    }
}

References

Swashbuckler has built in support for some fundamental (scoped) reference semantics. This means, instead of repeating your definitions, you can reference them. This applies to atomic elements like fonts and colors, but also entire style blocks.

.feedViewController
    backgroundColor #FF00CC
    defaultFont 12pt 'Helvetica-Neue'

    #headerView
        isTranslucent true
        titleFont @defaultFont

The above swashbuckler stylesheet will emit the following Swift code on iOS:

public struct FeedViewControllerStyle {

    public struct HeaderViewStyle {
        public let isTranslucent = true
        public let titleFont = UIFont(name: "Helvetica-Neue", size: 12.0)! // swiftlint:disable:this force_unwrap
    }

    public let headerViewStyle = HeaderViewStyle()
    public let backgroundColor = UIColor(red: 255.0/255.0, green: 0.0/255.0, blue: 204.0/255.0, alpha: 255.0/255.0)
    public let defaultFont: = UIFont(name: "Helvetica-Neue", size: 12.0)! // swiftlint:disable:this force_unwrap
}

extension FeedViewController {
    public var style: FeedViewControllerStyle {
        return FeedViewControllerStyle()
    }
}

About

Swashbuckler is a tool to formalize and automate the styling of applications.

License:MIT License


Languages

Language:Swift 93.9%Language:Ruby 4.3%Language:HTML 1.2%Language:Objective-C 0.7%