All Projects → alexdrone → YAS

alexdrone / YAS

Licence: MIT license
Yet Another Stylesheet (YAML-based Stylesheet Engine)

Programming Languages

swift
15916 projects
c
50402 projects - #5 most used programming language
objective c
16641 projects - #2 most used programming language
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to YAS

Idaskins
Advanced skinning plugin for IDA Pro
Stars: ✭ 832 (+3517.39%)
Mutual labels:  stylesheet
Foleys gui magic
A GUI builder module for JUCE
Stars: ✭ 89 (+286.96%)
Mutual labels:  stylesheet
Qbstyles
QuantumBlack Matplotlib styles
Stars: ✭ 166 (+621.74%)
Mutual labels:  stylesheet
Makegithubgreatagain
Extension for making GitHub great again
Stars: ✭ 1,039 (+4417.39%)
Mutual labels:  stylesheet
Sprite Loader
A image sprite loader for webpack.
Stars: ✭ 82 (+256.52%)
Mutual labels:  stylesheet
Interfacss
The CSS-inspired styling and layout framework for iOS
Stars: ✭ 92 (+300%)
Mutual labels:  stylesheet
Qbt Theme
collection of themes for qbittorrent
Stars: ✭ 776 (+3273.91%)
Mutual labels:  stylesheet
Breezestylesheets
Breeze/BreezeDark-like Qt StyleSheets
Stars: ✭ 221 (+860.87%)
Mutual labels:  stylesheet
Vertical Rhythm
Put some typographical vertical rhythm in your CSS. LESS, Stylus and SCSS/SASS versions included.
Stars: ✭ 83 (+260.87%)
Mutual labels:  stylesheet
Defer.js
🥇 A super small, super efficient library that helps you lazy load everything like images, video, audio, iframe as well as stylesheets, and JavaScript.
Stars: ✭ 138 (+500%)
Mutual labels:  stylesheet
Vanilla Css
A minimal baseline stylesheet for any web project
Stars: ✭ 53 (+130.43%)
Mutual labels:  stylesheet
Extracted Loader
It reloads extracted stylesheets extracted with ExtractTextPlugin
Stars: ✭ 67 (+191.3%)
Mutual labels:  stylesheet
React Native Normalized
Components that behave more consistently between IOS and Android
Stars: ✭ 101 (+339.13%)
Mutual labels:  stylesheet
Motif
Lightweight and customizable stylesheets for iOS
Stars: ✭ 879 (+3721.74%)
Mutual labels:  stylesheet
Styleurl Extension
Share & export CSS tweaks from Chrome instantly.
Stars: ✭ 175 (+660.87%)
Mutual labels:  stylesheet
Fxp Require Asset
Helper of required assets for Twig with Webpack
Stars: ✭ 6 (-73.91%)
Mutual labels:  stylesheet
Glamorous Primitives
💄 style primitive React interfaces with glamorous
Stars: ✭ 91 (+295.65%)
Mutual labels:  stylesheet
get-css-data
A micro-library for collecting stylesheet data from link and style nodes
Stars: ✭ 29 (+26.09%)
Mutual labels:  stylesheet
Sbuttons
💡 Simple buttons you can use easily for your next project.
Stars: ✭ 207 (+800%)
Mutual labels:  stylesheet
Sscss
Light Sass lib for managing your font-size, margin, padding, and position values across breakpoints.
Stars: ✭ 119 (+417.39%)
Mutual labels:  stylesheet

YAS Swift License

Logo

YAS is a 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 are using xcodegen add the framework to your project.yml like so:

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

If you are using Carthage: Add the following line to your Cartfile:

github "alexdrone/YAS" "master"    

Getting Started

Create a new YAML stylesheet and save it in a file named style.yaml.

FooStyle:
  backgroundColor: {_type: color, hex: ff0000}
  margin: 10.0

Load it up and access to its member using the built-in dynamic lookup proxy.

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

or automatically apply the style to your UIView:

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

Built-in types

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}
  # Custom objects.
  # Use the reserved _type attribute to distinguish the object type.
  # New object types can be exported by calling ObjectExpr.export(...)
  # {_type: color, hex: ffffff, (darken: [0-100]), (lighten: [0-100]), (alpha: [0-1])}
  color: {_type: color, hex: ff0000}
  # {_type: font, (name: [fontname]), size: [size], (weight: [light...])}
  font:  {_type: font, name: Arial, size: 42}
  fontWeight: {_type: font, weight: bold, size: 12}
  # {_type: animator, duration: 1, (curve: [easeIn...]), (damping: [0-1])}
  animator: {_type: animator, curve: easeIn, duration: 1}
  # {_type: text,  (name: [fontname]), size: [size], (weight: [light...]), (kern: [0..n]), (hex: [hex colorcode]), (supportDynamicType: [bool])}
  textStyle: {_type: text, name: Arial, size: 42, kern: 2, hex: ff0000}

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: {_type: color, hex: ff0000}
Bar:
  <<: *_Foo
  yetAnotherValue: 2

Real life example

Palette:
  primaryColorHex: &_primaryColorHex ff0000
  primaryColor: &_primaryColor {_type: color, hex: *_primaryColorHex}
  primaryColor600: &_primaryColor600 {_type: color, hex: *_primaryColorHex, darken: 10}
  primaryColor700: &_primaryColor700 {_type: color, hex: *_primaryColorHex, darken: 20}
Typography:
  primaryFontName: &_primaryFontName "Open Sans"
  secondaryFontName: &_secondaryFontName "Rubik"
  body1: &_body1 {_type: attributedString, name: *_secondaryFontName, size: 14.26, kern: 0.25, color: *_primaryColorHex}
  body2: &_body2 {_type: attributedString, weight: medium, size: 12.22, kern: 0.5, color: *_primaryColorHex}
LandingPage:
  titleText: *_body1
  backgroundColor: *_primaryColor600
  topMargin: 12
  shouldHideHero: ${horizontalSizeClass == compact}
  tileSize: ${screenSize.width/2 - 8}  

Cascade imports

Stylesheets can be split into smaller modules by using the import rule at the top of the main stylesheet file.

import: [typography.yaml, palette.yaml, buttons.yaml]

Custom types

You can define your own custom object expressions by creating a new ObjectExpr subclass.

@objc class MyCustomObjectExpression : ObjectExprBase {
  // Your arguments must be marked with @obj and dynamic.
  @objc dynamic var foo: Int = 0
  @objc dynamic var bar: String = ""

  override func eval() -> Any? {
    // Build your desired return types
    return MyCustomObject(foo: foo, bar: bar)
  }
}

Finally register your ObjectExpr in the shared ObjectExprRegistry.

StylesheetContext.objectExpr.export(ObjectExprFactory(
  type: MyCustomObjectExpression.self,
  name: "myObject")

Use your custom define object expression in any stylesheet rule.

MyStyle:
  myCustomRule: {_type: myObject, foo: 42, bar: "Hello"}

Reacting to stylesheet changes

Notification.Name.StylesheetContextDidChange is posted whenever the stylesheet has been reloaded.

Dependencies and credits

Deps forked from:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].