回答編集履歴
2
不要なパスを削除、hamlのサンプルも追加
test
CHANGED
@@ -38,15 +38,13 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
```
|
41
|
+
```ruby
|
42
42
|
|
43
43
|
#!/usr/bin/env ruby
|
44
44
|
|
45
45
|
# The command line Haml parser.
|
46
46
|
|
47
47
|
|
48
|
-
|
49
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
50
48
|
|
51
49
|
require 'haml'
|
52
50
|
|
@@ -87,3 +85,27 @@
|
|
87
85
|
|
88
86
|
|
89
87
|
で実行してみると良いかと思います。
|
88
|
+
|
89
|
+
その場合は、lists.hamlは以下のようになります。
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```haml
|
94
|
+
|
95
|
+
!!!
|
96
|
+
|
97
|
+
%html{:lang => "ja"}
|
98
|
+
|
99
|
+
%body
|
100
|
+
|
101
|
+
- list = List.find(1)
|
102
|
+
|
103
|
+
- url = list.url
|
104
|
+
|
105
|
+
- title = list.title
|
106
|
+
|
107
|
+
%p
|
108
|
+
|
109
|
+
%a(href="#{url}") #{title}
|
110
|
+
|
111
|
+
```
|
1
具体例の追加
test
CHANGED
@@ -27,3 +27,63 @@
|
|
27
27
|
|
28
28
|
|
29
29
|
にすれば解決するかもしれませんが、その前の require も合わせて別の*.rbなファイルに置いておく方がよいかと思います。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
具体例としては、以下のようなファイルをhaml.rbとして用意して、
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```haml.rb
|
42
|
+
|
43
|
+
#!/usr/bin/env ruby
|
44
|
+
|
45
|
+
# The command line Haml parser.
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
50
|
+
|
51
|
+
require 'haml'
|
52
|
+
|
53
|
+
require 'haml/exec'
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
require 'active_record'
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => "./lists.db")
|
62
|
+
|
63
|
+
class List < ActiveRecord::Base
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
opts = Haml::Exec::Haml.new(ARGV)
|
70
|
+
|
71
|
+
opts.parse!
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
`chmod 755 haml.rb` などとして実行権限を与えた上で、
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```shell-session
|
82
|
+
|
83
|
+
$ ./haml.rb lists.haml lists.html
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
で実行してみると良いかと思います。
|