diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 288b9ab..454ecdd 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,10 @@ *= require_tree . *= require_self */ + +body { + background: #fff; + color: #333; + margin: 0; + padding: .5rem 1rem; +} \ No newline at end of file diff --git a/app/assets/stylesheets/messages.css b/app/assets/stylesheets/messages.css new file mode 100644 index 0000000..9fc4546 --- /dev/null +++ b/app/assets/stylesheets/messages.css @@ -0,0 +1,15 @@ + +.headers { + list-style: none; + padding: 0 0 1rem 0; + border-bottom: 1px solid #000; +} + +.search { + padding: 0 0 1rem 0; + border-bottom: 1px solid #000; +} + +h2 { + font-size: 100%; +} \ No newline at end of file diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb index f1bca9f..ebe9e68 100644 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -1,2 +1,24 @@ module MessagesHelper + def without_list_prefix(subject) + subject.sub(/^\[.+\]\s*/, '') + end + + MARGIN = 50 + def search_snippet(body, keyword) + snippet = '' + + offset = 0 + while (i = body.index(keyword, offset)) + start = [i - MARGIN, offset].max + len = keyword.length + MARGIN + snippet += body[start, len] + offset = start + len + end + + if snippet.empty? + return body[0, MARGIN * 2] + else + snippet + end + end end diff --git a/app/models/message.rb b/app/models/message.rb index 50c9210..23c7329 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -37,19 +37,21 @@ def self.from_string(str) published_at = DateTime.strptime(headers['Date'], '%Y-%m-%dT%H:%M:%S%:z') self.new( - body: body, + body: Kconv.toutf8(body), subject: headers['Subject'], from: headers['From'], published_at: published_at, ) end - def reload_from_s3 - m = self.from_s3(List.find_by_id(self.list_id).name, self.list_seq) + def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION)) + m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client) self.body = m.body self.subject = m.subject self.from = from self.published_at = m.published_at + + m end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e44a8a4..9d58673 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,13 @@
-- Subject: - <%= message.subject %> -
- -- From: - <%= message.from %> -
+<% content_for :title, message.subject %> + diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb index cdd2df6..45c2825 100644 --- a/app/views/messages/index.html.erb +++ b/app/views/messages/index.html.erb @@ -2,32 +2,36 @@- <% - [ - [:ruby_talk, 'ruby-talk (English)'], - [:ruby_core, 'ruby-core (For developing Ruby iself, English)'], - [:ruby_list, 'ruby-list (Japanese)'], - [:ruby_dev, 'ruby-dev (For developing Ruby itself, Japanese)'], - ].each do |name, label| - %> - - <%= form.check_box name, {checked: params[name] != '0' } %> - <%= form.label name, label %> - - <% end %> -
-<% end %> ++ <% + [ + [:ruby_talk, 'ruby-talk (English)'], + [:ruby_core, 'ruby-core (For developing Ruby iself, English)'], + [:ruby_list, 'ruby-list (Japanese)'], + [:ruby_dev, 'ruby-dev (For developing Ruby itself, Japanese)'], + ].each do |name, label| + %> + + <%= form.check_box name, {checked: params[name] != '0' } %> + <%= form.label name, label %> + + <% end %> +
+ <% end %> +