Giter Club home page Giter Club logo

salsa's Introduction

Carthage compatible CocoaPods Compatible

What is Salsa?

Salsa is an open source library that renders iOS views and exports them into a Sketch file. We built Salsa to help bridge the gap between design and engineering in an effort to create a single source of truth for visual styling of UI.

How it works

Running Salsa inside of an iOS simulator will output two things into a specified directory: a .salsa file and an images folder. You can then pass these two inputs into the salsa command line tool to compile them into a .sketch file.

Why two steps?

Certain macOS-only APIs need to be used to encode text for .sketch files. Having two steps allows us to define our own intermediate file format that’s easier to work with than the full sketch file format. This means we can leverage this file format in the future if we want to expand this tool for other platforms.

Installing Salsa

Cocoapods

pod 'Salsa'

Carthage

github 'Yelp/salsa'

Homebrew

brew tap yelp/salsa
brew install salsa

Using Salsa

import Salsa
Converting a view to a Sketch Group
// Configure the export directory
SalsaConfig.exportDirectory = "/some_directory"

// Convert a view into a group
let myGroup = myView.makeSketchGroup()
Putting a group into a sketch document and exporting to a salsa file
// Create a page containing the generated group, and insert it into a Document
let document = Document(pages: [Page(layers: [myGroup])])

// Export the document to disk
try? document.export(fileName: "my_file")
Converting a salsa file to a sketch file

In your terminal of choice run the following:

$ salsa -f /some_directory/my_file.salsa -e /some_directory/my_file.sketch

Creating a Sketch file documenting your standard UI elements

We provide some helpers to help you document your elements out of the box. You organize examples of your views into an Artboard by conforming your view class to ArtboardRepresentable.

extension View1: ArtboardRepresentable {
  static func artboardElements() -> [[ArtboardElement]] {
    ...
  }
}

If you would like to also create Symbols of your views to go along with the generated Artboards you can instead conform your views to SymbolRepresentable.

extension View2: SymbolRepresentable {
  static func artboardElements() -> [[ArtboardElement]] {
    ...
  }
}

Create your Artboards and Symbols from these ArtboardRepresentable and SymbolRepresentable views

// Configure the export directory
SalsaConfig.exportDirectory = "/some_directory"

// Generate the artboards and symbols
let artboardsAndSymbols = makeArtboardsAndSymbols(from: [[View1.self], [View2.self]])

// Put the artboards and symbols onto their own dedicated pages
let artboardPage = Page(name: "Artboards", layers: artboardsAndSymbols.artboards)
let symbolPage = Page(name: "Symbols", layers: artboardsAndSymbols.symbols)

// Create a document with the generated pages and export it
let document = Document(pages: [artboardPage, symbolPage])
try? document.export(fileName: "my_file")

Example Project

Check out the Example project to see how Sasla can be used in production. The Example app uses a test target to generate Sketch files without manually launching Xcode.

To generate a Sketch file for the Example project run the following after cloning the repo:

cd Example
pod install
./generate_sketch

This should create a new file called ExampleSketch.sketch inside the project directory

Open up generate_sketch with a text editor to see how this is done.

Documentation

For a full breakdown of the Salsa API check out the docs

salsa's People

Contributors

altonlau avatar elliottwilliams avatar mrabiciu 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salsa's Issues

Can not create Sketch file from Example's generate_sketch

Following the directions here: README Link

I get this output upon running generate_sketch:

Fatal error: Could not find font: SFProText-Semibold: file /Users/~/Developer/salsa/SalsaCompiler/SalsaCompiler/SketchJson/Text+SketchJson.swift, line 76
./generate_sketch: line 19: 10945 Illegal instruction: 4  ../SalsaCompiler/build/Release/salsa -f /tmp/SalsaExample/generated.salsa -e ExampleSketch
Failed to build sketch file

I'm wondering if this is because of version mismatch? I had to update generate_sketch's first xcodebuild command. I changed the simulator to iOS 11.3, since Xcode 9.3 does not support the 10.3.1 simulator.

Versions:
xcodebuild: 9.3
Cocoapods: 1.5.0

Add the ability to snap instance of view?

First of all, thanks for the hard work!

Would like to know your opinion on adding new set of APIs to Salsa for capturing UIView instance conveniently. Seems like the current code forces us to instantiate new UIView instances and return them via static function:

static func artboardElements() -> [[ArtboardElement]] 

One usecase of this is to allow it to snap views during the UI automation. I experimented with it to generate Sketch file as visual documentation of an app (removing filtering/purging to keep exact copy of view hierarchies).

The additional APIs could be something like what I did there:
https://github.com/aunnnn/salsa-AutoSketch/blob/master/Salsa/Salsa%2BAutoSketch.swift

Unable to run sample project ?

Its giving pod installation error like below,

Analyzing dependencies
[!] Unable to find a specification for Salsa

[!] Automatically assigning platform ios with version 11.3 on target Salsa because no platform was specified. Please specify a platform for this target in your Podfile. See https://guides.cocoapods.org/syntax/podfile.html#platform.

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.