GithubHelp home page GithubHelp logo

raymondjavaxx / stylegen Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 0.0 73 KB

CLI tool for managing colors in iOS apps.

Home Page: https://rubygems.org/gems/stylegen

License: MIT License

Ruby 100.00%
ios colors themes uicolor swift uikit theme styling

stylegen's Introduction

stylegen

A CLI utility for managing the colors used in an iOS/macOS app from a centralized YAML file in a type-safe way.

CI

Installing

You can install stylegen manually by running:

$ gem install stylegen

Or by adding the following entry to your Gemfile, then running $ bundle install.

gem "stylegen"

How to use

To use stylegen in your project, you will need to create a theme.yaml file at the root of the project by executing:

$ stylegen init

The generated YAML file will look similar to this:

# Name of the design system. Defaults to "Theme".
# Feel free to use your company name, name of product,
# or name of your design system.
# e.g.: Primer, Material, Polaris, etc.
# system_name: "Theme"

# Path of generated Swift file.
output_path: "Colors.swift"

# UI frameworks to support.
# frameworks:
#   - UIKit
#   - AppKit

# Enables SwiftUI support.
# swiftui: false

# Key-value pairs of theme colors.
colors:

  accent: # Keys will be used as color names.
    color: "#00BFC2" # Hex color

  # Shorthand syntax
  warning: "#ED4337"

  text_primary:
    light: # Value for light mode
      color: "#000000"
      # Optionally you can specify an alpha value.
      # Defaults to `1.0`.
      alpha: 0.95
    dark: # Value for dark mode
      color: "#FFFFFF"

  text_secondary:
    light:
      color: "#000000"
      alpha: 0.4
    dark:
      color: "#FFFFFF"
      alpha: 0.6

  primary_background:
    description: The color for the main background of your interface.
    light: "#FFFFFF"
    dark:
      # Value for base (non-elevated) level
      base: "#0D0D0D"
      # Value for elevated level
      elevated: "#191D1D"

You can use your favorite text editor to edit the YAML file, then use the build sub-command to generate the Swift code:

$ stylegen build

The generated file will contain all the colors and utility methods for referencing them. You must add this generated file to your Xcode target to use it.

In places where you normally do:

self.backgroundColor = UIColor(named: "AccentColor")

Now you can just do:

self.backgroundColor = .theme(.accent)

The .theme() static method serves as a namespace to easily distinguish between UIKit's built-in colors and our custom colors. The name of the namespacing function gets inferred from the system_name property in the YAML file.

stylegen's People

Contributors

deepsourcebot avatar raymondjavaxx avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.