ludy 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,16 @@
1
1
  = ludy changes history
2
2
 
3
+ == ludy 0.1.4, 2008.01.31
4
+
5
+ * added Page#begin and Page#end for real index in the data
6
+ * added Paginator#count for counter.call wrapper
7
+
8
+ * rename from Ludy::eout to Ludy::erbout
9
+ * added erubis support
10
+ * rename task from erb:preprocess to preprocess:erb and preprocess:erubis
11
+ * task preprocess would preprocess with erb and erubis
12
+ * rename PROJ to Project with open struct. use Project.name now
13
+
3
14
  == ludy 0.1.3, 2008.01.23
4
15
 
5
16
  * renamed next_page to next, and prev_page to prev
data/Manifest.txt CHANGED
@@ -56,10 +56,10 @@ lib/ludy/symbol/to_msg.rb
56
56
  lib/ludy/symbol/to_proc.rb
57
57
  lib/ludy/tasks.rb
58
58
  lib/ludy/tasks/common.rb
59
- lib/ludy/tasks/erb_cpp.rb
60
- lib/ludy/tasks/erb_cpp/attr_builder.rb
61
- lib/ludy/tasks/erb_cpp/header_guard.rb
62
- lib/ludy/tasks/erb_cpp/template_forward_parameters.rb
59
+ lib/ludy/tasks/preprocess_cpp.rb
60
+ lib/ludy/tasks/preprocess_cpp/attr_builder.rb
61
+ lib/ludy/tasks/preprocess_cpp/header_guard.rb
62
+ lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb
63
63
  lib/ludy/test/helper.rb
64
64
  lib/ludy/variable.rb
65
65
  lib/ludy/y_combinator.rb
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = ludy 0.1.3
1
+ = ludy 0.1.4
2
2
  by Lin Jen-Shin (a.k.a. godfat 真常)
3
3
  strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org
4
4
  http://ludy.rubyforge.org
@@ -103,7 +103,7 @@ ludy tasks:
103
103
 
104
104
  header_guard:
105
105
  require 'ludy/tasks/erb_cpp/header_guard'
106
- PROJ = 'header_sample' # remember to set project name
106
+ Project.name = 'header_sample' # remember to set project name
107
107
 
108
108
  # in utils/SimpleTest.hpp.erb
109
109
  <% header_guard do %>
@@ -111,7 +111,7 @@ header_guard:
111
111
  <% end %>
112
112
 
113
113
  # run preprocessing task
114
- $ rake erb:preprocessing
114
+ $ rake preprocessing
115
115
 
116
116
  # produce:
117
117
  #ifndef _HEADER_SAMPLE_UTILS_SIMPLETEST_
@@ -130,7 +130,7 @@ attr_builder:
130
130
  };
131
131
 
132
132
  # run preprocessing task
133
- $ rake erb:preprocessing
133
+ $ rake preprocessing
134
134
 
135
135
  # produce:
136
136
  class MapSetting{
@@ -170,7 +170,7 @@ template_forward_parameters:
170
170
  <% } %>
171
171
 
172
172
  # run preprocessing task
173
- $ rake erb:preprocessing
173
+ $ rake preprocessing
174
174
 
175
175
  # one of the produce: (can't list all...)
176
176
  template <class T0, class T1, class T2, class T3>
@@ -183,6 +183,7 @@ template_forward_parameters:
183
183
  * ruby 1.8/1.9 (1.9 is prefered...)
184
184
  * rake
185
185
  * gem facets if you are using puzzle_generator
186
+ * gem erubis if you are using preprocess:erubis
186
187
 
187
188
  == INSTALL:
188
189
 
data/Rakefile CHANGED
@@ -6,6 +6,7 @@ load 'tasks/setup.rb'
6
6
 
7
7
  ensure_in_path 'lib'
8
8
  require 'ludy'
9
+ require 'ludy/tasks'
9
10
 
10
11
  task :default do
11
12
  sh 'rake --tasks'
@@ -20,7 +21,7 @@ PROJ.description = paragraphs_of('README', 1).join("\n\n")
20
21
  PROJ.changes = paragraphs_of('CHANGES', 0..1).join("\n\n")
21
22
  PROJ.rubyforge_name = 'ludy'
22
23
 
23
- PROJ.version = '0.1.3'
24
+ PROJ.version = '0.1.4'
24
25
  PROJ.exclude << '.DS_Store' << '^tmp'
25
26
  PROJ.dependencies << 'rake'
26
27
 
data/TODO CHANGED
@@ -12,3 +12,7 @@
12
12
  * rails multiple layout
13
13
 
14
14
  * better manifest creating
15
+
16
+ * better bin/ludy support
17
+
18
+ * refactor tasks...
@@ -8,7 +8,7 @@ module Kernel
8
8
  end
9
9
  # another else variant...
10
10
  def else
11
- if self && !self.kind_of?(Blackhole) then self
11
+ if self && !self.kind_of?(Ludy::Blackhole) then self
12
12
  else yield end
13
13
  end
14
14
  end
@@ -24,9 +24,13 @@ module Ludy
24
24
  @pager == rhs.instance_variable_get('@pager')
25
25
  end
26
26
  # explicitly fetch the data from pager
27
- def fetch; @data = @pager.fetcher[@pager.offset(@page), @pager.per_page]; end
27
+ def fetch; @data = @pager.fetcher[self.begin, @pager.per_page]; end
28
28
  # get the data fetched from pager
29
29
  def data; @data ||= fetch; end
30
+ # the real beginning index
31
+ def begin; @pager.offset @page; end
32
+ # the real ending index (need fetch, because we don't know the size)
33
+ def end; self.begin + self.size - 1; end
30
34
  # any other method call would delegate to the data,
31
35
  # e.g., each, to_a, map, first, method_you_defined, etc.
32
36
  def method_missing msg, *args, &block
@@ -68,14 +72,13 @@ module Ludy
68
72
  # nil would be returned. note, page start at 1, not zero.
69
73
  def page page
70
74
  offset = (page-1)*@per_page
71
- size = @counter.call
72
- return nil unless page > 0 and offset <= size
75
+ return nil unless page > 0 and offset <= count
73
76
  Page.new self, page
74
77
  end
75
- # return the number of pages
76
- def size
77
- (@counter.call/@per_page.to_f).ceil
78
- end
78
+ # return the amount of pages
79
+ def size; (count/@per_page.to_f).ceil; end
80
+ # simply call @counter.call
81
+ def count; @counter.call; end
79
82
  alias_method :[], :page
80
83
  # get the offset property about the page.
81
84
  # it is simply (page-1)*@per_page
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ludy
3
3
  # append erb output...
4
- def self.eout string, binding
4
+ def self.erbout string, binding
5
5
  eval('_erbout', binding) << string
6
6
  end
7
7
  end
@@ -6,12 +6,12 @@ module Kernel
6
6
  # C/C++ header guard generator, you shold provide the final #endif yourself,
7
7
  # and you should provide PROJ name for header guard prefix
8
8
  def header_guard random_suffix = nil, &block
9
- defined = "_#{PROJ.upcase}_#{@dir.upcase}_#{@class.upcase}_#{random_suffix.nil? ? '' : rand.to_s[2..-1]+'_'}"
9
+ defined = "_#{Project.name.upcase}_#{@dir.upcase}_#{@class.upcase}_#{random_suffix.nil? ? '' : rand.to_s[2..-1]+'_'}"
10
10
 
11
- Ludy::eout "#ifndef #{defined}
11
+ Ludy::erbout "#ifndef #{defined}
12
12
  #define #{defined}", block.binding
13
13
  block.call
14
- Ludy::eout '#endif', block.binding
14
+ Ludy::erbout '#endif', block.binding
15
15
  end
16
16
 
17
17
  end # of ludy
@@ -0,0 +1,67 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake/clean'
4
+ require 'ludy'
5
+ Ludy.require_all_in 'tasks/preprocess_cpp'
6
+ require 'erb'
7
+ require 'open-uri'
8
+ require 'ostruct'
9
+
10
+ Project = OpenStruct.new
11
+
12
+ namespace :preprocess do
13
+
14
+ erb_inputs = FileList['**/*.erb']
15
+ erb_outputs = erb_inputs.ext
16
+
17
+ task :erb_begin do; puts "processing templates: #{erb_inputs.inspect}\n\n"; end
18
+ task :end do; puts "processing done."; end
19
+
20
+ desc 'automaticly translate all *.cpp.erb into *.cpp'
21
+ task :erb => [:erb_begin, erb_outputs, :end].flatten
22
+
23
+ def preprocess template_engine, input, output
24
+ puts "processing... #{output}"
25
+ open output, 'w' do |o|
26
+ @class = output.pathmap '%n'
27
+ @dir = output.pathmap('%-1d')
28
+ @indent = ' '
29
+ @prefix = ''
30
+ Project.name ||= 'please_set_Project_name_for_your_header_name'
31
+ o << template_engine.new(input).result(binding)
32
+ end
33
+ end
34
+
35
+ erb_inputs.zip(erb_outputs).each{ |input, output|
36
+ file output => input do
37
+ preprocess ERB, open(input).read, output
38
+ end
39
+ }
40
+
41
+ erubis_outputs = [] # for people don't have erubis
42
+ begin
43
+ require 'erubis'
44
+ erubis_inputs = FileList['**/*.eruby']
45
+ erubis_outputs = erubis_inputs.ext
46
+
47
+ task :erubis_begin do; puts "processing templates: #{erubis_inputs.inspect}\n\n"; end
48
+ task :end do; puts "processing done."; end
49
+
50
+ desc 'automaticly translate all *.cpp.eruby into *.cpp'
51
+ task :erubis => [:erubis_begin, erubis_outputs, :end].flatten
52
+
53
+ erubis_inputs.zip(erubis_outputs).each{ |input, output|
54
+ file output => input do
55
+ class ErboutEruby < Erubis::Eruby; include Erubis::ErboutEnhancer; end
56
+ preprocess ErboutEruby, open(input).read, output
57
+ end
58
+ }
59
+ rescue LoadError; end # no erubis
60
+
61
+ outputs = erb_outputs + erubis_outputs
62
+ CLEAN.include outputs
63
+
64
+ end # of namespace preprocess
65
+
66
+ desc 'run all preprocessing stuffs'
67
+ task :preprocess => ['preprocess:erb','preprocess:erubis']
data/lib/ludy.rb CHANGED
@@ -12,7 +12,7 @@ require 'rake'
12
12
  module Ludy
13
13
 
14
14
  # :stopdoc:
15
- VERSION = '0.1.3'
15
+ VERSION = '0.1.4'
16
16
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
17
17
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
18
18
  $LOAD_PATH << LIBPATH
@@ -1,7 +1,6 @@
1
1
 
2
2
  require 'puzzle_generator/misc'
3
3
  require 'puzzle_generator/chain'
4
- require 'ludy/array/body'
5
4
 
6
5
  require 'rubygems'
7
6
  gem 'facets', '>=2.0.0'
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'rubygems'
3
+ gem 'facets', '>=2.0.0'
3
4
  require 'facets/kernel/deep_clone'
4
5
  require 'facets/array/pad'
5
6
 
@@ -4,6 +4,7 @@ require 'puzzle_generator/chained_map'
4
4
  require 'puzzle_generator/colored_map'
5
5
 
6
6
  require 'rubygems'
7
+ gem 'facets', '>=2.0.0'
7
8
  require 'facets/array/rotate'
8
9
  require 'facets/timer'
9
10
 
@@ -29,6 +29,10 @@ class TestPaginator < Test::Unit::TestCase
29
29
  assert_equal(5050, pager.inject(0){|r, i| r += i.inject(&:+) })
30
30
 
31
31
  assert_equal 4, pager[4].page
32
+
33
+ assert_equal 10, pager[2].begin
34
+ assert_equal 19, pager[2].end
35
+ assert_equal 100, pager[11].end
32
36
  end
33
37
  def test_basic
34
38
  pager = Ludy::Paginator.new(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ludy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Lin Jen-Shin (a.k.a. godfat \xE7\x9C\x9F\xE5\xB8\xB8)"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-23 00:00:00 +08:00
12
+ date: 2008-01-31 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -101,10 +101,10 @@ files:
101
101
  - lib/ludy/symbol/to_proc.rb
102
102
  - lib/ludy/tasks.rb
103
103
  - lib/ludy/tasks/common.rb
104
- - lib/ludy/tasks/erb_cpp.rb
105
- - lib/ludy/tasks/erb_cpp/attr_builder.rb
106
- - lib/ludy/tasks/erb_cpp/header_guard.rb
107
- - lib/ludy/tasks/erb_cpp/template_forward_parameters.rb
104
+ - lib/ludy/tasks/preprocess_cpp.rb
105
+ - lib/ludy/tasks/preprocess_cpp/attr_builder.rb
106
+ - lib/ludy/tasks/preprocess_cpp/header_guard.rb
107
+ - lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb
108
108
  - lib/ludy/test/helper.rb
109
109
  - lib/ludy/variable.rb
110
110
  - lib/ludy/y_combinator.rb
@@ -1,35 +0,0 @@
1
-
2
- require 'rubygems'
3
- require 'rake/clean'
4
- require 'ludy'
5
- Ludy.require_all_in 'tasks/erb_cpp'
6
-
7
- namespace :erb do
8
-
9
- inputs = FileList['**/*.erb']
10
- outputs = inputs.ext
11
- CLEAN.include outputs
12
-
13
- desc 'automaticly translate all *.cpp.erb into *.cpp'
14
- task :preprocess => [:begin, outputs, :end].flatten
15
- task :begin do; puts "processing templates: #{inputs.inspect}\n\n"; end
16
- task :end do; puts "processing done."; end
17
-
18
- require 'erb'
19
- require 'open-uri'
20
-
21
- inputs.zip(outputs).each{ |input, output|
22
- file output => input do
23
- puts "processing... #{output}"
24
- open output, 'w' do |o|
25
- @class = output.pathmap '%n'
26
- @dir = output.pathmap('%-1d')
27
- @indent = ' '
28
- @prefix = ''
29
- PROJ ||= 'please_set_PROJ_for_your_header_name'
30
- o << ERB.new(open(input).read).result(binding)
31
- end
32
- end
33
- }
34
-
35
- end # of namespace erb