my_wiki_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/my_wiki/grep.txt +238 -0
  2. data/my_wiki/my_wiki_generator.rb +248 -0
  3. data/my_wiki/templates/POST_GENERATION_REMINDER +1 -0
  4. data/my_wiki/templates/app/controllers/application.rb +75 -0
  5. data/my_wiki/templates/app/controllers/content_history_controller.rb +49 -0
  6. data/my_wiki/templates/app/controllers/login_controller.rb +93 -0
  7. data/my_wiki/templates/app/controllers/my_wiki_admin_controller.rb +26 -0
  8. data/my_wiki/templates/app/controllers/my_wiki_controller.rb +250 -0
  9. data/my_wiki/templates/app/controllers/page_admin_controller.rb +51 -0
  10. data/my_wiki/templates/app/controllers/user_admin_controller.rb +34 -0
  11. data/my_wiki/templates/app/helpers/application_helper.rb +3 -0
  12. data/my_wiki/templates/app/helpers/content_history_helper.rb +2 -0
  13. data/my_wiki/templates/app/helpers/login_helper.rb +2 -0
  14. data/my_wiki/templates/app/helpers/my_wiki_admin_helper.rb +2 -0
  15. data/my_wiki/templates/app/helpers/my_wiki_helper.rb +94 -0
  16. data/my_wiki/templates/app/helpers/page_admin_helper.rb +2 -0
  17. data/my_wiki/templates/app/helpers/user_admin_helper.rb +2 -0
  18. data/my_wiki/templates/app/models/attachment.rb +55 -0
  19. data/my_wiki/templates/app/models/content.rb +32 -0
  20. data/my_wiki/templates/app/models/content_history.rb +49 -0
  21. data/my_wiki/templates/app/models/content_sweeper.rb +7 -0
  22. data/my_wiki/templates/app/models/my_wiki_mailer.rb +29 -0
  23. data/my_wiki/templates/app/models/role.rb +18 -0
  24. data/my_wiki/templates/app/models/setting.rb +7 -0
  25. data/my_wiki/templates/app/models/user.rb +60 -0
  26. data/my_wiki/templates/app/views/content_history/_form.rhtml +19 -0
  27. data/my_wiki/templates/app/views/content_history/edit.rhtml +9 -0
  28. data/my_wiki/templates/app/views/content_history/list.rhtml +27 -0
  29. data/my_wiki/templates/app/views/content_history/new.rhtml +8 -0
  30. data/my_wiki/templates/app/views/content_history/show.rhtml +21 -0
  31. data/my_wiki/templates/app/views/layouts/my_wiki.rhtml +105 -0
  32. data/my_wiki/templates/app/views/login/edit.rhtml +25 -0
  33. data/my_wiki/templates/app/views/login/login.rhtml +23 -0
  34. data/my_wiki/templates/app/views/login/logout.rhtml +10 -0
  35. data/my_wiki/templates/app/views/login/signup.rhtml +23 -0
  36. data/my_wiki/templates/app/views/login/welcome.rhtml +13 -0
  37. data/my_wiki/templates/app/views/my_wiki/_form.rhtml +11 -0
  38. data/my_wiki/templates/app/views/my_wiki/css.rhtml +224 -0
  39. data/my_wiki/templates/app/views/my_wiki/diff.rhtml +4 -0
  40. data/my_wiki/templates/app/views/my_wiki/edit.rhtml +34 -0
  41. data/my_wiki/templates/app/views/my_wiki/fileinfo.rhtml +22 -0
  42. data/my_wiki/templates/app/views/my_wiki/list.rhtml +1 -0
  43. data/my_wiki/templates/app/views/my_wiki/mails.rhtml +1 -0
  44. data/my_wiki/templates/app/views/my_wiki/new.rhtml +6 -0
  45. data/my_wiki/templates/app/views/my_wiki/recent.rhtml +3 -0
  46. data/my_wiki/templates/app/views/my_wiki/search.rhtml +5 -0
  47. data/my_wiki/templates/app/views/my_wiki/search_result.rhtml +10 -0
  48. data/my_wiki/templates/app/views/my_wiki/show.rhtml +31 -0
  49. data/my_wiki/templates/app/views/my_wiki_admin/index.rhtml +5 -0
  50. data/my_wiki/templates/app/views/my_wiki_admin/setting.rhtml +64 -0
  51. data/my_wiki/templates/app/views/my_wiki_mailer/inform.rhtml +3 -0
  52. data/my_wiki/templates/app/views/page_admin/_form.rhtml +22 -0
  53. data/my_wiki/templates/app/views/page_admin/edit.rhtml +9 -0
  54. data/my_wiki/templates/app/views/page_admin/list.rhtml +55 -0
  55. data/my_wiki/templates/app/views/page_admin/new.rhtml +8 -0
  56. data/my_wiki/templates/app/views/page_admin/show.rhtml +8 -0
  57. data/my_wiki/templates/app/views/user_admin/_form.rhtml +10 -0
  58. data/my_wiki/templates/app/views/user_admin/change_password.rhtml +9 -0
  59. data/my_wiki/templates/app/views/user_admin/list.rhtml +25 -0
  60. data/my_wiki/templates/app/views/user_admin/signup.rhtml +20 -0
  61. data/my_wiki/templates/components/admin/menu/menu.rhtml +5 -0
  62. data/my_wiki/templates/components/admin/menu_controller.rb +3 -0
  63. data/my_wiki/templates/components/list/list/list.rhtml +11 -0
  64. data/my_wiki/templates/components/list/list_controller.rb +11 -0
  65. data/my_wiki/templates/components/sidebar/sidebar/show.rhtml +7 -0
  66. data/my_wiki/templates/components/sidebar/sidebar_controller.rb +9 -0
  67. data/my_wiki/templates/config/routes.rb +35 -0
  68. data/my_wiki/templates/db/migrate/001_my_wiki_migration.rb +75 -0
  69. data/my_wiki/templates/lib/diff/lcs.rb +1105 -0
  70. data/my_wiki/templates/lib/diff/lcs/array.rb +21 -0
  71. data/my_wiki/templates/lib/diff/lcs/block.rb +51 -0
  72. data/my_wiki/templates/lib/diff/lcs/callbacks.rb +322 -0
  73. data/my_wiki/templates/lib/diff/lcs/change.rb +169 -0
  74. data/my_wiki/templates/lib/diff/lcs/hunk.rb +257 -0
  75. data/my_wiki/templates/lib/diff/lcs/ldiff.rb +226 -0
  76. data/my_wiki/templates/lib/diff/lcs/string.rb +19 -0
  77. data/my_wiki/templates/lib/login_system.rb +87 -0
  78. data/my_wiki/templates/lib/markup/simple_markup.rb +489 -0
  79. data/my_wiki/templates/lib/markup/simple_markup/fragments.rb +329 -0
  80. data/my_wiki/templates/lib/markup/simple_markup/inline.rb +338 -0
  81. data/my_wiki/templates/lib/markup/simple_markup/lines.rb +151 -0
  82. data/my_wiki/templates/lib/markup/simple_markup/preprocess.rb +68 -0
  83. data/my_wiki/templates/lib/markup/simple_markup/to_flow.rb +188 -0
  84. data/my_wiki/templates/lib/markup/simple_markup/to_html.rb +302 -0
  85. data/my_wiki/templates/lib/markup/simple_markup/to_latex.rb +333 -0
  86. data/my_wiki/templates/lib/my_wiki_plugin.rb +60 -0
  87. data/my_wiki/templates/lib/my_wiki_plugins/christel.rb +5 -0
  88. data/my_wiki/templates/lib/my_wiki_plugins/join.rb +3 -0
  89. data/my_wiki/templates/lib/my_wiki_plugins/link_to_attach.rb +17 -0
  90. data/my_wiki/templates/lib/my_wiki_plugins/recent.rb +8 -0
  91. data/my_wiki/templates/public/javascripts/my_wiki.js +8 -0
  92. data/my_wiki/templates/public/stylesheets/my_wiki/back.jpg +0 -0
  93. data/my_wiki/templates/public/stylesheets/my_wiki/back1.jpg +0 -0
  94. data/my_wiki/templates/public/stylesheets/my_wiki/back2.jpg +0 -0
  95. data/my_wiki/templates/public/stylesheets/my_wiki/foot.jpg +0 -0
  96. data/my_wiki/templates/public/stylesheets/my_wiki/h1.gif +0 -0
  97. data/my_wiki/templates/public/stylesheets/my_wiki/h1.jpg +0 -0
  98. data/my_wiki/templates/public/stylesheets/my_wiki/menu.jpg +0 -0
  99. data/my_wiki/templates/public/stylesheets/my_wiki/menu2.jpg +0 -0
  100. data/my_wiki/templates/public/stylesheets/my_wiki/menu_c.jpg +0 -0
  101. data/my_wiki/templates/public/stylesheets/my_wiki/my_wiki.css +336 -0
  102. data/my_wiki/templates/public/stylesheets/my_wiki/title.jpg +0 -0
  103. metadata +181 -0
@@ -0,0 +1 @@
1
+ finish
@@ -0,0 +1,75 @@
1
+ # Filters added to this controller will be run for all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+ require_dependency "login_system"
4
+ require 'diff/lcs'
5
+ require 'diff/lcs/callbacks'
6
+ require '<%= file_name %>_plugin'
7
+ #require 'gettext/rails'
8
+
9
+ class ApplicationController < ActionController::Base
10
+ include LoginSystem
11
+ model :user
12
+ #init_gettext 'mywiki'
13
+
14
+ before_filter do |controller|
15
+ <%= class_name %>Plugin.controller = controller
16
+ controller.session[:settings] ||= Setting.find_active_or_default
17
+ end
18
+
19
+ def difference_between(previous, current)
20
+ current_content = current.split "\n"
21
+ previous_content = previous.split "\n"
22
+
23
+ difference = ''
24
+ Diff::LCS::sdiff(previous_content, current_content) do |change|
25
+ difference += (
26
+ case change.action
27
+ when '+', '>'
28
+ "<span class=\"diff_added\">#{change.new_element}</span>\n"
29
+ when '-', '<'
30
+ "<span class=\"diff_deleted\">#{change.new_element}</span>\n"
31
+ when '='
32
+ "<span class=\"diff_same\">#{change.new_element}</span>\n"
33
+ when '#', '!'
34
+ "<span class=\"diff_modified\"><span class=\"diff_old\">#{change.old_element}</span>\n<span class=\"diff_new\">#{change.new_element}</span></span>\n"
35
+ else
36
+ "?#{change.action}?#{change.old_element}?#{change.new_element}?\n"
37
+ end
38
+ )
39
+ end
40
+ difference
41
+ end
42
+
43
+ def must_be_creator_or_super_if_freezed
44
+ @content ||= Content.find_by_id_or_title params
45
+ return true if @content.nil? or !@content.freezed
46
+
47
+ if login_required
48
+ user = @session[:user]
49
+ if (@content.user == user) or (@content.user.role_id < user.role_id)
50
+ true
51
+ else
52
+ store_location
53
+ access_denied
54
+ false
55
+ end
56
+ else
57
+ false
58
+ end
59
+ end
60
+
61
+ def must_be_admin
62
+ if login_required
63
+ user = @session[:user]
64
+ if user.role.admin?
65
+ true
66
+ else
67
+ store_location
68
+ access_denied
69
+ false
70
+ end
71
+ else
72
+ false
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,49 @@
1
+ class ContentHistoryController < ApplicationController
2
+ layout '<%= file_name %>'
3
+ #before_filter :must_be_creator_or_super_if_freezed, :only => :rollback
4
+
5
+ def show
6
+ @content_history = ContentHistory.find_by_id_or_title params
7
+ if @content_history.nil?
8
+ # if the version of the page does not exist, then redirected to the current page
9
+ options = {:controller => '<%= file_name %>', :action => 'show'}
10
+ options[:title] = params[:title] if params.include? :title
11
+ options[:id] = params[:content_id] if params.include? :content_id
12
+ redirect_to options
13
+ else
14
+ #@max = ContentHistory.maximum(:version, :conditions => ["content_id = ?", params[:content_id]])
15
+ @max = ContentHistory.max_version @content_history.content_id
16
+ @mytemplate = <%= class_name %>Helper::<%= class_name %>Template.new
17
+ @title = "#{@content_history.title} - Rev. ##{@content_history.version}"
18
+ @prev_version = if 1 < @content_history.version then @content_history.version - 1 else nil end
19
+ @next_version = if @content_history.version < @max then @content_history.version + 1 else nil end
20
+ end
21
+ end
22
+
23
+ def rollback
24
+ history = ContentHistory.find_by_id_or_title params
25
+ @content = Content.find history.content_id
26
+ if must_be_creator_or_super_if_freezed
27
+ flash[:rollback_to] = history
28
+ flash[:rollback_from] = @content
29
+ redirect_to :controller => '<%= file_name %>', :action => 'update'
30
+ else
31
+ flash[:notice] = "ページ'#{@content.title}'は凍結されています。"
32
+ end
33
+ end
34
+
35
+ def destroy
36
+ ContentHistory.find(params[:id]).destroy
37
+ redirect_to :action => 'list'
38
+ end
39
+
40
+ def diff
41
+ content_history = ContentHistory.find_by_id_or_title params
42
+ content = Content.find_by_id content_history.content_id.to_i
43
+
44
+ @title = "Diff: #{content.title} Rev. ##{content_history.version}"
45
+ @difference = difference_between(content_history.body, content.body)
46
+
47
+ render :action => '../<%= file_name %>/diff'
48
+ end
49
+ end
@@ -0,0 +1,93 @@
1
+ #require_dependency "login_system"
2
+
3
+ class LoginController < ApplicationController
4
+ include LoginSystem
5
+ layout '<%= file_name %>'
6
+
7
+ def login
8
+ @title = 'Login'
9
+ case @request.method
10
+ when :post
11
+ if @session[:user] = User.authenticate(@params[:user_login], @params[:user_password])
12
+
13
+ flash['notice'] = "Login successful"
14
+ redirect_back_or_default :action => "welcome"
15
+ else
16
+ flash.now['notice'] = "Login unsuccessful"
17
+
18
+ @login = @params[:user_login]
19
+ end
20
+ end
21
+ end
22
+
23
+ def edit
24
+ @title = 'Edit'
25
+ @roles = Role.find :all, :order => 'id'
26
+ @user = User.find(@params[:id])
27
+
28
+ if @request.post?
29
+ if (User.authenticate @params[:user][:login], @params[:old_password]).nil?
30
+ flash['notice'] = "Wrong password."
31
+ redirect_to :action => 'edit'
32
+ #redirect_back_or_default :action => "welcome"
33
+ else
34
+ if @user.role_id == @params[:user][:role_id]
35
+ # change only password
36
+ @user.password = @params[:user][:password]
37
+ @user.password_confirmation = @params[:user][:password_confirmation]
38
+ else
39
+ # change role
40
+ @user.role_id = @params[:user][:role_id]
41
+ if @params[:user][:password].empty? and @params[:user][:password_confirmation]
42
+ @user.password = @params[:old_password]
43
+ @user.password_confirmation = @params[:old_password]
44
+ else
45
+ # change password
46
+ @user.password = @params[:user][:password]
47
+ @user.password_confirmation = @params[:user][:password_confirmation]
48
+ end
49
+ end
50
+
51
+ if @user.role.normal? or @session[:user].role.admin?
52
+ if @user.save
53
+ @session[:user] = User.authenticate(@user.login, @params[:user][:password])
54
+ flash['notice'] = "Edit successful"
55
+ redirect_back_or_default :action => "welcome"
56
+ end
57
+ else
58
+ flash['notice'] = "Only a user having a less role than #{@session[:user].role.name} can be added."
59
+ redirect_to :action => 'edit'
60
+ #redirect_back_or_default :action => "welcome"
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def signup
67
+ @title = 'Sign Up'
68
+ @roles = Role.find :all, :order => 'id'
69
+ @user = User.new(@params[:user])
70
+
71
+ if @request.post?
72
+ if @user.role.normal? or @session[:user].role.admin?
73
+ if @user.save
74
+ @session[:user] = User.authenticate(@user.login, @params[:user][:password])
75
+ flash['notice'] = "Signup successful"
76
+ redirect_back_or_default :action => "welcome"
77
+ end
78
+ else
79
+ flash['notice'] = "Only a normal user can be added."
80
+ redirect_back_or_default :action => "welcome"
81
+ end
82
+ end
83
+ end
84
+
85
+ def logout
86
+ @title = 'Logout'
87
+ @session[:user] = nil
88
+ end
89
+
90
+ def welcome
91
+ @title = 'Welcome'
92
+ end
93
+ end
@@ -0,0 +1,26 @@
1
+ class <%= class_name %>AdminController < ApplicationController
2
+ layout "<%= file_name %>"
3
+ model :setting
4
+ before_filter :must_be_admin
5
+
6
+ def index
7
+ @title = 'Administrate'
8
+ end
9
+
10
+ def setting
11
+ @title = '各種設定'
12
+ @setting = Setting.find_active_or_default
13
+ end
14
+
15
+ def update
16
+ @setting = Setting.find params[:id]
17
+ if @setting.update_attributes(params[:setting])
18
+ session[:settings] = @setting
19
+ flash[:notice] = 'Setting was successfully updated.'
20
+ else
21
+ flash[:notice] = 'Setting was mistakenly updated.'
22
+ end
23
+
24
+ redirect_to :action=>"setting", :id=>@setting
25
+ end
26
+ end
@@ -0,0 +1,250 @@
1
+ class <%= class_name %>Controller < ApplicationController
2
+ model :content_history
3
+ before_filter :must_be_creator_or_super_if_freezed, :only => :edit
4
+ #before_filter :must_be_admin, :only => :admin
5
+
6
+ #caches_action :show
7
+ #cache_sweeper :content_sweeper, :only => :update
8
+
9
+ def index
10
+ redirect_to_frontpage
11
+ end
12
+
13
+ def list
14
+ @title = "ページ一覧"
15
+ end
16
+
17
+ def recent
18
+ @title = "Recent"
19
+ end
20
+
21
+ def show
22
+ @content = Content.find_by_id_or_title params
23
+ if @content.nil?
24
+ redirect_to(:action => 'new', :title => params[:title])
25
+ else
26
+ @mytemplate = <%= class_name %>Helper::<%= class_name %>Template.new
27
+ @title = @content.title
28
+ @attaches = Attachment.list @content.id
29
+ @max = @content.version == 1 ? nil : @content.version - 1
30
+ end
31
+ end
32
+
33
+ def new
34
+ @title = 'New'
35
+ @content = Content.new
36
+ @content.title = params[:title] unless params[:title].nil?
37
+ end
38
+
39
+ def create
40
+ @content = Content.new(params[:content])
41
+ @content.version = FIRST_VERSION #ContentHistory.max_version(@content.id) + 1
42
+ if @content.save
43
+ flash[:notice] = 'Content was successfully created.'
44
+ #<%= class_name %>Mailer.deliver_inform "新規作成", @content
45
+ redirect_to :action => 'show', :id => @content
46
+ else
47
+ render :action => 'new'
48
+ end
49
+ end
50
+
51
+ def edit
52
+ @content = Content.find_by_id_or_title(params) if @content.nil?
53
+ unless params[:title].nil?
54
+ # when redirected from the update action because of a collision
55
+ flash[:notice] = 'A collision is detected'
56
+ @difference = difference_between(@content.body, params[:body])
57
+ @content.title = params[:title]
58
+ @content.body = params[:body]
59
+ end
60
+
61
+ if @content.nil?
62
+ redirect_to_frontpage
63
+ return
64
+ else
65
+ @title = "Edit: #{@content.title}"
66
+ end
67
+ end
68
+
69
+ #TODO: この関数、ごちゃごちゃし過ぎてるので何とかしたいです。
70
+ def update
71
+ new_content = nil
72
+ if flash.include? :rollback_to
73
+ content_history = flash[:rollback_to]
74
+ @content = flash[:rollback_from]
75
+ new_content = {:body => content_history.body, :version => @content.version + 1}
76
+ else
77
+ if params[:commit] == 'プレビュー'
78
+ @mytemplate = <%= class_name %>Helper::<%= class_name %>Template.new
79
+ @preview = params[:content][:body]
80
+ @content = Content.new params[:content]
81
+ render :controller=>'mywiki', :action=>'edit'
82
+ return
83
+ end
84
+
85
+ @content = Content.find_by_id_or_title params
86
+ if @content.version != params[:content][:version].to_i
87
+ redirect_to :action => 'edit',
88
+ :id => @content,
89
+ :title => params[:content][:title],
90
+ :body => params[:content][:body]
91
+ return
92
+ end
93
+
94
+ if params[:content][:body].nil? or params[:content][:body].strip.empty?
95
+ Attachment.destroy_all @content.id
96
+ #<%= class_name %>Mailer.deliver_inform "削除", @content
97
+ ContentHistory.create_for @content
98
+ ContentHistory.mark_as_deleted @content.id
99
+ @content.destroy
100
+ flash[:notice] = "ページ'#{params[:content][:title]}'を削除しました。"
101
+ redirect_to_frontpage
102
+ return
103
+ end
104
+
105
+ new_content = params[:content]
106
+ new_content[:version] = new_content[:version].to_i + 1
107
+ end
108
+
109
+ ContentHistory.create_for @content
110
+ if @content.update_attributes(new_content)
111
+ flash[:notice] = "更新しました。"
112
+ #<%= class_name %>Mailer.deliver_inform "更新", @content
113
+ if params[:commit] == '保存して編集を継続'
114
+ redirect_to :action => 'edit', :id => @content
115
+ else
116
+ redirect_to :action => 'show', :id => @content
117
+ end
118
+ else
119
+ render :action => 'edit'
120
+ end
121
+ end
122
+
123
+ def css
124
+ @title = 'CSS'
125
+ end
126
+
127
+ def change_css
128
+ session[:css] = params[:css]
129
+ redirect_to :action => 'css'
130
+ end
131
+
132
+ def handle_interwiki
133
+ interwikipage = Content.find :first, :conditions => "title = 'InterWikiName'"
134
+ if interwikipage.nil?
135
+ flash[:notice] = "ページ'InterWikiName'が存在しません。"
136
+ flash[:notice] = "Page, InterWikiName, does not exist."
137
+ redirect_to_frontpage
138
+ return
139
+ end
140
+
141
+ interwikinames = Hash.new
142
+ (interwikipage.body.split "\n").collect do |line|
143
+ if line =~ /^\s*\*\s*\[\[(.+)\|(.+)\]\](.*)$/
144
+ interwikinames[$1] = [$2, $3]
145
+ end
146
+ end
147
+
148
+ if interwikinames.include? params[:server]
149
+ redirect_to interwikinames[params[:server]][0] + URI.encode(params[:keyword].toutf8)
150
+ else
151
+ flash[:notice] = "Interwikiname, #{params[:server]}, has not been defined yet."
152
+ redirect_to_frontpage
153
+ end
154
+ end
155
+
156
+ def attach_file
157
+ attachment = Attachment.new_with_params params
158
+ if attachment.validate
159
+ attachment.save
160
+ flash[:notice] = "success to store"
161
+ else
162
+ flash[:notice] = attachment.error_message
163
+ end
164
+ redirect_to :action => 'show', :id => params[:attached][:id]
165
+ end
166
+
167
+ def detach_file
168
+ Attachment.new(params[:id], params[:filename]).destroy
169
+ redirect_to :action => 'show', :id => params[:id]
170
+ end
171
+
172
+ def fileinfo
173
+ @title = "Fileinfo: #{params[:filename]}"
174
+ @attachment = Attachment.new(params[:id], params[:filename]).info
175
+ end
176
+
177
+ def download
178
+ attachment = Attachment.new(params[:id], params[:filename]).info
179
+ if attachment.extname =~ /(jpg|jpeg|png|gif)/i
180
+ send_file attachment.cleanpath, type => "image/#{$1.downcase}"
181
+ else
182
+ send_file attachment.cleanpath
183
+ end
184
+ end
185
+
186
+ def diff
187
+ current = Content.find_by_id_or_title params
188
+ previous = ContentHistory.find :first, :conditions => ["content_id = :content_id", {:content_id => current.id}], :order => "version DESC"
189
+
190
+ @is_first = previous.nil?
191
+ @title = "Diff: #{current.title}"
192
+ @difference = ''
193
+
194
+ if @is_first
195
+ @difference = current.body.gsub(/^.*$/, ' \&')
196
+ else
197
+ @difference += difference_between(previous.body, current.body)
198
+ end
199
+ end
200
+
201
+ def search
202
+ @title = "Search"
203
+ end
204
+
205
+ def search_result
206
+ @title = "Search Result: #{params[:words]}"
207
+ words = (params[:words].split " ").uniq.collect{|e| "%#{e}%"}
208
+ if words.empty?
209
+ flash[:notice] = 'input at least one keyword'
210
+ redirect_to :action => 'search'
211
+ return
212
+ end
213
+
214
+ condition_sql = "body like ?"
215
+ (words.size - 1).times do
216
+ condition_sql += " and body like ?"
217
+ end
218
+ @contents = Content.find :all, :conditions => [condition_sql, *words], :order => "id"
219
+ end
220
+
221
+ def rss
222
+ require 'rss/maker'
223
+ rss = RSS::Maker.make("1.0") do |maker|
224
+ maker.channel.about = url_for(:controller => '<%= file_name %>', :action => 'rss')
225
+ maker.channel.title = "techno.hippy.jp"
226
+ maker.channel.link = url_for(:controller => '<%= file_name %>', :action => 'show')
227
+ maker.channel.description = "Railsを使ったWikiの動作確認"
228
+
229
+ Content.find(:all, :order=>"updated_at DESC", :limit=>15).each do |content|
230
+ item = maker.items.new_item
231
+ item.title = content.title
232
+ item.description = content.body.gsub(/^(.{0,200}).*/m,"\\1").toutf8 #truncate(content.body, 200)
233
+ item.content_encoded = <%= class_name %>Helper::<%= class_name %>Template.new.render content.body
234
+ item.date = content.updated_at
235
+ item.link = url_for(:controller => '<%= file_name %>', :action => 'show', :title => content.title)
236
+ end
237
+
238
+ maker.items.do_sort = true
239
+ maker.items.max_size = 15
240
+ end
241
+ @headers["Content-Type"] = 'application/xml; charset=UTF-8'
242
+ render :text => rss, :layout => false
243
+ end
244
+
245
+ private
246
+ def redirect_to_frontpage
247
+ redirect_to :action => 'show', :title => "FrontPage"
248
+ end
249
+
250
+ end