hyogen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ +++ 0.0.1 2007-05-02
2
+
3
+ + 1 major enhancement:
4
+ + Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/hyogen.rb
6
+ lib/hyogen/version.rb
7
+ scripts/txt2html
8
+ setup.rb
9
+ test/test_helper.rb
10
+ test/test_hyogen.rb
11
+ website/index.html
12
+ website/index.txt
13
+ website/javascripts/rounded_corners_lite.inc.js
14
+ website/stylesheets/screen.css
15
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,177 @@
1
+ README for hyogen
2
+ =================
3
+
4
+ 1. ���̃c�[���ɂ‚���
5
+ �@CSV�f�[�^��Excel�t�@�C���� Ruby�I�u�W�F�N�g��C�ӂ̃f�[�^�`���ɕϊ�����c�[���ł��B
6
+ �@�\�`���̃f�[�^����\�[�X�R�[�h��HTML�t�@�C����e�ՂɎ��������ł���悤�ɂ���̂��ڕW�ł��B
7
+ �@�\�f�[�^�ɕ\�̍\�������^�O�Ƃ��Ė��ߍ��ނ��ƂŁA�\���ƂɃp�[�X���邽�߂̃R�[�h�����Ȃ��Ă� Ruby�I�u�W�F�N�g��
8
+ �@�C�ӂ̃e���v���[�g�`���ɕϊ��ł���悤�ɂ��܂��B
9
+
10
+ 2. �c�[�����J�o�[����͈�
11
+ �@���̃c�[���ł͊ȒP�ȕ\�A�‚܂茩�o���ƒl�̑΂���Ȃ�f�[�^�W�����������Ƃ��ł��܂��B���o���͊K�w�����邱�Ƃ��”\�ł��B�����̕\�����“��̓f�[�^���������Ƃ��”\�ł��B�������A����q�ɂȂ����\�͈����܂���B������\�̌`���ɂ‚��Ă̏ڍׂ͌�q���܂��B
12
+
13
+ 3. �\�̌`��
14
+ �@�\�͏c���Ɖ����̓�‚̎��ŔC�ӂ̃f�[�^�̖��́i���x���j�ƒl��\�����܂��B���Ƃ��΁A�ȉ��̗�1�̕\�ł͑��s�̉������f�[�^�̃��x����\�����Ă��܂��B����ɁA���x���ɑΉ�����l�̏W���𕡐��\�����邱�Ƃ��ł��܂��B���̈�‚̏W�������R�[�h�ƌĂт܂��B��1�ł́A���s�A��O�s���ꂼ�ꂪ���x���ɑΉ�����l�̏W�����Ă���A��‚̃��R�[�h������܂��B
15
+
16
+ �@�i��1�j
17
+ �@�o�Ȕԍ� | ���O | ���N����
18
+ �@-----------------------------------
19
+ 1 | ABE | 1999/2/10
20
+ 2 | ITOH | 1999/4/30
21
+
22
+ �@�\�ɂɂ̓��x���̕��тƃ��R�[�h�̕��т�����܂��B���̓�‚̕��т͒��s���Ă���A���x�������������i�c�������j�ɕ��Ԃ̂ł���΃��R�[�h�͏c�������i���������j�ɕ��т܂��B��1�͉��������Ƀ��x��������ł��܂��B��2�̂悤�ɕ\��]�u����Ǝ�������ւ��܂��B
23
+
24
+ �@�i��2�j
25
+ �@�o�Ȕԍ� |1 | 2
26
+ ���O |ABE | ITOH
27
+ ���N���� |1999/2/10 | 1999/4/30
28
+ �@-----------------------------------
29
+
30
+ ���R�[�h�́A�ȉ��̂悤�ɓ�‘g�݂̏W���Ƃ��ĕ\���ł��܂��B
31
+ L = {l_1, l_2, ..., l_n} : ���x���̏W��
32
+ V = {v_1, v_2, ..., v_n} : �l�̏W��
33
+ R = {(l_1, v_1,), (l_2, v_2), ..., (l_n, v_n)} : ���R�[�h
34
+ n: ���x���̐�
35
+ �@�\�̓��R�[�h�̏W���ł��B
36
+ T = {R_1, R_2, ..., R_m} : �e�[�u��
37
+ m: ���R�[�h�̐�
38
+
39
+ 3. �\�̍\���ƍ\���^�O
40
+ �@�c�[���ɕ\�̍\���ɂ‚��ċ�����K�v������܂��B���l�̖ړI�̃c�[���ɂ� Java�� XLSBeans������܂����AXLSBeans�ł͍\�������A�e�[�V�������邢�͊O�� XML�t�@�C���ŗ^���Ă��܂��B���̃c�[���ł́A�\������\�f�[�^���̂��̂Ƀ^�O�Ŗ��ߍ��݂܂��B
41
+
42
+ �@��‚�CSV�f�[�^�ɕ����̕\���܂߂邱�Ƃ��ł��܂��B�\��CSV�f�[�^�s�̏W�܂�ł���A��‚̕\�͈ȉ��̏����� CSV�f�[�^�s����\������܂��B�e���ڂ�{}�̓^�O�ł͂Ȃ��A�s���o������񐔂ł��B
43
+ �@�@1. �\�^�O���܂ލs {1
44
+ �@ 2. �󔒍s {0..n}
45
+ �@�@3. ���x���^�O���܂ލs {1..n}
46
+ �@ 4. �l���܂ލs {1..n}
47
+ �@ 5. �󔒍s {0..n}
48
+ �@
49
+ (1)�\���^�O
50
+ �^�O�ɂ̓^�O��{}�Ŋ���܂��B�^�O�ɂ͕\�^�O�A���x���^�O�Ȃǂ�����A���ꂼ�ꖄ�ߍ��݉”\�Ȉʒu���قȂ�܂��B�ڍׂ͂��ꂼ��̃^�O�̐������Q�Ƃ��Ă��������B
51
+ �^�O��CSV�f�[�^�̃Z���Ɉȉ��̂悤�ɂ��Ė��ߍ��݂܂��B���ߍ��݈ʒu�͑O�ł���ł����܂��܂���B�p�[�X��́A�^�O�𖄂ߍ��񂾃Z���̒l�Ō����ł��܂��B���̗�ł�"���t"�Ƃ���CSV�f�[�^�̌�Ƀ^�O�𖄂ߍ���ł��܂��B
52
+ �@ ���t{TAG}, 2007/4/1, 2000/1/1
53
+ �@
54
+ /*
55
+ �@�^�O�͒l�����‚��Ƃ��ł��܂��B�^�O���̌��":"�ȍ~���l�ɂȂ�܂��B�p�[�X��A�����ŗ^�����l���g���ăf�[�^�������ł���悤�ɂȂ�܂��B���̍ŏ��̗�ł̓^�O��"Date"�Ƃ����l��^���Ă��܂��B��Ԗڂ̗�����l�ł����ACSV�f�[�^�ł���"���t"���ȗ����Ă��܂��B�ȗ��̓^�O���l�����ꍇ�̂݉”\�ł��B
56
+ �@���t{TAG:Date}, 2007/4/1, 2000/1/1
57
+ {TAG:Date}, 2007/4/1, 2000/1/1
58
+ */
59
+
60
+ (2)�\�ƕ\�^�O {HTABLE}, {VTABLE}
61
+ CSV�f�[�^�s�̐擪���\�^�O���܂ލs�́A�\�̊J�n���Ӗ����܂��B�\�^�O�ɂ� HTABLE, VTABLE�̓��ނ�����A�����̈Ⴂ�̓��x���ƃ��R�[�h�̕�������\�����܂��B���x�����������i���R�[�h���c�����j�ɕ��ԏꍇ�́A{VTABLE}�^�O���g���܂��B�c�����ɕ��ԏꍇ�́A{VTABLE}�^�O���g���܂��B
62
+
63
+ (3)���x���ƃ��x���^�O {L}
64
+ �@���x���^�O�̓��x���Q�̊J�n�ʒu��\��������̂ŁA���x���Q�̐擪�ɖ��ߍ��݂܂��B
65
+ �@����F���x���͘A�����Ă��Ȃ���΂Ȃ�܂���
66
+
67
+ (4)���R�[�h
68
+ �@���R�[�h�̊J�n�ʒu�́A�e�[�u���^�O�ƃ��x���^�O�ɂ�茈�܂�܂��B�e�[�u���^�O��{HTALBE}�̏ꍇ�A���x���^�O�𖄂ߍ��񂾎��̍s����󔒍s�̎�O�܂ł����R�[�h�^�O�ƌ��Ȃ��܂��B{VTABLE}�̏ꍇ�A���x���^�O�𖄂ߍ��񂾎��̗񂩂�󔒗�̎�O�܂ł����R�[�h�^�O�ƌ��Ȃ��܂��B
69
+
70
+ (5)���x���⑫�^�O {N}
71
+ ���R�[�h�ł͂Ȃ��A���x���ɂ‚��Ă̕⑫���ɂ́A�擪��{N}�^�O�𖄂ߍ��݂܂��B
72
+
73
+ (6)���̂̒u�� <.+>
74
+ �@�^�O�ł͂���܂��񂪁A�^�O�Ɠ����悤�ɖ��ߍ��ނ��̂ɖ��̂̒u��������܂��B�u���������Z����<.*>�𖄂ߍ��ނ��ƂŁA�e�[�u�����A���x�����A���R�[�h�̒l��<>�̒��̕�����ɒu�����܂��B
75
+
76
+ �@�i��3�j
77
+ {HTABLE}�o�ȕ�,,
78
+ �@{L}�o�Ȕԍ�, ���O, ���N����
79
+ 1,ABE,1999/2/10
80
+ 2,ITOH,1999/4/30
81
+
82
+ �@�i��4�j
83
+ {VTABLE}�o�ȕ�,,
84
+ �@{L}�o�Ȕԍ�, 1, 2
85
+ ���O, ABE, ITOH
86
+ ���N����, 1999/2/10, 1999/4/30
87
+ �@-----------------------------------
88
+
89
+ {HTABLE}�o�ȕ�,,
90
+ �@item{L}, �o�Ȕԍ�, ���O<name>, ���N����
91
+ student1, 1,ABE{����},1999/2/10
92
+ student2, 2,ITOH,1999/4/30
93
+ ....
94
+ �⑫{N},,
95
+
96
+ {VTABLE}�o�ȕ�,,
97
+ ����{L}, student1, studen2, ...., �⑫{N},,
98
+ �@�o�Ȕԍ�, 1, 2
99
+ ���O, ABE, ITOH
100
+ ���N����, 1999/2/10, 1999/4/30
101
+
102
+ 4. ���G�ȕ\��\������
103
+ (1) ���x�����ȗ�����B
104
+
105
+ (2) �l���ȗ�����B
106
+
107
+ (3) �K�w�����x��
108
+ {VTABLE}�o�ȕ�,,
109
+ ����1{L}, ����2, student1, studen2, ...., �⑫{N},,
110
+ �@�o�Ȕԍ�, (1), 1, 2
111
+ �@, (2), 20024, 49842
112
+ ���O,, ABE, ITOH
113
+ ���N����,, 1999/2/10, 1999/4/30
114
+
115
+ (4) �z��
116
+ {L},{L}, {L}
117
+ �@�o�Ȕԍ�, (1)[], num, 1, 2
118
+ �@, , val, 3, 9
119
+ �@, (1)[], num, 20024, 49842
120
+ �@, , val, 10, 100
121
+
122
+ �z��Ƃ��Ĉ��������ꍇ�́A�u(1)[]�v�̂悤�ȋL�@�Ŗ�������B���̂悤�ȋL�@��p���Ȃ��ꍇ�͏㏑������B�㏑������Ƃ��͌x�����o�����ƁB
123
+
124
+
125
+
126
+ 5. ��������f�[�^
127
+ �@��������f�[�^�́A�\�ƃ��x���I�u�W�F�N�g�E�E�E�E
128
+ tables = [table_1, table_2, ..., table_n]
129
+ table_i = [[R_1, R_2, ..., R_n], [L_1,L_2, ..., L_n]]
130
+ R_i = [(L_1, V_i_1), (L_2, V_i_2), ..., (L_n, V_i_n)]
131
+ L_i = [[l_i_1, l_i_2, ..., l_i_n], [N_i_1, N_i_2, ..., N_i_2_n]
132
+ l_i_k: string
133
+ V_i_k : string
134
+ N_i_k : string
135
+
136
+ tables[tablename].records.first["Name"]["second"]
137
+ tables[tablename].labels.first["�⑫"]
138
+
139
+
140
+ 6. �e���v���[�g
141
+ �@�����f�[�^�����ƂɃe���v���[�g�Ńe�L�X�g�𐶐��ł���BERB�𗘗p�E�E�E
142
+
143
+
144
+ =begin Done
145
+ #��‚�CSV���ɕ����̃e�[�u��
146
+ #���@���`����
147
+ #��̓��W�b�N�𕪎U������̂ł͂Ȃ��A��‚̃N���X�ɏW�񂷂�B
148
+ #�A���������x�����ȗ��”\�ɂ���
149
+ #���x�����̂̒u��������
150
+ #���R�[�h�̒l�̒u��������
151
+ #�e�[�u���^�C�g���ƃ��x���̊Ԃ̏璷�ȍs������
152
+ #�l�i�e�[�u���^�C�g���A���x���A���R�[�h�l�Ȃǁj�̑O��̏璷�ȋ󔒂�����
153
+ #�⑫�^�O���T�|�[�g
154
+ #Excel�t�@�C������ǂݍ��߂�悤�ɂ���
155
+ #�e���v���[�g����̐������T�|�[�g
156
+ #�R�}���h���C���Ή�
157
+
158
+ =begin ToDo: 1st release
159
+ #�\�[�X�t�@�C���𕪊����Đ���
160
+
161
+ =begin ToDo: 2nd release
162
+ #�W�v���T�|�[�g
163
+ #�f�[�^�̖����`�F�b�N���T�|�[�g
164
+ #C����p�R�[�h�̐������T�|�[�g
165
+ #Ruby����p�R�[�h�̐������T�|�[�g
166
+
167
+ =====?
168
+ #�A���f�[�^��z��ɂł���悤�ɂ���
169
+ #�A���������R�[�h���ȗ��”\�ɂ���
170
+ #���@�������ɒ�`����
171
+ #���G�ȃX�L�[�}�F�����Ɛ����̑g�ݍ��킹
172
+
173
+ ====ParseExcel�̐���H(�o�O�H)
174
+ *�����̒l���擾�ł��Ȃ�
175
+
176
+ *�u10�v�����͂��ꂽ�Z�����A����10�Ȃ̂��A����10.0������������K�v������H
177
+ =end
data/Rakefile ADDED
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ #require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ include FileUtils
12
+ require File.join(File.dirname(__FILE__), 'lib', 'hyogen', 'version')
13
+
14
+ AUTHOR = 'yutaka' # can also be an array of Authors
15
+ EMAIL = "yutakayy@gmail.com"
16
+ DESCRIPTION = "This package allows you to mapping CSV or Excel to Ruby objects and generating some data."
17
+ GEM_NAME = 'hyogen' # what ppl will type to install your gem
18
+ RUBYFORGE_PROJECT = 'hyogen' # The unix name for your project
19
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
21
+
22
+ NAME = "hyogen"
23
+ REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ VERS = Hyogen::VERSION::STRING + (REV ? ".#{REV}" : "")
25
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
26
+ RDOC_OPTS = ['--quiet', '--title', 'hyogen documentation',
27
+ "--opname", "index.html",
28
+ "--line-numbers",
29
+ "--main", "README",
30
+ "--inline-source"]
31
+
32
+ class Hoe
33
+ def extra_deps
34
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
35
+ end
36
+ end
37
+
38
+ # Generate all the Rake tasks
39
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
40
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
41
+ p.author = AUTHOR
42
+ p.description = DESCRIPTION
43
+ p.email = EMAIL
44
+ p.summary = DESCRIPTION
45
+ p.url = HOMEPATH
46
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
47
+ # p.test_globs = ["test/**/test_*.rb"]
48
+ # p.test_globs = ["spec/**/spec_*.rb"]
49
+ p.test_globs = ["spec/**/*"]
50
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
51
+ # p.package_files.include("spec/**/*")
52
+
53
+ # == Optional
54
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
55
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
56
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
57
+ end
58
+
59
+ require 'spec/rake/spectask'
60
+ desc "Run all specs"
61
+ Spec::Rake::SpecTask.new('runspecs') do |t|
62
+ t.spec_files = FileList['spec/**/*.rb']
63
+ end
64
+
65
+
66
+ desc 'Generate website files'
67
+ task :website_generate do
68
+ Dir['website/**/*.txt'].each do |txt|
69
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
70
+ end
71
+ end
72
+
73
+ desc 'Upload website files to rubyforge'
74
+ task :website_upload do
75
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
76
+ host = "#{config["username"]}@rubyforge.org"
77
+ remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
78
+ # remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
79
+ local_dir = 'website'
80
+ sh %{rsync -av #{local_dir}/ #{host}:#{remote_dir}}
81
+ end
82
+
83
+ desc 'Generate and upload website files'
84
+ task :website => [:website_generate, :website_upload]
85
+
86
+ desc 'Release the website and new gem version'
87
+ task :deploy => [:check_version, :website, :release]
88
+
89
+ task :check_version do
90
+ unless ENV['VERSION']
91
+ puts 'Must pass a VERSION=x.y.z release version'
92
+ exit
93
+ end
94
+ unless ENV['VERSION'] == VERS
95
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
96
+ exit
97
+ end
98
+ end
@@ -0,0 +1,9 @@
1
+ module Hyogen #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/hyogen.rb ADDED
@@ -0,0 +1,10 @@
1
+ $KCODE = 's'
2
+ require 'kconv'
3
+
4
+ Dir[File.join(File.dirname(__FILE__), 'hyogen/**/*.rb')].sort.each { |lib| require lib }
5
+
6
+ module Hyogen
7
+ def self.parse_tables(any_format)
8
+ Reader.read_tables any_format
9
+ end
10
+ end
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/hyogen/version.rb'
8
+
9
+ version = Hyogen::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/hyogen'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)