Skip to content

Commit

Permalink
Merge branch 'master' into feature/compiler_options
Browse files Browse the repository at this point in the history
  • Loading branch information
veelenga committed Feb 29, 2016
2 parents fdc493d + 29e9e2a commit c3029bd
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 15 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# vicr [![Build Status](https://travis-ci.org/veelenga/vicr.svg?branch=master)](https://travis-ci.org/veelenga/vicr)
<img src="https://github.com/veelenga/ss/blob/master/vicr/logo.png" width="200">

[![Build Status](https://travis-ci.org/veelenga/vicr.svg?branch=master)](https://travis-ci.org/veelenga/vicr)

Vicr stands for **"Vim-like Interactive CRystal"** and represents a tiny command line application
that designed to quickly execute Crystal code with fast feedback and options to proceed:

![](https://media.githubusercontent.com/media/veelenga/ss/master/vicr/demo.gif)
![](https://raw.githubusercontent.com/veelenga/ss/master/vicr/demo.gif)

## Installation

Expand Down Expand Up @@ -35,10 +37,16 @@ For example:
```sh
# loads local file
$ vicr src/vicr/cli.cr

# loads Github file
$ vicr https://github.com/manastech/crystal/blob/master/samples/2048.cr

# loads Github gist
$ vicr https://gist.github.com/veelenga/a5b861ccd32ff559b7d2#file-benchmark_test-cr

# loads CarcIn file
$ vicr https://carc.in/#/r/rlj

# loads raw file
$ vicr http://example.com/program.cr
```
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: vicr
version: 0.3.1
version: 0.4.0

authors:
- Vitalii Elenhaupt <velenhaupt@gmail.com>
Expand Down
16 changes: 16 additions & 0 deletions spec/vicr/carc_in_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "../spec_helper"

module Vicr
describe CarcIn do
describe ".raw" do
it "returns path to raw file on carc.in" do
CarcIn.raw("https://carc.in/#/r/rlc")
.should eq "https://carc.in/runs/rlc.cr"
end

it "returns nil if this is not carc.in path" do
CarcIn.raw("https://github.com/test/test.cr").should be_nil
end
end
end
end
17 changes: 17 additions & 0 deletions spec/vicr/github_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "../spec_helper"

module Vicr
describe Github do
describe ".raw" do
it "returns path to raw file on github" do
Github.raw("https://github.com/user/repo/blob/master/file.cr")
.should eq "https://raw.githubusercontent.com/user/repo/master/file.cr"
end

it "returns nil if this is not github path" do
Github.raw("https://example.com/user/repo/blob/master/file.cr")
.should eq nil
end
end
end
end
4 changes: 0 additions & 4 deletions spec/vicr_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
require "./spec_helper"

describe Vicr do
# TODO: Write tests
end
11 changes: 11 additions & 0 deletions src/vicr/carc_in.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Vicr
module CarcIn
extend self

def raw(path : String)
if md = path.match /carc.in\/.*\/.*\/(.*)/
"https://carc.in/runs/#{md[1]}.cr"
end
end
end
end
5 changes: 3 additions & 2 deletions src/vicr/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require "json"

module Vicr
class Cli

def self.run(args = ARGV)
Cli.new.run(args)
end
Expand Down Expand Up @@ -39,11 +40,11 @@ module Vicr
private def load_file(path : String)
buffer = File.read path if File.exists? path
buffer ||= load_http_file path if path.starts_with? "http"
buffer ? buffer : raise "Unable to load file '#{path}'"
buffer || raise "Unable to load file '#{path}'"
end

private def load_http_file(path : String)
raw = Github.raw(path) || Github.gist_raw(path, "Crystal") || path
raw = Github.raw(path) || Github.gist_raw(path, "Crystal") || CarcIn.raw(path) || path
resp = HTTP::Client.get raw
resp.status_code == 200 ? resp.body : nil
end
Expand Down
12 changes: 7 additions & 5 deletions src/vicr/github.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ require "json"
require "levenshtein"

module Vicr
class Github
def self.raw(path : String)
module Github
extend self

def raw(path : String)
if md = path.match /github.com\/(.*)\/(.*)\/blob\/(.*)\/(.*)/
user, repo, branch, file = md[1], md[2], md[3], md[4]
"https://raw.githubusercontent.com/#{user}/#{repo}/#{branch}/#{file}"
end
end

def self.gist_raw(path : String, language = nil : String)
def gist_raw(path : String, language = nil : String)
path, filename = path.split("#file-") + [nil]
if path && (md = path.match /gist.github.com\/.*\/(.*)/)
files = gist_files md[1]
Expand All @@ -25,13 +27,13 @@ module Vicr
end
end

private def self.gist(id : String)
private def gist(id : String)
resp = HTTP::Client.get "https://api.github.com/gists/" + id
return JSON.parse(resp.body) if resp.status_code == 200
raise ArgumentError.new "Gist with id '#{id}' not found"
end

private def self.gist_files(id : String)
private def gist_files(id : String)
gist_files = [] of Hash(Symbol, String)
gist(id)["files"].each do |file, value|
gist_files << {
Expand Down
2 changes: 1 addition & 1 deletion src/vicr/version.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Vicr
VERSION = "0.3.1"
VERSION = "0.4.0"
end

0 comments on commit c3029bd

Please sign in to comment.