lisp-rails-view 0.0.1 → 0.0.2

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: dbdddd6688a527855ed9e36b3219ae465820bbaa
4
- data.tar.gz: 09f2e4529a22af4ebccd5e28e8b6269a2b6778d9
3
+ metadata.gz: c891454d8f24a05a1afa27024b8f96d530c6a10c
4
+ data.tar.gz: de3093264b3b1c573da4ffcb3b2dcdfe9631fe6c
5
5
  SHA512:
6
- metadata.gz: a98ac529566451e8d0490ed66f4d5ab2c4e7e58b963d6645815402529c7d1fe6fb8fdcbd9bf3ebcd314c3da3c39dac234cf9ff5c1a25753502ba78bd013891b1
7
- data.tar.gz: 102a8232c486c37e09d543190b0f375a752bfaf5d6adeb087019632e7b3f33931b4135e65b1e8223c60f47b9cfd772817ed8bb595358089345eea7282538dc9f
6
+ metadata.gz: 6793b7ca79b2c2e7ddb545ee63b8be73c176824e18578997e526171deaa7ac15c01a6e0d2fe9b1ce84ca45929b74f81868ad7dd36ba1ff62f48674c9a8e50bcf
7
+ data.tar.gz: ba59381c86e285af79ce1aae879a674f239bc666a205b43b7564c73018f36d509f8146962b3560e50eeff1e693ec367379d27fe3aa7489516022945a09fdb069
@@ -1 +1,5 @@
1
1
  (:p "パーシャルの中です。まみむめも。")
2
+ (:div#main
3
+ (:h3.title "title")
4
+ (:p#foo.bar "Hello"))
5
+
@@ -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"))
@@ -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.join.html_safe
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
@@ -1,3 +1,3 @@
1
1
  module LispRailsView
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -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 raw ()
9
+ (defclass ruby-code ()
9
10
  ((value :initarg :value :accessor value)))
10
11
 
11
- (defclass raw= (raw) ())
12
+ (defclass =ruby-code (ruby-code) ())
12
13
 
13
14
  (defclass html-safe ()
14
15
  ((value :initarg :value :accessor value)))
15
16
 
16
- (defun raw (x)
17
- (make-instance 'raw :value x))
17
+ (defun ruby-code (x)
18
+ (make-instance 'ruby-code :value x))
18
19
 
19
- (defun raw= (x)
20
- (make-instance 'raw= :value x))
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 "&amp;" out))
31
+ ((char= #\< c)
32
+ (write-string "&lt;" out))
33
+ ((char= #\> c)
34
+ (write-string "&gt;" out))
35
+ ((char= #\" c)
36
+ (write-string "&quot;" out))
37
+ ((char= #\' c)
38
+ (write-string "&#x27;" 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
- ;;TODO constant の連結
43
- (loop for x in (nreverse *buffer*)
44
- do (format stream "~a~%" (to-ruby-exp x))))
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 raw))
112
+ (defmethod to-ruby-exp ((x ruby-code))
75
113
  (value x))
76
114
 
77
- (defmethod to-ruby-exp ((x raw=))
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 (raw= (make-ruby-form (cdr x) t))))
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 (raw (make-ruby-form x))))))
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.1
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-08 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler