sugamasao-saag 0.2.4 → 0.3.4

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.
Files changed (7) hide show
  1. data/ChangeLog +10 -0
  2. data/README.rdoc +50 -0
  3. data/TODO +1 -0
  4. data/VERSION +1 -1
  5. data/lib/saag.rb +183 -6
  6. metadata +5 -5
  7. data/README +0 -40
data/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2009-07-06 sugamasao@gmail.com
2
+
3
+ * Version 0.3.4 : modified ends at the [Sass Syntax Error] or [File I/O
4
+ Error]. endless loop for file search.
5
+
6
+ 2009-07-05 sugamasao@gmail.com
7
+
8
+ * Version 0.3.2 : moved README to README.rdoc
9
+ * Version 0.3.0 : added to rdoc comments
10
+
1
11
  2009-06-25 sugamasao@gmail.com
2
12
 
3
13
  * Version 0.2.4 : change to this file.
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = saag
2
+
3
+ == Description
4
+
5
+ SASS automatic monitor and generate CSS file.
6
+
7
+ SASS ファイルを監視し、変更があれば即座に CSS ファイルへ変換します。
8
+
9
+ 手動で以下のコマンドを行うのと同等です。
10
+ % sass hoge.sass hoge.css
11
+
12
+ == Gem Installation
13
+
14
+ gem install sugamasao-saag --source http://gems.github.com
15
+
16
+ == Features/Problems
17
+
18
+ * Ruby 1.8.6 及び、 1.8.7 で、動作確認を行っています
19
+ * Windows XP 及び、 Mac OSX で動作確認を行っています
20
+ * 事前にSass(HAML)のインストールが必要になります(未インストール時は本gemと一緒にインストールされます)
21
+
22
+ == Synopsis
23
+
24
+ 使用例:
25
+ % saag
26
+ 引数を使用しない場合、コマンド実行者のカレントディレクトリを基点とし、*.sass ファイルを探し、対象ファイルとします。
27
+
28
+ また、出力される CSS ファイルは sass ファイルと同じ階層になります。
29
+
30
+ % saag -i /path/to/sass
31
+
32
+ -i オプションを使用することで、sass ファイルのあるディレクトリ(ファイル名でも可)を指定する事が可能です。
33
+
34
+ 出力先は、上記と同様に、sass ファイルのあるディレクトリになります。
35
+
36
+ % saag -i /path/to/sass -o /path/to/css
37
+
38
+ -o オプションを使用することで、css の出力先ファイルを指定することができます。
39
+
40
+ 出力先ファイルのディレクトリ構成は、-i オプションに依存します。
41
+
42
+ 上記のオプションを指定、/path/to/sass/sub_dir/hoge.sass があった場合、出力先ディレクトリは
43
+
44
+ /path/to/css/sub_dir/hoge.css となります。
45
+
46
+ == Copyright
47
+
48
+ Author:: sugamasao <sugamasao@gmail.com>
49
+ License:: Ruby's
50
+
data/TODO CHANGED
@@ -1,5 +1,6 @@
1
1
  = TODO List
2
2
 
3
+ * Tab Character to '2 spaces'
3
4
  * GUI Interface
4
5
  * Plugin Function
5
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.4
data/lib/saag.rb CHANGED
@@ -4,10 +4,22 @@ require 'optparse'
4
4
  require 'logger'
5
5
  require 'pp'
6
6
 
7
+ #
8
+ # Sass 補助ツール、saag クラスです
9
+ #
7
10
  class Saag
8
11
  SASS_EXT = '.sass'
9
12
  CSS_EXT = '.css'
10
13
 
14
+ #== saag Constructor
15
+ # 引数の解析、及び初期値の設定を行います
16
+ #
17
+ #=== 引数
18
+ # 引数となる配列
19
+ #
20
+ #=== 例外
21
+ # 特になし
22
+ #
11
23
  def initialize(argv = [])
12
24
  # クラス共通の値
13
25
  @app_name = self.class
@@ -54,6 +66,18 @@ class Saag
54
66
  @logger.info("output directory => #{@conf[:out_path]}")
55
67
  end
56
68
 
69
+ #== saag#run
70
+ # saag によるファイル監視を実行します
71
+ #
72
+ #=== 引数
73
+ # なし
74
+ #
75
+ #=== 戻り値
76
+ # なし
77
+ #
78
+ #=== 例外
79
+ # なし
80
+ #
57
81
  def run
58
82
  old_list = []
59
83
  # メインループ
@@ -63,8 +87,6 @@ class Saag
63
87
  break if @exit # SIGNAL を受けたりすると true
64
88
  sleep 1
65
89
  end
66
- rescue SystemCallError => e
67
- @logger.error("File I/O Error! [#{e.message}]")
68
90
  rescue => e
69
91
  @logger.error("FATLE Error! [#{e.message}]")
70
92
  end
@@ -72,8 +94,24 @@ class Saag
72
94
  @logger.info("sass file watching exit...")
73
95
  end
74
96
 
97
+ ############################
98
+ # private methods
99
+ ############################
75
100
  private
76
101
 
102
+ #== saag#main_loop
103
+ # saag の監視処理のメイン処理です。
104
+ # このメソッドを繰り返し呼ぶ事で監視処理を実施しています。
105
+ #
106
+ #=== 引数
107
+ # _old_list_:: Array オブジェクト 前回の main_loop メソッドで取得したファイルリストの一覧。
108
+ #
109
+ #=== 戻り値
110
+ # Array:: main_loop内で取得したファイルリストの配列。
111
+ #
112
+ #=== 例外
113
+ # なし
114
+ #
77
115
  def main_loop(old_list)
78
116
  return nil if @exit # SIGNAL を受けていたら処理を抜ける
79
117
  new_list = get_file_list(@conf[:in_path])
@@ -85,21 +123,55 @@ class Saag
85
123
  file_list.each do |sass_file|
86
124
  if sass_file[:change]
87
125
  @logger.info("change file found. => #{sass_file[:path]}")
88
- css_text = Sass::Engine.new(File.read(sass_file[:path]), {:style => @conf[:render_opt] }).render
89
- write_css_file(sass_file, css_text)
126
+ begin
127
+ # render to sass text
128
+ css_text = Sass::Engine.new(File.read(sass_file[:path]), {:style => @conf[:render_opt] }).render
129
+ write_css_file(sass_file, css_text)
130
+ rescue Sass::SyntaxError => e
131
+ @logger.error("Sass Syntax Error! file => [#{sass_file[:path]}] error message => [#{e.message}]")
132
+ new_list = set_default_time(new_list, sass_file[:path])
133
+ rescue SystemCallError => e
134
+ @logger.error("File I/O Error! file => [#{sass_file[:path]}] error message => [#{e.message}]")
135
+ new_list = set_default_time(new_list, sass_file[:path])
136
+ end
90
137
  end
91
138
  end
92
139
 
93
140
  return new_list
94
141
  end
95
142
 
143
+ #== saag#set_dir_path
96
144
  # 絶対パスにし、ディレクトリの場合は最後尾にスラッシュを付ける
145
+ #
146
+ #=== 引数
147
+ # _path_:: ファイルパスの記載された String オブジェクト
148
+ #
149
+ #=== 戻り値
150
+ # String:: ディレクトリであれば末尾に '/' を付加した、絶対パスのファイル名
151
+ #
152
+ #=== 例外
153
+ # なし
154
+ #
97
155
  def set_dir_path(path)
98
156
  path = File.expand_path(path)
99
157
  path = path + '/' if File.directory?(path)
100
158
  return path
101
159
  end
102
160
 
161
+ #== saag#set_signal
162
+ # シグナルハンドラの設定
163
+ # シグナルを受けると即死するのではなく、キリの良いところで終了するよう、
164
+ # 終了フラグを true にするだけの処理を行う。
165
+ #
166
+ #=== 引数
167
+ # なし
168
+ #
169
+ #=== 戻り値
170
+ # なし
171
+ #
172
+ #=== 例外
173
+ # なし
174
+ #
103
175
  def set_signal
104
176
  begin
105
177
  Signal.trap(:INT){
@@ -138,6 +210,19 @@ class Saag
138
210
  end
139
211
  end
140
212
 
213
+ #== saag#set_render_opt
214
+ # sass 実行時のオプション設定用メソッド
215
+ # オプションで値が渡されていれば その値を、そうでなければでフォルト値のnestedを使う。
216
+ #
217
+ #=== 引数
218
+ # _input_opt_:: 引数の -r で入力された文字列
219
+ #
220
+ #=== 戻り値
221
+ # Symbol:: 入力された文字列に対応した Symbol
222
+ #
223
+ #=== 例外
224
+ # なし
225
+ #
141
226
  def set_render_opt(input_opt)
142
227
  opt = ""
143
228
  case input_opt.downcase
@@ -156,6 +241,20 @@ class Saag
156
241
  return opt
157
242
  end
158
243
 
244
+ #== saag#set_default_conf
245
+ # sass 実行時のオプション設定用メソッド。
246
+ # 省略時の入力パスと出力パスを設定する。
247
+ # ディレクトリの場合は '/' を付加する。
248
+ #
249
+ #=== 引数
250
+ # なし
251
+ #
252
+ #=== 戻り値
253
+ # なし
254
+ #
255
+ #=== 例外
256
+ # なし
257
+ #
159
258
  def set_default_conf()
160
259
  unless @conf[:in_path]
161
260
  @conf[:in_path] = Dir.pwd + '/'
@@ -172,7 +271,18 @@ class Saag
172
271
  end
173
272
  end
174
273
 
274
+ #== saag#get_file_list
175
275
  # ファイルのパスと時刻のリストを作成する
276
+ #
277
+ #=== 引数
278
+ # _in_path_:: 引数の -i で入力されたパス
279
+ #
280
+ #=== 戻り値
281
+ # Array:: 時刻とパスを保持したファイルリスト。
282
+ #
283
+ #=== 例外
284
+ # なし
285
+ #
176
286
  def get_file_list(in_path)
177
287
  list = []
178
288
  if File.file?(in_path)
@@ -188,6 +298,23 @@ class Saag
188
298
  return list.compact
189
299
  end
190
300
 
301
+ #== saag#create_file_data
302
+ # ファイルパスと時刻等を保持した HASH を生成する。
303
+ # 生成する HASH の内容は以下の通り
304
+ # * :path => ファイルの絶対パス
305
+ # * :sub_path => 入力時に指定されたディレクトリ以降からのファイルパス
306
+ # * :time => 対象ファイルの mtime
307
+ # * :change => 前回との変更があったか?を現すフラグ(この時点では全て true)
308
+ #
309
+ #=== 引数
310
+ # _path_:: ファイルパス
311
+ #
312
+ #=== 戻り値
313
+ # Hash:: 時刻とパス等を保持した Hash データ。
314
+ #
315
+ #=== 例外
316
+ # なし
317
+ #
191
318
  def create_file_data(path)
192
319
  # 入力パスと実ファイルのパスの差分を出す(この差分が出力ディレクトリの連結パスとなる)
193
320
  sub_path = ""
@@ -206,13 +333,27 @@ class Saag
206
333
  return data
207
334
  end
208
335
 
336
+ #== saag#check_file_list
337
+ # 前回走査したファイルリストと、今回走査したファイルリストにおいて、
338
+ # ファイルの更新や追加があったリストの :change を true にし、そうでなければ false にする。
339
+ #
340
+ #=== 引数
341
+ # _old_list_:: 前回のループで取得したファイルリストの Array
342
+ # _new_list_:: 今回のループで取得したファイルリストの Array
343
+ #
344
+ #=== 戻り値
345
+ # Array:: change フラグの更新が終わった new_list
346
+ #
347
+ #=== 例外
348
+ # なし
349
+ #
209
350
  def check_file_list(old_list, new_list)
210
351
  return new_list if old_list.empty?
211
352
 
212
353
  new_list.each do |new|
213
354
  old_list.each do |old|
214
- if(new[:path] == old[:path])
215
- if(new[:time] > old[:time])
355
+ if(new[:path] == old[:path]) # 前回と今回で同じファイルがあれば、時刻の比較を行う
356
+ if(new[:time] > old[:time]) # 時刻が更新されていれば true
216
357
  new[:change] = true
217
358
  else
218
359
  new[:change] = false
@@ -224,6 +365,19 @@ class Saag
224
365
  return new_list
225
366
  end
226
367
 
368
+ #== saag#write_css_file
369
+ # 変換された CSS ファイルを出力する
370
+ #
371
+ #=== 引数
372
+ # _sass_file:: 変換対象のファイルの Hash
373
+ # _css_text_:: 変換された CSS テキストの String
374
+ #
375
+ #=== 戻り値
376
+ # なし
377
+ #
378
+ #=== 例外
379
+ # SystemCallError:: ファイル出力時の例外時に出力
380
+ #
227
381
  def write_css_file(sass_file, css_text)
228
382
  @logger.debug("@conf[:out_path] = #{@conf[:out_path]}, sass_file[:sub_path] = #{sass_file[:sub_path]}")
229
383
  out_dir = ""
@@ -246,5 +400,28 @@ class Saag
246
400
  end
247
401
  @logger.info("generate css file => #{filename}")
248
402
  end
403
+
404
+ #== saag#set_default_time
405
+ # 指定された path の :time 値をあり得ない値にして更新する。
406
+ # 更新に失敗したデータは時刻を現在より過去のものにして、次回のループで変換対象となるようにする。
407
+ #
408
+ #=== 引数
409
+ # _list_:: 走査対象のファイルリスト
410
+ # _path_:: 更新に失敗したファイルのパス
411
+ #
412
+ #=== 戻り値
413
+ # Array:: :time の更新が終わった new_list
414
+ #
415
+ #=== 例外
416
+ # なし
417
+ #
418
+ def set_default_time(file_list, path)
419
+ file_list.map do |list|
420
+ if list[:path] == path
421
+ list[:time] = Time.at(0) # 1970/1/1
422
+ end
423
+ list
424
+ end
425
+ end
249
426
  end
250
427
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugamasao-saag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sugamasao
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-25 00:00:00 -07:00
12
+ date: 2009-07-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  - saag
15
15
  dependencies:
@@ -31,11 +31,11 @@ extensions: []
31
31
 
32
32
  extra_rdoc_files:
33
33
  - ChangeLog
34
- - README
34
+ - README.rdoc
35
35
  - TODO
36
36
  files:
37
37
  - ChangeLog
38
- - README
38
+ - README.rdoc
39
39
  - VERSION
40
40
  - bin/saag
41
41
  - lib/saag.rb
@@ -52,7 +52,7 @@ rdoc_options:
52
52
  - index.html
53
53
  - --line-numbers
54
54
  - --main
55
- - README
55
+ - README.rdoc
56
56
  - --inline-source
57
57
  - --exclude
58
58
  - ^(examples|extras)/
data/README DELETED
@@ -1,40 +0,0 @@
1
- = saag
2
-
3
- == Description
4
-
5
- SASS automatic monitor and generate CSS file.
6
- SASS ファイルを監視し、変更があれば即座に CSS ファイルへ変換します。
7
- 手動で以下のコマンドを行うのと同等です。
8
- % sass hoge.sass hoge.css
9
-
10
- == Gem Installation
11
-
12
- gem install sugamasao-saag --source http://gems.github.com
13
-
14
- == Features/Problems
15
-
16
- * Ruby 1.8.7 でのみ、動作確認を行っています
17
- * 事前にSASS(HAML)のインストールが必要になります
18
-
19
- == Synopsis
20
-
21
- 使用例:
22
- % saag
23
-  引数を使用しない場合、コマンド実行者のカレントディレクトリを基点とし、*.sass ファイルを探し、対象ファイルとします。
24
- また、出力される CSS ファイルは sass ファイルと同じ階層になります。
25
-
26
- % saag -i /path/to/sass
27
- -i オプションを使用することで、sass ファイルのあるディレクトリ(ファイル名でも可)を指定する事が可能です。
28
- 出力先は、上記と同様に、sass ファイルのあるディレクトリになります。
29
-
30
- % saag -i /path/to/sass -o /path/to/css
31
- -o オプションを使用することで、css の出力先ファイルを指定することができます。
32
- 出力先ファイルのディレクトリ構成は、-i オプションに依存します。
33
- 上記のオプションを指定、/path/to/sass/sub_dir/hoge.sass があった場合、出力先ディレクトリは
34
- /path/to/css/sub_dir/hoge.css となります。
35
-
36
- == Copyright
37
-
38
- Author:: sugamasao <sugamasao@gmail.com>
39
- License:: Ruby's
40
-