cat_ 0.0.1 → 0.1.0

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: 56fbc54d4e1276d0697f23bf81924ad9ab1f87ae
4
- data.tar.gz: 7f1530f84e4953a11ceade46ba194310b4106fcd
3
+ metadata.gz: bb5f603f6636c29a42b27ee5d18219ec1bcb1f96
4
+ data.tar.gz: 871847c23294bf53fdb126cbde597795e28903a3
5
5
  SHA512:
6
- metadata.gz: 65fa9ef714e5a84e6a1f2a25c28e5b43aa08c585e0189617addbd10172097cfe0b0683619fe0539371f2e458f2fe9622dd299cbc3ade649cc3970983aa9b7d07
7
- data.tar.gz: f9b2e4ef9d84f0cd2bff1891b3651269d696417d225d290663e564f1233e7b6b4e1db744788a8b7d7032348e6490697518389537f037c6267941c4225bcf71b0
6
+ metadata.gz: b7d2a1b3c52f93d9a2e869ef8f4b078f323bfd2610a02f751f3034282865283ad89c4090e3caa1f5db08fa7e1eaa661da21b6be84df7c3180d16caf975de796e
7
+ data.tar.gz: bfe155ae99d300dc18d839d3da025afd1c79ad433d3466d301fd89b910a1946a43ac88d6ec0e9f2b7f2287c462de603ff7e230c8595d555dff6415aec94ad29f
data/exe/cats CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  require 'rack'
4
4
  require 'optparse'
5
- require 'cat/version'
5
+ require 'cat'
6
6
  require 'cat/server'
7
7
 
8
8
  options = {
@@ -27,12 +27,13 @@ OptionParser.new do |opts|
27
27
  opts.on("-s", "--server SERVER", "Set Cat Server engine") { |name| handlers.unshift(name.to_s) }
28
28
  opts.on("-o", "--host HOST", "Set Cat Base address") { |host| options[:Host] = host.to_s; puts host }
29
29
  opts.on("-p", "--port PORT", "Set Cat Tunnel number") { |port| options[:Port] = port.to_i }
30
- opts.on("-F", "--file FILE", "Set Cat define file path") { |file| require File.join(Dir.pwd, file || "cat.rb") }
30
+ opts.on("-F", "--file FILE", "Set Cat define file path") { |file| Cat.config_file(file) }
31
31
 
32
32
  opts.parse! ARGV
33
33
  end
34
34
 
35
35
  begin
36
+ load Cat.config_file
36
37
  Rack::Handler.default.run Cat::Server, options
37
38
  rescue LoadError => e
38
39
  STDERR.puts e
data/lib/cat.rb CHANGED
@@ -1,5 +1,25 @@
1
1
  require "cat/version"
2
+ require 'cat/engine'
2
3
 
3
4
  module Cat
4
- # Your code goes here...
5
+ def self.instance
6
+ @instance ||= Cat::Engine.new
7
+ end
8
+
9
+ def self.summon(&block)
10
+ Cat.instance.instance_eval(&block)
11
+ end
12
+
13
+ def self.config_file(catfile = nil)
14
+ return @catfile || File.join(Dir.pwd, "cat.rb") if catfile.nil?
15
+ @catfile = File.join(Dir.pwd, catfile)
16
+ end
17
+
18
+ def self.to_html
19
+ Cat.instance.to_html
20
+ end
21
+
22
+ def self.to_css
23
+ Cat.instance.to_css
24
+ end
5
25
  end
data/lib/cat/engine.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'cat/skeleton'
2
+ require 'cat/skin'
3
+
4
+ module Cat
5
+ class Engine
6
+ def initialize
7
+ @skin = Skin.new
8
+ @skeleton = Skeleton.new(@skin)
9
+ end
10
+
11
+ def skeleton(skeleton = nil, &block)
12
+ @skeleton = skeleton unless skeleton.nil?
13
+ @skeleton.update(&block) if block_given?
14
+ end
15
+
16
+ def skin(&block)
17
+ @skin.instance_eval(&block)
18
+ end
19
+
20
+ def to_html
21
+ @skeleton.generate
22
+ end
23
+
24
+ def to_css
25
+ @skin.generate(from: @skeleton)
26
+ end
27
+ end
28
+ end
data/lib/cat/server.rb CHANGED
@@ -1,7 +1,37 @@
1
1
  module Cat
2
2
  class Server
3
+ ACCEPT_PATH = ["/", "/skin.css"]
4
+
3
5
  def self.call(env)
4
- [200, {"Content-Type" => "text/plain"}, ["Hello World"]]
6
+ return [404, {"Content-Type" => "text/plain"}, ["No cats found"]] unless ACCEPT_PATH.include?(env['PATH_INFO'])
7
+
8
+ @last_update ||= Time.now
9
+ @cat_update = File.mtime(Cat.config_file)
10
+ if @cat_update > @last_update
11
+ load Cat.config_file
12
+ @last_update = @cat_update
13
+ end
14
+
15
+ case env['PATH_INFO']
16
+ when "/" then response_skeleton
17
+ when "/skin.css" then response_skin
18
+ end
19
+ end
20
+
21
+ def self.response_skeleton
22
+ [
23
+ 200,
24
+ {"Content-Type" => "text/html"},
25
+ [Cat.to_html]
26
+ ]
27
+ end
28
+
29
+ def self.response_skin
30
+ [
31
+ 200,
32
+ {"Content-Type" => "text/css"},
33
+ [Cat.to_css]
34
+ ]
5
35
  end
6
36
  end
7
37
  end
@@ -0,0 +1,36 @@
1
+ require 'slim'
2
+ require 'cat/skeleton_node'
3
+
4
+ module Cat
5
+ class Skeleton
6
+ def initialize(skin, &block)
7
+ @skin = skin
8
+ @node = SkeletonNode.new("cat", &block)
9
+ end
10
+
11
+ def update(&block)
12
+ @node = SkeletonNode.new("cat", &block)
13
+ end
14
+
15
+ def skins
16
+ @node.skin
17
+ end
18
+
19
+ def cat
20
+ @node.expand
21
+ end
22
+
23
+ def generate
24
+ Slim::Template.new {
25
+ %{
26
+ html
27
+ head
28
+ title Loading Car
29
+ link(href="skin.css" rel="stylesheet")
30
+ body
31
+ #{cat}
32
+ }
33
+ }.render
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,46 @@
1
+ module Cat
2
+ class SkeletonNode
3
+ INDENT_SYMBOL = "\t"
4
+
5
+ def initialize(name = "cat", &block)
6
+ @nodes = []
7
+ @class = name
8
+ @body = nil
9
+ @skin = SkinNode.new(name)
10
+ instance_eval(&block) if block_given?
11
+ end
12
+
13
+ def body
14
+ return if @body.nil?
15
+ " #{@body}"
16
+ end
17
+
18
+ def to_s
19
+ ".#{@class}#{body}"
20
+ end
21
+
22
+ def node(name, &block)
23
+ @nodes << SkeletonNode.new(name, &block)
24
+ end
25
+
26
+ def skin(&block)
27
+ if block_given?
28
+ @skin.instance_eval(&block)
29
+ else
30
+ @skin.expand(with: @nodes)
31
+ end
32
+ end
33
+
34
+ def expand(indent = 2)
35
+ [
36
+ INDENT_SYMBOL * indent + to_s,
37
+ @nodes.map { |node| node.expand(indent + 1) }.join("\n")
38
+ ].join("\n")
39
+ end
40
+
41
+ def method_missing(name, *args, &block)
42
+ return @skin.send(name, *args, &block) if @skin.methods.include?(name)
43
+ super
44
+ end
45
+ end
46
+ end
data/lib/cat/skin.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'sassc'
2
+ require 'cat/skin_node'
3
+
4
+ module Cat
5
+ class Skin
6
+ def initialize
7
+ @base_style = %{
8
+ body {
9
+ background-color: $bgColor;
10
+ }
11
+ }
12
+
13
+ @variables = {
14
+ 'bgColor': "rgb(230, 220, 220)"
15
+ }
16
+ end
17
+
18
+ def var(name, value)
19
+ @variables[name] = value
20
+ end
21
+
22
+ def variables
23
+ @variables.map {|key, value|
24
+ "$#{key}:#{value};"
25
+ }.join("\n")
26
+ end
27
+
28
+ def style
29
+ variables + @base_style
30
+ end
31
+
32
+ def generate(from: nil)
33
+ _style = style
34
+ _style << from.skins unless from.nil?
35
+ SassC::Engine.new(_style).render
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,93 @@
1
+ require 'cat/style/ellipse'
2
+ require 'cat/style/mask'
3
+ require 'cat/style/fill'
4
+ require 'cat/style/center'
5
+ require 'cat/style/size'
6
+ require 'cat/style/stroke'
7
+ require 'cat/style/rotate'
8
+ require 'cat/style/clip'
9
+ require 'cat/style/position'
10
+ require 'cat/style/offset'
11
+ require 'cat/style/rounded'
12
+
13
+ module Cat
14
+ class SkinNode
15
+ def initialize(name, &block)
16
+ @name = name
17
+ @styles = ["box-sizing: border-box;"]
18
+ instance_eval(&block) if block_given?
19
+ end
20
+
21
+ def include_children(items)
22
+ items.map { |node| node.skin }.join("\n")
23
+ end
24
+
25
+ def ellipse
26
+ @styles << Style::Ellipse.new
27
+ self
28
+ end
29
+
30
+ def fill(color)
31
+ @styles << Style::Fill.new(color)
32
+ self
33
+ end
34
+
35
+ def center
36
+ @styles << Style::Center.new
37
+ self
38
+ end
39
+
40
+ def size(width, height = nil)
41
+ @styles << Style::Size.new(width, height)
42
+ self
43
+ end
44
+
45
+ def stroke(width = nil, color: nil, only: [:top, :right, :bottom, :left])
46
+ @styles << Style::Stroke.new(width, color, only)
47
+ self
48
+ end
49
+
50
+ def mask(size)
51
+ @styles << Style::Mask.new(size)
52
+ self
53
+ end
54
+
55
+ def rotate(deg)
56
+ @styles << Style::Rotate.new(deg)
57
+ self
58
+ end
59
+
60
+ def clip(mode = true)
61
+ @styles << Style::Clip.new
62
+ self
63
+ end
64
+
65
+ def position(top: nil, right: nil, bottom: nil, left: nil)
66
+ @styles << Style::Position.new(top: top, right: right, bottom: bottom, left: left)
67
+ self
68
+ end
69
+
70
+ def offset(amount, direction = :top)
71
+ @styles << Style::Offset.new(amount, direction)
72
+ self
73
+ end
74
+
75
+ def rounded(top: nil, right: nil, bottom: nil, left: nil)
76
+ @styles << Style::Rounded.new(top: top, right: right, bottom: bottom, left: left)
77
+ self
78
+ end
79
+
80
+ def to_s
81
+ @styles.join("\n")
82
+ end
83
+
84
+ def expand(with: [])
85
+ %{
86
+ .#{@name} {
87
+ #{to_s}
88
+ #{include_children(with)}
89
+ }
90
+ }
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,14 @@
1
+ module Cat
2
+ module Style
3
+ class Center
4
+ def to_s
5
+ %{
6
+ position: absolute;
7
+ top: 50%;
8
+ left: 50%;
9
+ transform: translate(-50%, -50%);
10
+ }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Cat
2
+ module Style
3
+ class Clip
4
+ def to_s
5
+ "overflow: hidden;"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Cat
2
+ module Style
3
+ class Ellipse
4
+ def to_s
5
+ %{
6
+ border-radius: 50%;
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Cat
2
+ module Style
3
+ class Fill
4
+ def initialize(color)
5
+ @color = color
6
+ @color = "black" unless (color =~ /^\$|#|rgb/) >= 0
7
+ end
8
+
9
+ def to_s
10
+ "background: #{@color};"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module Cat
2
+ module Style
3
+ class Mask
4
+ def initialize(size)
5
+ @size = size
6
+ @size = "#{@size}%" if @size.is_a?(Integer)
7
+ end
8
+
9
+ def to_s
10
+ %{
11
+ position: absolute;
12
+ width: #{@size};
13
+ height: #{@size};
14
+ border-radius: 100% 0 0 0;
15
+ transform-origin: right bottom;
16
+ background-color: $bgColor;
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,18 @@
1
+ module Cat
2
+ module Style
3
+ class Offset
4
+ def initialize(amount, direction)
5
+ @direction = direction
6
+ @direction = :top unless [:top, :left, :right, :bottom].include?(@direction)
7
+
8
+ @amount = amount.to_i
9
+ @amount = "#{amount}px" if @amount.is_a?(Integer)
10
+ @amount = "0px" unless (@amount =~ /px|%|em|rem$/) > 0
11
+ end
12
+
13
+ def to_s
14
+ "margin-#{@direction}: #{@amount};"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module Cat
2
+ module Style
3
+ class Position
4
+ def initialize(top: nil, right: nil, bottom: nil, left: nil)
5
+ @top = validate(top)
6
+ @right = validate(right)
7
+ @bottom = validate(bottom)
8
+ @left = validate(left)
9
+ end
10
+
11
+ def validate(value)
12
+ return nil if value.nil?
13
+ return "#{value}px" if value.is_a?(Integer)
14
+ return "0px" unless (value =~ /px|%|em|rem$/) > 0
15
+ value
16
+ end
17
+
18
+ def to_s
19
+ %{
20
+ position: absolute;
21
+ #{@top ? "top: #{@top};" : ""}
22
+ #{@right ? "right: #{@right};" : ""}
23
+ #{@bottom ? "bottom: #{@bottom};" : ""}
24
+ #{@left ? "left: #{@left};" : ""}
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Cat
2
+ module Style
3
+ class Rotate
4
+ def initialize(deg)
5
+ @deg = "#{deg.to_i}deg"
6
+ end
7
+
8
+ def to_s
9
+ "transform: rotate(#{@deg});"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Cat
2
+ module Style
3
+ class Rounded < Position
4
+ def to_s
5
+ "border-radius: #{@top || 0} #{@right || 0} #{@bottom || 0} #{@left || 0};"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Cat
2
+ module Style
3
+ class Size
4
+ def initialize(width, height = nil)
5
+ @width = width
6
+ @height = height || width
7
+ @width = "#{@width}px" if @width.is_a?(Integer)
8
+ @height = "#{@height}px" if @height.is_a?(Integer)
9
+ @width = '100px' unless (@width =~ /px|%|em|rem$/) > 0
10
+ @height = '100px' unless (@height =~ /px|%|em|rem$/) > 0
11
+ end
12
+
13
+ def to_s
14
+ %{
15
+ width: #{@width};
16
+ height: #{@height};
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,18 @@
1
+ module Cat
2
+ module Style
3
+ class Stroke
4
+ def initialize(width, color = nil, only = [:top, :right, :bottom, :left])
5
+ @width = width || '3'
6
+ @color = color || 'black'
7
+ @only = only
8
+
9
+ @width = "#{@width}px" if @width.is_a?(Integer)
10
+ @width = '3px' unless (@width =~ /px|%|em|rem$/) > 0
11
+ end
12
+
13
+ def to_s
14
+ @only.map { |direction| "border-#{direction}: #{@width} solid #{@color};" }.join("\n")
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/cat/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cat
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cat_
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -113,7 +113,23 @@ files:
113
113
  - cat.gemspec
114
114
  - exe/cats
115
115
  - lib/cat.rb
116
+ - lib/cat/engine.rb
116
117
  - lib/cat/server.rb
118
+ - lib/cat/skeleton.rb
119
+ - lib/cat/skeleton_node.rb
120
+ - lib/cat/skin.rb
121
+ - lib/cat/skin_node.rb
122
+ - lib/cat/style/center.rb
123
+ - lib/cat/style/clip.rb
124
+ - lib/cat/style/ellipse.rb
125
+ - lib/cat/style/fill.rb
126
+ - lib/cat/style/mask.rb
127
+ - lib/cat/style/offset.rb
128
+ - lib/cat/style/position.rb
129
+ - lib/cat/style/rotate.rb
130
+ - lib/cat/style/rounded.rb
131
+ - lib/cat/style/size.rb
132
+ - lib/cat/style/stroke.rb
117
133
  - lib/cat/version.rb
118
134
  homepage: https://github.com/elct9620/.cat
119
135
  licenses: []