Giter Club home page Giter Club logo

victor-cli's Introduction

Victor CLI

Gem Version Build Status Maintainability


Command line interface for Victor, the SVG Library.


Installation

$ gem install victor-cli

Usage

init: Create a sample Ruby file

Run this command to create an initial sample file:

$ victor init example

render: Render Ruby to SVG

Given this Ruby code:

# example.rb
setup width: 140, height: 100

build do
  circle cx: 50, cy: 50, r: 30, fill: "yellow"
end

Run this command:

$ victor render example.rb --template minimal

To generate this code:

<svg width="140" height="100">
  <circle cx="50" cy="50" r="30" fill="yellow"/>
</svg>

convert: Convert SVG to Ruby

Given this SVG file:

<!-- example.svg -->
<svg width="140" height="100">
  <circle cx="50" cy="50" r="30" fill="yellow"/>
</svg>

Run this command:

$ victor convert example.svg

To generate this Ruby code:

setup width: 140, height: 100

build do
  circle cx: 50, cy: 50, r: 30, fill: "yellow"
end

victor-cli's People

Contributors

dannyben avatar gingermusketeer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

victor-cli's Issues

Improve Ruby code generation

There are multiple issues with the Ruby code generation:

  1. It creates quoted numeric attributes:
setup width: "100", width: "100"
# instead of the expected
setup width: 100, width: 100
  1. It does not convert attributes-with-hyphens to attributes_with_underscores
g "font-size": 30, "font-family": "arial", fill: "white" do
  # ...
end

Suggestions for additional commands

To make victor-cli more useful, maybe we should consider these:

  • Add victor init [RUBY_FILE] command, that will save a sample - this template should be special - without the svg.save and maybe without the initial Victor::SVG.new.
  • Add victor to-svg RUBY_FILE [SVG_FILE] command that will run and save/generate the Ruby file.
  • Rename the generate command to something like to-ruby to avoid the "what are we generating" confusion.
  • Maybe add victor icodi STRING [SVG_FILE] that generates icodi icon?

@gingermusketeer thoughts?

Error when converting SVG with style or text nodes

Reproduction

Save this as dev/bug.svg:

<svg>
<style type="text/css">
<![CDATA[
  * { color: black }
]]>
</style>

<circle cx="58" cy="32" r="4" fill="black"/>
</svg>

Run this:

$ PRETTY_TRACE=full bundle exec victor to-ruby dev/bug.svg

Get this:

NoMethodError
undefined method `map' for "* { color: black }":String
Did you mean?  tap

Same problem occurs with text nodes:

<svg>
<text x="15" y="15" font-size="14" font-family="Verdana">
  You are
  <tspan fill="red" font-weight="bold">
  not
  </tspan>
  a banana
</text>
</svg>

Improve conversion of style attributes

Need to handle this Victor feature:

If the value of an attribute is a hash, it will be converted to a style-compatible string:

svg.rect x: 0, y: 0, width: 100, height: 100, style: { stroke: '#ccc', fill: 'red' }
# => <rect x=0 y=0 width=100 height=100 style="stroke:#ccc; fill:red"/>

Add `init` command

That will just write a basic template ruby file to current directory.

Consider normalizing CodeGenerator

The CodeGenerator class is the opposite of RubyCode. So perhaps they should be normalized to:

  • Have similar interfaces
  • Have similar names describing what they are, not what they do (RubySource, SVGSource ?)

Comments are converted to the word `comment`

Reproduction code

Use this sample.svg

<svg>
  <!-- this comment is converted to the word 'comment' -->
  <rect x="10" y="10" width="120" height="80"/>
</svg>

Run this:

$ victor to-ruby sample.svg

Get this output:

require "victor"

svg = Victor::SVG.new
svg.build do
  comment   # <-- this should not be here
  rect x: "10", y: "10", width: "120", height: "80"
end

svg.save "generated"

Better handling of errors in userland

When running victor to-svg file.rb on a file with syntax errors, the output is less helpful than it can be:

$ victor to-svg dev/error.rb
NameError: undefined local variable or method `problem' for #<Victor::CLI::RubyCode:0x0000555e08a41aa8>

Running with DEBUG=1 is slightly better, since it shows backtrace, but this is not user friendly and the output is ugly:

$ DEBUG=1 victor to-svg dev/error.rb

This needs some attention.

Improve CSS conversion

CSS is currently not converted properly. This requires some thought as to whether the way Victor itself handles CSS is the best or not, and might require refactoring the Parser + SVGSource classes to work differently.

Also, we might require the aid of some lightweight CSS parser, like the css_parser gem.

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.