Giter VIP home page Giter VIP logo

yas's Introduction

YAS Swift License

Logo

YAS is YAML-based stylesheet engine written in Swift.

Installing the framework

cd {PROJECT_ROOT_DIRECTORY}
curl "https://raw.githubusercontent.com/alexdrone/YAS/master/bin/dist.zip" > dist.zip && unzip dist.zip && rm dist.zip;

Drag YAS.framework in your project and add it as an embedded binary.

If you use xcodegen add the framework to your project.yml like so:

targets:
  YOUR_APP_TARGET:
    ...
    dependencies:
      - framework: PATH/TO/YOUR/DEPS/YAS.framework

Getting Started

Let's create a very basic YAML stylesheet and save it in a file named style.yaml.

FooStyle:
  backgroundColor: color(ff0000)
  margin: 10.0

Load it up and use it in your Swift code:

try! Yas.manager.load("style.yaml")
let margin = Yas.lookup.FooStyle.margin //10.0
let backgroundColor = Yas.lookup.FooStyle.backgroundColor //UIColor(...)

Apply a style to a UIView:

view.apply(style: Yas.lookup.FooStyle)

Primitives

Example:
  cgFloat: 42.0
  bool: true
  integer: 42
  # Symbols can be exported by calling ConstExpr.export([:])
  enum: ${NSTextAlignment.right}
  # ${...} is the expression delimiter
  cgFloatExpression: ${41+1}
  boolExpression: ${1 == 1 && true}
  integerExpression: ${41+1}
  # Functions.
  # New functions can be exported by calling FuncExpr.export(...)
  # `color(string [color hexcode])`: Returns a color.
  color: "color(#ff0000)"
  # `font(string [font name or `system`], number [point size])`
  font: font(Arial,42)
  # `systemfont(number [point size], weight [ultralight, thin, ..., black])`
  systemFont: systemfont(12,bold)
  # `animator(number [duration], string [easeIn, easeOut, easeInOut, linear])` or
  # `animator(number [duration], number [damping])`
  animator1: animator(1,easeIn)

References and anchors

By using YAML anchors and references you can reuse values across your stylesheet:

Foo:
  fooValue: &_fooValue 42.0
Bar
  bar: *_fooValue
  baz: 2

You can also copy the whole style using the YAML extension construct:

Foo: &_Foo
  aValue: 42.0
  anotherValue: "Hello"
  someColor: color(#cacaca)
Bar
  <<: *_Foo
  yetAnotherValue: 2

Credits:

Deps forked from:

yas's People

Contributors

alexdrone avatar

Watchers

James Cloos avatar Trending Technology 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.