computering 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9efa6d55cd4edf4da0ff1bf5c1ab415973b9cdc0
4
- data.tar.gz: 3f125e492b6ca53f7e011a044488ff4a0d2d00da
3
+ metadata.gz: 7c68086d104fb3bed1f55ac98d5125ae49425a39
4
+ data.tar.gz: 7c5863b2754e9976309ff05a49dd3700766e0947
5
5
  SHA512:
6
- metadata.gz: 296528c1d1c84523f13a57366e38143a856db47ef4334bb2a900f3d3c7c7649ad268adc0897de24a7e36e285bd97fe2da8034e6196b0bf8bd1d5fc319d68c536
7
- data.tar.gz: cb578a23be60309645c8dcf33e7b9438b90d4c07a978cc17af8bbcbabd00215e113b97d1dc1ba8c4140b8654a2c695519dd3d6cdbc1aa8b709e70966054556fa
6
+ metadata.gz: ebbdd7570a201575f677b467a6dbb0b9279721d1158e4464857dd084a7ee1db6b5f306d14135dee99ba872476bb79ffa066cb967c8b289f50bfc4fae4ab552ff
7
+ data.tar.gz: 43d10ef29b3bc8f2a7ccc3d4b5f9b6bae2f3d82a550c39896440f6c74c3d8048e134306df0f87c91b28c1f973ab9d23661e392dd6a2ccd63ed50ac9dd2bd2eeb
@@ -0,0 +1,3 @@
1
+ script: "bundle exec rake"
2
+ rvm:
3
+ - 2.0.0-p247
data/README.md CHANGED
@@ -24,7 +24,7 @@ echo "
24
24
  headline 'computering'
25
25
  paragraph 'is super easy'
26
26
  command 'echo to use'
27
- link 'see yourself', 'https://github.com/phoet/computering'
27
+ link 'see yourself', 'https://github.com/phoet/computering#usage'
28
28
  " > preso.rb
29
29
  ```
30
30
 
@@ -39,7 +39,6 @@ computering preso.rb
39
39
  * syntax-check
40
40
  * dry-mode
41
41
  * config speed
42
- * add styling
43
42
 
44
43
  # License
45
44
 
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "test/**/*_test.rb"
6
+ end
7
+
8
+ task default: :test
@@ -2,7 +2,7 @@
2
2
  lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
3
3
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
4
4
 
5
- require "Computering"
5
+ require "computering"
6
6
 
7
7
  abort "USAGE: computering file [file ...]" if ARGV.empty?
8
8
 
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "rainbow", "> 1.0"
21
+ spec.add_dependency "sorcerer"
22
+ spec.add_dependency "minitest"
21
23
 
22
24
  spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rspec"
24
25
  spec.add_development_dependency "rake"
25
26
  end
@@ -1,7 +1,23 @@
1
+ configure do
2
+ # changes styles described here: https://github.com/sickill/rainbow#features
3
+ self.style = {
4
+ headline: {
5
+ text: "-".background(:green),
6
+ buffer: "-".background(:blue),
7
+ }
8
+ }
9
+ end
10
+
1
11
  headline 'computering'
2
12
 
3
13
  paragraph 'is super easy'
4
14
 
5
15
  command 'echo to use'
6
16
 
7
- link 'see yourself', 'https://github.com/phoet/computering'
17
+ spec "runs spec" do
18
+ it "even runs your spec with minitest" do
19
+ true.must_equal true
20
+ end
21
+ end
22
+
23
+ link 'see yourself', 'https://github.com/phoet/computering#usage'
@@ -0,0 +1,23 @@
1
+ paragraph 'hi, i am peter, member of señor developer crew'
2
+ paragraph '@phoet on twitter and on github'
3
+ paragraph 'i pretend to type incredible fast'
4
+
5
+ headline 'SO CODED'
6
+
7
+ paragraph 'A Web Conference in Hamburg'
8
+
9
+ headline 'SAVE the DATE'
10
+
11
+ paragraph '19. & 20. Sept. 2013'
12
+
13
+ headline 'VENUE'
14
+
15
+ paragraph 'LOLA Hamburg Bergedorf'
16
+
17
+ headline 'LINEUP'
18
+
19
+ list "Jessica Allen (Engine Yard)", "Jason Costello (GitHub)", "Chad Fowler (6Wunderkinder)"
20
+
21
+ headline 'interwebs'
22
+
23
+ link '@socodedconf', 'http://socoded.com/'
@@ -1,9 +1,14 @@
1
1
  require "rainbow"
2
2
 
3
3
  require "computering/version"
4
+ require "computering/config"
4
5
  require "computering/dsl"
5
6
  require "computering/dsl/text"
6
- require "computering/dsl/command"
7
7
  require "computering/dsl/headline"
8
+ require "computering/dsl/list"
8
9
  require "computering/dsl/link"
10
+ require "computering/dsl/command"
11
+ require "computering/dsl/spec"
12
+ require "computering/code_parser"
13
+ require "computering/container"
9
14
  require "computering/cmd"
@@ -4,27 +4,19 @@ module Computering
4
4
  class Cmd
5
5
  class Exit < StandardError; end
6
6
 
7
- include Computering::Dsl
8
-
9
7
  CONTROL_C = 3
10
8
  ENTER = 13
11
9
 
12
10
  def initialize(file, stdin = STDIN, stdout = STDOUT)
13
- @file = file
14
- @stdin = stdin
15
- @stdout = stdout
16
- @code = File.readlines(file).join "\n"
17
-
18
- instance_eval @code
11
+ @file = file
12
+ @stdin = stdin
13
+ @stdout = stdout
14
+ @container = Container.new File.read(file)
19
15
  end
20
16
 
21
17
  def execute
22
- items.each do |item|
23
- if item.blank?
24
- @stdout.puts
25
- else
26
- readchars item
27
- end
18
+ @container.items.each do |item|
19
+ readchars item unless item.blank?
28
20
  end
29
21
  end
30
22
 
@@ -36,10 +28,11 @@ module Computering
36
28
  if char.ord == ENTER
37
29
  @stdout.puts item[i..-1]
38
30
  item.execute
39
- @stdout.puts item.buffer
31
+ @stdout.puts item.buffer if item.buffer
32
+ @stdout.puts item.padding if item.padding
40
33
  break
41
34
  else
42
- @stdout.putc item[i] if item[i]
35
+ @stdout.write item[i] if item[i]
43
36
  i += 1
44
37
  end
45
38
  end
@@ -0,0 +1,31 @@
1
+ require "ripper"
2
+ require "sorcerer"
3
+
4
+ module Computering
5
+ class CodeParser
6
+ attr_reader :blocks
7
+
8
+ def initialize(code)
9
+ @sexp = Ripper::SexpBuilder.new(code).parse
10
+ @blocks = {}
11
+ walk(@sexp)
12
+ end
13
+
14
+ def walk(sexp, last=nil)
15
+ sexp.each do |item|
16
+ if item.is_a? Array
17
+ walk(item, sexp)
18
+ elsif item == :command
19
+ next_item = sexp[1]
20
+ token, name, _ = next_item
21
+ if token == :@ident && name == "spec"
22
+ block_sexp = last.last.last
23
+ code = Sorcerer.source(block_sexp, multiline: true, indent: true)
24
+ name = sexp.last[1].last.last.last[1]
25
+ @blocks[name] = code
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ module Computering
2
+ class Config
3
+ @style_defaults = {
4
+ text: {
5
+ text: "-",
6
+ buffer: "-",
7
+ },
8
+ list: {
9
+ text: "-",
10
+ bullet: "-".color(:green),
11
+ },
12
+ headline: {
13
+ text: "-".background(:red),
14
+ buffer: "-".background(:red),
15
+ },
16
+ link: {
17
+ text: "-".color(:black).background(:cyan),
18
+ cursor: "-".color(:green),
19
+ error: "-".background(:red),
20
+ },
21
+ command: {
22
+ text: "-".color(:black).background(:cyan),
23
+ cursor: "-".color(:green),
24
+ buffer: "-".bright,
25
+ error: "-".color(:red),
26
+ },
27
+ spec: {
28
+ text: "-".foreground(:green),
29
+ buffer: "-".bright,
30
+ error: "-".color(:red),
31
+ },
32
+ }
33
+ @style = @style_defaults.dup
34
+
35
+ class << self
36
+ attr_accessor :style
37
+
38
+ def styling(text, id, type)
39
+ style_defaults(id, type).gsub("-", text)
40
+ end
41
+
42
+ def style_defaults(id, type)
43
+ default = @style_defaults[id][type] || "-"
44
+ (style[id] && style[id][type]) ? style[id][type] : default
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ module Computering
2
+ class Container
3
+ include Computering::Dsl
4
+
5
+ def initialize(code)
6
+ @source = CodeParser.new(code)
7
+
8
+ instance_eval code
9
+ end
10
+
11
+ protected
12
+
13
+ def block_source(name)
14
+ @source.blocks[name].strip
15
+ end
16
+ end
17
+ end
@@ -1,14 +1,26 @@
1
1
  module Computering
2
2
  module Dsl
3
- def headline(text)
3
+ def spec(name, &block)
4
+ self.items += Spec.from_block(name, block_source(name), &block)
5
+ end
6
+
7
+ def configure(&block)
8
+ Config.instance_eval(&block)
9
+ end
10
+
11
+ def list(*text)
12
+ self.items += List.from_text(text)
13
+ end
14
+
15
+ def headline(*text)
4
16
  self.items += Headline.from_text(text)
5
17
  end
6
18
 
7
- def paragraph(text)
19
+ def paragraph(*text)
8
20
  self.items += Text.from_text(text)
9
21
  end
10
22
 
11
- def command(text)
23
+ def command(*text)
12
24
  self.items += Command.from_text(text)
13
25
  end
14
26
 
@@ -16,8 +28,6 @@ module Computering
16
28
  self.items += Link.from_text(text, link)
17
29
  end
18
30
 
19
- protected
20
-
21
31
  def items
22
32
  @items ||= []
23
33
  end
@@ -2,24 +2,23 @@ require "bundler"
2
2
 
3
3
  module Computering::Dsl
4
4
  class Command < Text
5
- def initialize(cmd)
6
- @text = " #{'⌘'.color(:green)} #{cmd.color(:black).background(:cyan)}"
7
- @buffer = ""
8
- @cmd = cmd
9
- end
10
-
11
5
  def execute
12
- output = ""
6
+ @buffer = "\n"
13
7
  Bundler.with_clean_env do
14
- output = `#{@cmd}`
8
+ @buffer << `#{@text}`.chomp
15
9
  end
16
- @buffer = "\n#{output}\n"
17
10
  rescue
18
- puts $!
11
+ @buffer << add_style($!.message, :error)
19
12
  end
20
13
 
21
- def self.from_text(cmd)
22
- Array(self.new cmd)
14
+ protected
15
+
16
+ def text_with_style(text, index)
17
+ text = add_style(text, :text)
18
+ if index == 0 || index == (0..-1)
19
+ text = " #{add_style('⌘', :cursor)} #{text}"
20
+ end
21
+ text
23
22
  end
24
23
  end
25
24
  end
@@ -1,8 +1,7 @@
1
1
  module Computering::Dsl
2
2
  class Headline < Text
3
- def initialize(text)
4
- @text = text.background(:red)
5
- @buffer = "#{'=' * text.size}\n\n".foreground(:red)
3
+ def buffer
4
+ add_style('=' * @text.size, :buffer)
6
5
  end
7
6
  end
8
7
  end
@@ -1,19 +1,39 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Computering::Dsl
2
3
  class Link < Text
4
+ def self.from_text(text, link)
5
+ Array(self.new text, link)
6
+ end
7
+
3
8
  def initialize(text, link)
4
- @text = " #{'☞'.color(:green)} #{text}"
5
- @link = link
6
- @buffer = ''
9
+ super text
10
+ @link = link
7
11
  end
8
12
 
9
13
  def execute
10
- `open '#{@link}'`
14
+ `#{command_by_os} '#{@link}'`
11
15
  rescue
12
- puts $!
16
+ @buffer = add_style($!.message, :error)
13
17
  end
14
18
 
15
- def self.from_text(text, link)
16
- Array(self.new text, link)
19
+ protected
20
+
21
+ def text_with_style(text, index)
22
+ text = add_style(text, :text)
23
+ if index == 0 || index == (0..-1)
24
+ text = " #{add_style('☞', :cursor)} #{text}"
25
+ end
26
+ text
27
+ end
28
+
29
+ private
30
+
31
+ def command_by_os
32
+ if (/linux/ =~ RUBY_PLATFORM)
33
+ "xdg-open"
34
+ else
35
+ "open"
36
+ end
17
37
  end
18
38
  end
19
39
  end
@@ -0,0 +1,13 @@
1
+ module Computering::Dsl
2
+ class List < Text
3
+ protected
4
+
5
+ def text_with_style(text, index)
6
+ text = add_style(text, :text)
7
+ if index == 0 || index == (0..-1)
8
+ text = " #{add_style('*', :bullet)} #{text}"
9
+ end
10
+ text
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,49 @@
1
+ require "minitest"
2
+ require "minitest/spec"
3
+ require "stringio"
4
+
5
+ module Minitest
6
+ class SummaryReporter < StatisticsReporter
7
+ def start
8
+ # REM (ps) monkeypatch it so that there is not so much verbose output
9
+ super
10
+ self.sync = io.respond_to? :"sync="
11
+ self.old_sync, io.sync = io.sync, true if self.sync
12
+ end
13
+ end
14
+ end
15
+
16
+ module Computering::Dsl
17
+ class Spec < Text
18
+ def self.from_block(name, text, &block)
19
+ Array(self.new name, text, &block)
20
+ end
21
+
22
+ def initialize(name, text, &block)
23
+ super text
24
+ @name = name
25
+ @block = block
26
+ @buffer = "\n"
27
+ end
28
+
29
+ def execute
30
+ describe @name, &@block
31
+
32
+ output = StringIO.new("")
33
+ reporter = Minitest::SummaryReporter.new(output)
34
+
35
+ reporter.start
36
+
37
+ Minitest::Runnable.runnables.each do |runnable|
38
+ runnable.run reporter
39
+ end
40
+
41
+ reporter.report
42
+
43
+ @buffer << output.string.strip
44
+ Minitest::Test.reset
45
+ rescue
46
+ @buffer << add_style($!.message, :error)
47
+ end
48
+ end
49
+ end
@@ -1,27 +1,46 @@
1
1
  module Computering::Dsl
2
2
  class Text
3
- def initialize(text)
3
+ def self.from_text(*text)
4
+ text.flatten.map do |t|
5
+ t.strip.split("\n").map { |line| self.new(line) }
6
+ end.flatten
7
+ end
8
+
9
+ attr_reader :text
10
+
11
+ def initialize(text, buffer = nil)
4
12
  @text = text
5
- @buffer = ""
13
+ @buffer = buffer
6
14
  end
7
15
 
8
16
  def [](index)
9
- @text[index]
17
+ text_with_style(@text[index], index) if @text[index]
10
18
  end
11
19
 
12
20
  def execute
13
21
  end
14
22
 
15
23
  def buffer
16
- @buffer
24
+ add_style(@buffer, :buffer) if @buffer
25
+ end
26
+
27
+ def padding
28
+ "\n"
17
29
  end
18
30
 
19
31
  def blank?
20
32
  @text.nil? || @text.strip == ""
21
33
  end
22
34
 
23
- def self.from_text(text)
24
- text.strip.split("\n").map { |line| self.new(line) }
35
+ protected
36
+
37
+ def text_with_style(text, index)
38
+ add_style(text, :text)
39
+ end
40
+
41
+ def add_style(text, type)
42
+ id = self.class.name.split("::").last.downcase.to_sym
43
+ Computering::Config.styling(text, id, type)
25
44
  end
26
45
  end
27
46
  end
@@ -1,3 +1,3 @@
1
1
  module Computering
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,25 @@
1
+ require_relative "test_helper"
2
+
3
+ module Computering
4
+ describe Config do
5
+ describe "style" do
6
+ before do
7
+ Config.style = {}
8
+ end
9
+
10
+ it "has defaults" do
11
+ assert_equal Hash, Config.style.class
12
+ end
13
+
14
+ it "applies styles to text" do
15
+ assert_equal "-", Config.style_defaults(:text, :text)
16
+ assert_equal "-".color(:green), Config.style_defaults(:command, :cursor)
17
+ end
18
+
19
+ it "can override styles" do
20
+ Config.style = {command: {cursor: "-".color(:blue)}}
21
+ assert_equal "-".color(:blue), Config.style_defaults(:command, :cursor)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "../test_helper"
2
+
3
+ module Computering::Dsl
4
+ describe Text do
5
+ describe "char access" do
6
+ before do
7
+ @item = Text.new "txt"
8
+ end
9
+
10
+ it "gets each character" do
11
+ assert_equal "t", @item[0]
12
+ assert_equal "x", @item[1]
13
+ assert_equal "t", @item[2]
14
+ assert_equal "txt", @item[0..-1]
15
+ end
16
+ end
17
+
18
+ describe "initalization" do
19
+ before do
20
+ @item = Text.new ""
21
+ end
22
+
23
+ it "has defaults" do
24
+ assert_equal true, @item.blank?
25
+ assert_equal "\n", @item.padding
26
+ assert_equal nil, @item.buffer
27
+ assert_equal nil, @item.execute
28
+ end
29
+
30
+ it "inits from string" do
31
+ items = Text.from_text("bla\nblupp")
32
+ assert_equal 2, items.size
33
+ assert_equal "bla", items[0].text
34
+ assert_equal "blupp", items[1].text
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
3
+
4
+ require 'minitest/autorun'
5
+ require 'computering'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: computering
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schröder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -25,33 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: sorcerer
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
34
- type: :development
33
+ version: '0'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -75,23 +89,30 @@ extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
91
  - .gitignore
78
- - .rspec
92
+ - .travis.yml
79
93
  - Gemfile
80
94
  - README.md
81
95
  - Rakefile
82
96
  - bin/computering
83
97
  - computering.gemspec
84
98
  - example/preso.rb
99
+ - example/socoded.rb
85
100
  - lib/computering.rb
86
101
  - lib/computering/cmd.rb
102
+ - lib/computering/code_parser.rb
103
+ - lib/computering/config.rb
104
+ - lib/computering/container.rb
87
105
  - lib/computering/dsl.rb
88
106
  - lib/computering/dsl/command.rb
89
107
  - lib/computering/dsl/headline.rb
90
108
  - lib/computering/dsl/link.rb
109
+ - lib/computering/dsl/list.rb
110
+ - lib/computering/dsl/spec.rb
91
111
  - lib/computering/dsl/text.rb
92
112
  - lib/computering/version.rb
93
- - spec/computering/dsl/text_spec.rb
94
- - spec/spec_helper.rb
113
+ - test/config_test.rb
114
+ - test/dsl/text_test.rb
115
+ - test/test_helper.rb
95
116
  homepage: https://github.com/phoet/computering
96
117
  licenses:
97
118
  - THE (extended) BEER-WARE LICENSE
@@ -117,6 +138,7 @@ signing_key:
117
138
  specification_version: 4
118
139
  summary: pretends you could type really fast
119
140
  test_files:
120
- - spec/computering/dsl/text_spec.rb
121
- - spec/spec_helper.rb
141
+ - test/config_test.rb
142
+ - test/dsl/text_test.rb
143
+ - test/test_helper.rb
122
144
  has_rdoc:
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
@@ -1,12 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Computering::Dsl
4
- describe Text do
5
- context "initialization" do
6
- it "inits from a paragraph" do
7
- items = Text.from_text(TEXT)
8
- items.should have(3).items
9
- end
10
- end
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- require "computering"
2
-
3
- RSpec.configure do |config|
4
- config.treat_symbols_as_metadata_keys_with_true_values = true
5
- config.run_all_when_everything_filtered = true
6
- config.filter_run :focus
7
- end
8
-
9
- TEXT = <<-PARAGRAPH
10
- Hallo leute,
11
-
12
- wie geht es euch?
13
- PARAGRAPH