lisp-rails-view 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/_partial.html.lisp +4 -0
- data/examples/index.html.lisp +4 -2
- data/lib/lisp-rails-view.rb +15 -2
- data/lib/lisp-rails-view/version.rb +1 -1
- data/lisp/lisp-rails-view.lisp +57 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c891454d8f24a05a1afa27024b8f96d530c6a10c
|
4
|
+
data.tar.gz: de3093264b3b1c573da4ffcb3b2dcdfe9631fe6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6793b7ca79b2c2e7ddb545ee63b8be73c176824e18578997e526171deaa7ac15c01a6e0d2fe9b1ce84ca45929b74f81868ad7dd36ba1ff62f48674c9a8e50bcf
|
7
|
+
data.tar.gz: ba59381c86e285af79ce1aae879a674f239bc666a205b43b7564c73018f36d509f8146962b3560e50eeff1e693ec367379d27fe3aa7489516022945a09fdb069
|
data/examples/_partial.html.lisp
CHANGED
data/examples/index.html.lisp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
(:h1.title "lisp-rails-view Lisp
|
1
|
+
(:h1.title "lisp-rails-view Lisp でビューを書く")
|
2
2
|
|
3
3
|
(:h2 "イストール")
|
4
4
|
|
@@ -28,6 +28,8 @@
|
|
28
28
|
|
29
29
|
(:p "エスケープされるはず。<script>alert(\"hello\");</script>&\"'")
|
30
30
|
|
31
|
+
(:p#<x>.<y> :data-foo "<z>" "<&\"'>")
|
32
|
+
|
31
33
|
(:h3 "Ruby のコード")
|
32
34
|
|
33
35
|
(:p "ふつうに . かスペースです。")
|
@@ -72,7 +74,7 @@
|
|
72
74
|
|
73
75
|
(:h3 "render")
|
74
76
|
|
75
|
-
(:p "
|
77
|
+
(:p "パーシャルもなんとか。")
|
76
78
|
|
77
79
|
(:p (:pre "(= render (\"partial\"))"))
|
78
80
|
(= render ("partial"))
|
data/lib/lisp-rails-view.rb
CHANGED
@@ -15,7 +15,7 @@ module LispRailsView
|
|
15
15
|
|
16
16
|
def self.call(template)
|
17
17
|
file = template.identifier
|
18
|
-
x = `sbcl --script #{LISP} #{file}`
|
18
|
+
x = `LANG=ja_JP.UTF-8 sbcl --script #{LISP} #{file}`
|
19
19
|
code = <<EOT
|
20
20
|
[].tap do |b__|
|
21
21
|
def b__.push(x)
|
@@ -28,7 +28,7 @@ def b__.push(x)
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
#{x}
|
31
|
-
end.flatten
|
31
|
+
end.flatten
|
32
32
|
EOT
|
33
33
|
Rails.logger.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
|
34
34
|
Rails.logger.debug(code)
|
@@ -36,4 +36,17 @@ EOT
|
|
36
36
|
code
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
module Helper
|
41
|
+
def _layout_for(name=nil)
|
42
|
+
name ||= :layout
|
43
|
+
view_flow.get(name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module ActionView
|
49
|
+
class Base
|
50
|
+
include LispRailsView::Helper
|
51
|
+
end
|
39
52
|
end
|
data/lisp/lisp-rails-view.lisp
CHANGED
@@ -1,27 +1,43 @@
|
|
1
1
|
(defpackage :lisp-rails-view
|
2
|
-
(:use :cl)
|
2
|
+
(:use :cl)
|
3
|
+
(:shadow :#=))
|
3
4
|
|
4
5
|
(in-package :lisp-rails-view)
|
5
6
|
|
6
7
|
(defvar *buffer* nil)
|
7
8
|
|
8
|
-
(defclass
|
9
|
+
(defclass ruby-code ()
|
9
10
|
((value :initarg :value :accessor value)))
|
10
11
|
|
11
|
-
(defclass
|
12
|
+
(defclass =ruby-code (ruby-code) ())
|
12
13
|
|
13
14
|
(defclass html-safe ()
|
14
15
|
((value :initarg :value :accessor value)))
|
15
16
|
|
16
|
-
(defun
|
17
|
-
(make-instance '
|
17
|
+
(defun ruby-code (x)
|
18
|
+
(make-instance 'ruby-code :value x))
|
18
19
|
|
19
|
-
(defun
|
20
|
-
(make-instance '
|
20
|
+
(defun =ruby-code (x)
|
21
|
+
(make-instance '=ruby-code :value x))
|
21
22
|
|
22
23
|
(defun html-safe (x)
|
23
24
|
(make-instance 'html-safe :value x))
|
24
25
|
|
26
|
+
(defun escape (thing)
|
27
|
+
(with-output-to-string (out)
|
28
|
+
(loop for c across (princ-to-string thing)
|
29
|
+
do (cond ((char= #\& c)
|
30
|
+
(write-string "&" out))
|
31
|
+
((char= #\< c)
|
32
|
+
(write-string "<" out))
|
33
|
+
((char= #\> c)
|
34
|
+
(write-string ">" out))
|
35
|
+
((char= #\" c)
|
36
|
+
(write-string """ out))
|
37
|
+
((char= #\' c)
|
38
|
+
(write-string "'" out))
|
39
|
+
(t (write-char c out))))))
|
40
|
+
|
25
41
|
(eval-when (:compile-toplevel :load-toplevel :execute)
|
26
42
|
(defmacro with-reader (&body body)
|
27
43
|
`(let ((*readtable* (copy-readtable nil)))
|
@@ -39,9 +55,31 @@
|
|
39
55
|
do (%eval form))))
|
40
56
|
|
41
57
|
(defun flush-buffer (stream)
|
42
|
-
|
43
|
-
|
44
|
-
|
58
|
+
(let (buffer)
|
59
|
+
(labels ((<< (x)
|
60
|
+
(setf buffer
|
61
|
+
(if buffer
|
62
|
+
(html-safe
|
63
|
+
(concatenate 'string (value buffer)
|
64
|
+
(if (stringp x)
|
65
|
+
(escape x)
|
66
|
+
(value x))))
|
67
|
+
(if (stringp x)
|
68
|
+
(html-safe (escape x))
|
69
|
+
x))))
|
70
|
+
(flush ()
|
71
|
+
(when buffer
|
72
|
+
(%write buffer)
|
73
|
+
(setf buffer nil)))
|
74
|
+
(%write (x)
|
75
|
+
(format stream "~a~%" (to-ruby-exp x))))
|
76
|
+
(loop for i in (nreverse *buffer*)
|
77
|
+
do (typecase i
|
78
|
+
((or string html-safe) (<< i))
|
79
|
+
(t
|
80
|
+
(flush)
|
81
|
+
(%write i))))
|
82
|
+
(flush))))
|
45
83
|
|
46
84
|
(defun emit (x)
|
47
85
|
(push x *buffer*))
|
@@ -71,10 +109,10 @@
|
|
71
109
|
(defmethod to-ruby-exp ((x number))
|
72
110
|
(to-ruby-exp (princ-to-string x)))
|
73
111
|
|
74
|
-
(defmethod to-ruby-exp ((x
|
112
|
+
(defmethod to-ruby-exp ((x ruby-code))
|
75
113
|
(value x))
|
76
114
|
|
77
|
-
(defmethod to-ruby-exp ((x
|
115
|
+
(defmethod to-ruby-exp ((x =ruby-code))
|
78
116
|
(format nil "b__.push(~a)" (value x)))
|
79
117
|
|
80
118
|
(defmethod to-ruby-exp ((x html-safe))
|
@@ -88,14 +126,14 @@
|
|
88
126
|
|
89
127
|
(defmethod %eval ((x cons))
|
90
128
|
(cond ((eq '= (car x))
|
91
|
-
(emit (
|
129
|
+
(emit (=ruby-code (make-ruby-form (cdr x) t))))
|
92
130
|
((keywordp (car x))
|
93
131
|
(process-tag x))
|
94
132
|
((and (symbolp (car x))
|
95
133
|
(fboundp (car x)))
|
96
134
|
(emit (eval x)))
|
97
135
|
(t
|
98
|
-
(emit (
|
136
|
+
(emit (ruby-code (make-ruby-form x))))))
|
99
137
|
|
100
138
|
(defun process-tag (form)
|
101
139
|
(multiple-value-bind (tag id classes) (parse-tag (car form))
|
@@ -109,15 +147,15 @@
|
|
109
147
|
(emit (html-safe (with-output-to-string (out)
|
110
148
|
(format out "<~a" tag)
|
111
149
|
(when id
|
112
|
-
(format out " id=\"~a\"" id))
|
150
|
+
(format out " id=\"~a\"" (escape id)))
|
113
151
|
(when classes
|
114
|
-
(format out " class=\"~{~a~^ ~}\"" classes))
|
152
|
+
(format out " class=\"~{~a~^ ~}\"" (mapcar #'escape classes)))
|
115
153
|
(loop for (k . v) in attributes do
|
116
154
|
(if (constantp v)
|
117
155
|
(if (eq v t)
|
118
|
-
(format out " ~a" k)
|
119
|
-
(format out " ~a=\"~a\"" k v))
|
120
|
-
(format out "#{~a == true ? \"~a\" : \"~a=\"~a\"\"}" v k k v)))
|
156
|
+
(format out " ~a" (escape k))
|
157
|
+
(format out " ~a=\"~a\"" (escape k) (escape v)))
|
158
|
+
(format out "#{~a == true ? \" ~a\" : \" ~a=\"~a\"\"}" v k k v)))
|
121
159
|
(if /-p
|
122
160
|
(write-string " />" out)
|
123
161
|
(write-string ">" out)))))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lisp-rails-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAHARA Yoshinori
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|