chatroom 0.0.8

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 (166) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +10 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +54 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/images/chatroom-icons/default.png +0 -0
  8. data/app/assets/images/emotions/0.gif +0 -0
  9. data/app/assets/images/emotions/1.gif +0 -0
  10. data/app/assets/images/emotions/10.gif +0 -0
  11. data/app/assets/images/emotions/100.gif +0 -0
  12. data/app/assets/images/emotions/101.gif +0 -0
  13. data/app/assets/images/emotions/102.gif +0 -0
  14. data/app/assets/images/emotions/103.gif +0 -0
  15. data/app/assets/images/emotions/104.gif +0 -0
  16. data/app/assets/images/emotions/105.gif +0 -0
  17. data/app/assets/images/emotions/106.gif +0 -0
  18. data/app/assets/images/emotions/107.gif +0 -0
  19. data/app/assets/images/emotions/108.gif +0 -0
  20. data/app/assets/images/emotions/109.gif +0 -0
  21. data/app/assets/images/emotions/11.gif +0 -0
  22. data/app/assets/images/emotions/110.gif +0 -0
  23. data/app/assets/images/emotions/111.gif +0 -0
  24. data/app/assets/images/emotions/112.gif +0 -0
  25. data/app/assets/images/emotions/113.gif +0 -0
  26. data/app/assets/images/emotions/114.gif +0 -0
  27. data/app/assets/images/emotions/115.gif +0 -0
  28. data/app/assets/images/emotions/116.gif +0 -0
  29. data/app/assets/images/emotions/117.gif +0 -0
  30. data/app/assets/images/emotions/118.gif +0 -0
  31. data/app/assets/images/emotions/119.gif +0 -0
  32. data/app/assets/images/emotions/12.gif +0 -0
  33. data/app/assets/images/emotions/120.gif +0 -0
  34. data/app/assets/images/emotions/121.gif +0 -0
  35. data/app/assets/images/emotions/122.gif +0 -0
  36. data/app/assets/images/emotions/123.gif +0 -0
  37. data/app/assets/images/emotions/124.gif +0 -0
  38. data/app/assets/images/emotions/125.gif +0 -0
  39. data/app/assets/images/emotions/126.gif +0 -0
  40. data/app/assets/images/emotions/127.gif +0 -0
  41. data/app/assets/images/emotions/128.gif +0 -0
  42. data/app/assets/images/emotions/129.gif +0 -0
  43. data/app/assets/images/emotions/13.gif +0 -0
  44. data/app/assets/images/emotions/130.gif +0 -0
  45. data/app/assets/images/emotions/131.gif +0 -0
  46. data/app/assets/images/emotions/132.gif +0 -0
  47. data/app/assets/images/emotions/133.gif +0 -0
  48. data/app/assets/images/emotions/134.gif +0 -0
  49. data/app/assets/images/emotions/14.gif +0 -0
  50. data/app/assets/images/emotions/15.gif +0 -0
  51. data/app/assets/images/emotions/16.gif +0 -0
  52. data/app/assets/images/emotions/17.gif +0 -0
  53. data/app/assets/images/emotions/18.gif +0 -0
  54. data/app/assets/images/emotions/19.gif +0 -0
  55. data/app/assets/images/emotions/2.gif +0 -0
  56. data/app/assets/images/emotions/20.gif +0 -0
  57. data/app/assets/images/emotions/21.gif +0 -0
  58. data/app/assets/images/emotions/22.gif +0 -0
  59. data/app/assets/images/emotions/23.gif +0 -0
  60. data/app/assets/images/emotions/24.gif +0 -0
  61. data/app/assets/images/emotions/25.gif +0 -0
  62. data/app/assets/images/emotions/26.gif +0 -0
  63. data/app/assets/images/emotions/27.gif +0 -0
  64. data/app/assets/images/emotions/28.gif +0 -0
  65. data/app/assets/images/emotions/29.gif +0 -0
  66. data/app/assets/images/emotions/3.gif +0 -0
  67. data/app/assets/images/emotions/30.gif +0 -0
  68. data/app/assets/images/emotions/31.gif +0 -0
  69. data/app/assets/images/emotions/32.gif +0 -0
  70. data/app/assets/images/emotions/33.gif +0 -0
  71. data/app/assets/images/emotions/34.gif +0 -0
  72. data/app/assets/images/emotions/35.gif +0 -0
  73. data/app/assets/images/emotions/36.gif +0 -0
  74. data/app/assets/images/emotions/37.gif +0 -0
  75. data/app/assets/images/emotions/38.gif +0 -0
  76. data/app/assets/images/emotions/39.gif +0 -0
  77. data/app/assets/images/emotions/4.gif +0 -0
  78. data/app/assets/images/emotions/40.gif +0 -0
  79. data/app/assets/images/emotions/41.gif +0 -0
  80. data/app/assets/images/emotions/42.gif +0 -0
  81. data/app/assets/images/emotions/43.gif +0 -0
  82. data/app/assets/images/emotions/44.gif +0 -0
  83. data/app/assets/images/emotions/45.gif +0 -0
  84. data/app/assets/images/emotions/46.gif +0 -0
  85. data/app/assets/images/emotions/47.gif +0 -0
  86. data/app/assets/images/emotions/48.gif +0 -0
  87. data/app/assets/images/emotions/49.gif +0 -0
  88. data/app/assets/images/emotions/5.gif +0 -0
  89. data/app/assets/images/emotions/50.gif +0 -0
  90. data/app/assets/images/emotions/51.gif +0 -0
  91. data/app/assets/images/emotions/52.gif +0 -0
  92. data/app/assets/images/emotions/53.gif +0 -0
  93. data/app/assets/images/emotions/54.gif +0 -0
  94. data/app/assets/images/emotions/55.gif +0 -0
  95. data/app/assets/images/emotions/56.gif +0 -0
  96. data/app/assets/images/emotions/57.gif +0 -0
  97. data/app/assets/images/emotions/58.gif +0 -0
  98. data/app/assets/images/emotions/59.gif +0 -0
  99. data/app/assets/images/emotions/6.gif +0 -0
  100. data/app/assets/images/emotions/60.gif +0 -0
  101. data/app/assets/images/emotions/61.gif +0 -0
  102. data/app/assets/images/emotions/62.gif +0 -0
  103. data/app/assets/images/emotions/63.gif +0 -0
  104. data/app/assets/images/emotions/64.gif +0 -0
  105. data/app/assets/images/emotions/65.gif +0 -0
  106. data/app/assets/images/emotions/66.gif +0 -0
  107. data/app/assets/images/emotions/67.gif +0 -0
  108. data/app/assets/images/emotions/68.gif +0 -0
  109. data/app/assets/images/emotions/69.gif +0 -0
  110. data/app/assets/images/emotions/7.gif +0 -0
  111. data/app/assets/images/emotions/70.gif +0 -0
  112. data/app/assets/images/emotions/71.gif +0 -0
  113. data/app/assets/images/emotions/72.gif +0 -0
  114. data/app/assets/images/emotions/73.gif +0 -0
  115. data/app/assets/images/emotions/74.gif +0 -0
  116. data/app/assets/images/emotions/75.gif +0 -0
  117. data/app/assets/images/emotions/76.gif +0 -0
  118. data/app/assets/images/emotions/77.gif +0 -0
  119. data/app/assets/images/emotions/78.gif +0 -0
  120. data/app/assets/images/emotions/79.gif +0 -0
  121. data/app/assets/images/emotions/8.gif +0 -0
  122. data/app/assets/images/emotions/80.gif +0 -0
  123. data/app/assets/images/emotions/81.gif +0 -0
  124. data/app/assets/images/emotions/82.gif +0 -0
  125. data/app/assets/images/emotions/83.gif +0 -0
  126. data/app/assets/images/emotions/84.gif +0 -0
  127. data/app/assets/images/emotions/85.gif +0 -0
  128. data/app/assets/images/emotions/86.gif +0 -0
  129. data/app/assets/images/emotions/87.gif +0 -0
  130. data/app/assets/images/emotions/88.gif +0 -0
  131. data/app/assets/images/emotions/89.gif +0 -0
  132. data/app/assets/images/emotions/9.gif +0 -0
  133. data/app/assets/images/emotions/90.gif +0 -0
  134. data/app/assets/images/emotions/91.gif +0 -0
  135. data/app/assets/images/emotions/92.gif +0 -0
  136. data/app/assets/images/emotions/93.gif +0 -0
  137. data/app/assets/images/emotions/94.gif +0 -0
  138. data/app/assets/images/emotions/95.gif +0 -0
  139. data/app/assets/images/emotions/96.gif +0 -0
  140. data/app/assets/images/emotions/97.gif +0 -0
  141. data/app/assets/images/emotions/98.gif +0 -0
  142. data/app/assets/images/emotions/99.gif +0 -0
  143. data/app/assets/images/emotions/static.gif +0 -0
  144. data/app/assets/javascripts/chatroom/marks.js +34 -0
  145. data/app/assets/javascripts/chatroom/messages.js.coffee +145 -0
  146. data/app/assets/stylesheets/chatroom/messages.css.scss +300 -0
  147. data/app/controllers/chatroom/messages_controller.rb +20 -0
  148. data/app/helpers/chatroom/message_helper.rb +26 -0
  149. data/app/views/chatroom/messages/_chatroom.html.erb +15 -0
  150. data/app/views/chatroom/messages/_form.html.erb +35 -0
  151. data/app/views/chatroom/messages/create.js.erb +6 -0
  152. data/chatroom.gemspec +26 -0
  153. data/lib/chatroom.rb +12 -0
  154. data/lib/chatroom/engine.rb +14 -0
  155. data/lib/chatroom/version.rb +3 -0
  156. data/lib/generators/active_record/chatroom_generator.rb +43 -0
  157. data/lib/generators/active_record/templates/migration.rb +14 -0
  158. data/lib/generators/chatroom/assets_generator.rb +40 -0
  159. data/lib/generators/chatroom/chatroom_generator.rb +40 -0
  160. data/lib/generators/chatroom/controllers_generator.rb +24 -0
  161. data/lib/generators/chatroom/helpers_generator.rb +24 -0
  162. data/lib/generators/chatroom/install_generator.rb +19 -0
  163. data/lib/generators/chatroom/orm_helpers.rb +59 -0
  164. data/lib/generators/chatroom/views_generator.rb +38 -0
  165. data/lib/generators/templates/chatroom.rb +3 -0
  166. metadata +278 -0
@@ -0,0 +1,26 @@
1
+ module Chatroom
2
+ module MessageHelper
3
+ def new_communication(msg=nil)
4
+ "<span class='message-line'>
5
+ <div class='info-message'>
6
+ <span class='sender'>:</span><span class='send-time'>#{msg.try(:send_time)}</span>
7
+ </div>
8
+ <span class='say'>#{msg.try(:html_content)}</span>
9
+ </span>"
10
+ end
11
+
12
+ # Show all the communications in chatroom
13
+ def show_communications(msgs=nil)
14
+ msgs ||= []
15
+ messages = msgs.collect do |msg|
16
+ "<span class='message-line'>
17
+ <div class='info-message'>
18
+ <span class='sender'>:</span><span class='send-time'>#{msg.try(:send_time)}</span>
19
+ </div>
20
+ <span class='say'>#{msg.try(:html_content)}</span>
21
+ </span>"
22
+ end
23
+ messages.join('')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ <div id="chatroom">
2
+ <div class="min-chatroom">Chatroom</div>
3
+
4
+ <div class="chat-show">
5
+ <div id="chat">
6
+ <%= show_communications(@messages).html_safe %>
7
+ </div>
8
+ </div>
9
+ <%= render "chatroom/messages/form" %>
10
+ </div>
11
+ <%= subscribe_to "/messages/new" %>
12
+
13
+ <div id="chatBeam">
14
+ <div class="max-chatroom">Chatroom</div>
15
+ </div>
@@ -0,0 +1,35 @@
1
+ <div class="chat-send">
2
+
3
+ <%= form_for Message.new, :remote => true, :html => { :class => "send-message" } do |f| %>
4
+ <div class="send-bar">
5
+ <%= link_to "", :class => "font-colorer" do%>
6
+ <i class="font-colorer-icon"></i>
7
+ <table class="chatroom-font-colors">
8
+ <tbody>
9
+ </tbody>
10
+ </table>
11
+ <% end %>
12
+
13
+ <%= link_to "", :class => "emotions" do%>
14
+ <i class="emotions-icon"></i>
15
+ <table class="chatroom-emotions-images">
16
+ <tbody>
17
+ </tbody>
18
+ </table>
19
+ <% end %>
20
+
21
+ <%= link_to "", :class => "font-bloder" do%>
22
+ <i class="font-bloder-icon"></i>
23
+ <% end %>
24
+
25
+ <%= link_to "", :class => "font-italic" do%>
26
+ <i class="font-italic-icon"></i>
27
+ <% end %>
28
+ </div>
29
+
30
+ <%= f.text_area :content, :id => "new_message_editor", :rows => 5 %>
31
+
32
+ <div class="send"><%= f.submit "Send", :class => "btn" %></div>
33
+ <% end %>
34
+ </div>
35
+
@@ -0,0 +1,6 @@
1
+ <% publish_to "/messages/new" do %>
2
+ $("#chat").append("<%= escape_javascript new_communication(@message).html_safe %>");
3
+ <% end %>
4
+ $("#chat").animate({scrollTop: $("#chat")[0].scrollHeight}, 100);
5
+
6
+ $("#new_message_content").val('');
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chatroom/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chatroom"
8
+ spec.version = Chatroom::VERSION
9
+ spec.authors = ["TsaiKoga"]
10
+ spec.email = ["969024089@qq.com"]
11
+ spec.description = %q{This gem can help you create a chatroom.}
12
+ spec.summary = %q{Chatroom provides functions, like adding emotions or changing text pattern.}
13
+ spec.homepage = "http://github.com/TsaiKoga/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "faye", "~> 1.0.0"
24
+ spec.add_development_dependency "private_pub", "~> 1.0.3"
25
+ spec.add_development_dependency "thin", "~> 1.5.1"
26
+ end
@@ -0,0 +1,12 @@
1
+ module Chatroom
2
+
3
+ require 'chatroom/engine' if defined?(Rails)
4
+ require 'generators/chatroom/install_generator'
5
+
6
+ # Default way to setup Chatroom. Run rails generate chatroom_install to create
7
+ # a fresh initializer with all configuration values.
8
+ # def self.setup
9
+ # yield self
10
+ # end
11
+
12
+ end
@@ -0,0 +1,14 @@
1
+ require "rails"
2
+
3
+ module Chatroom
4
+ class Engine < Rails::Engine
5
+ # ==> HookFor Configuration
6
+ # It allows you to implement a generators command by hooking for views,
7
+ # helpers or controllers.
8
+ config.generators do |g|
9
+ g.views :views
10
+ g.helpers :helpers
11
+ g.controllers :controllers
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Chatroom
2
+ VERSION = "0.0.8"
3
+ end
@@ -0,0 +1,43 @@
1
+ require "rails/generators/active_record"
2
+ require "generators/chatroom/orm_helpers"
3
+
4
+ module ActiveRecord
5
+ module Generators
6
+ class ChatroomGenerator < ActiveRecord::Generators::Base
7
+ argument :attributes, :type => :array, :default => [], :banner => "field: type field: type"
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+ include Chatroom::Generators::OrmHelpers
11
+
12
+ def copy_chatroom_migration
13
+ migration_template "migration.rb", "db/migrate/chatroom_create_#{table_name}"
14
+ end
15
+
16
+ def migration_data
17
+ <<RUBY
18
+ t.text :content, :null => false
19
+ RUBY
20
+ end
21
+
22
+ def generate_model
23
+ invoke "active_record:model", [name], :migration => false
24
+ end
25
+
26
+ def inject_chatroom_content
27
+ content = model_contents
28
+
29
+ class_path = if namespaced?
30
+ class_name.to_s.split("::")
31
+ else
32
+ [class_name]
33
+ end
34
+ indent_depth = class_path.size - 1
35
+
36
+ content = content.split("\n").map { |line| " " * indent_depth + line }.join("\n") << "\n"
37
+
38
+ inject_into_class(model_path, class_path.last, content) if model_exists?
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ class ChatroomCreate<%= table_name.camelize %> < ActiveRecord::Migration
3
+ def change
4
+ create_table(:<%= table_name %>) do |t|
5
+ <%= migration_data -%>
6
+
7
+ <% attributes.each do |attribute| -%>
8
+ t.<%= attribute.type %> :<%= attribute.name %>
9
+ <% end -%>
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ module Chatroom
2
+ module Generators
3
+ class AssetsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../../../app/assets', __FILE__)
5
+
6
+ desc "Generators the assets including coffee and sass"
7
+
8
+ def generate_stylesheets
9
+ directory "stylesheets/chatroom", "#{stylesheets_target_path}" do |content|
10
+ content
11
+ end
12
+ end
13
+
14
+ def generate_coffees
15
+ directory "javascripts/chatroom", "#{javascripts_target_path}" do |content|
16
+ content
17
+ end
18
+ end
19
+
20
+ def generate_images
21
+ directory "images", "#{images_target_path}" do |content|
22
+ content
23
+ end
24
+ end
25
+
26
+ private
27
+ def stylesheets_target_path
28
+ @stylesheets_target_path ||= "app/assets/stylesheets/chatroom"
29
+ end
30
+
31
+ def javascripts_target_path
32
+ @javascripts_target_path ||= "app/assets/javascripts/chatroom"
33
+ end
34
+
35
+ def images_target_path
36
+ @images_target_path ||= "app/assets/images"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module Chatroom
2
+ module Generators
3
+ class ChatroomGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::ResourceHelpers
5
+
6
+ namespace "chatroom"
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ desc "Generators a model with the given NAME (if one does not exists) with chatroom " <<
10
+ "configuration plus a migration file, controller_file, assets_file, views_file and chatroom routes." <<
11
+ "Setup the faye server for chatting."
12
+
13
+ class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
14
+
15
+ hook_for :orm
16
+ # hook_for :views
17
+ # hook_for :controllers
18
+ hook_for :assets
19
+ # hook_for :helpers
20
+
21
+ def add_chatroom_routes
22
+ chatroom_route = <<-ROUTE
23
+ resources :#{plural_name}, module: 'chatroom'
24
+ ROUTE
25
+ route chatroom_route
26
+ end
27
+
28
+ def setup_private_pub
29
+ gem 'private_pub', '1.0.3'
30
+ gem 'thin', '1.5.1'
31
+ generate 'private_pub:install'
32
+
33
+ inject_into_file 'app/assets/javascripts/application.js', before: '//= require_tree .' do <<-RUBY
34
+ //= require private_pub
35
+ RUBY
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ module Chatroom
2
+ # Include this module in your generator to generate Chatroom controllers.
3
+ # 'copy_controllers' is the main method and by default copies all controllers.
4
+ module ControllerPathTemplates
5
+ protected
6
+ def target_path
7
+ @target_path ||= "app/controllers"
8
+ end
9
+
10
+ def controller_directory(name, _target_path = nil)
11
+ directory name.to_s, _target_path || "#{target_path}/#{name}"
12
+ end
13
+ end
14
+
15
+ class ControllersGenerator < Rails::Generators::Base
16
+ include ControllerPathTemplates
17
+ source_root File.expand_path('../../../../app/controllers', __FILE__)
18
+ desc "Copies Chatroom controllers to your application."
19
+
20
+ def copy_controllers
21
+ controller_directory(:chatroom)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Chatroom
2
+ # Include this module in your generator to generate Chatroom helpers.
3
+ # 'copy_helpers' is the main method and by default copies all helpers.
4
+ module HelperPathTemplates
5
+ protected
6
+ def target_path
7
+ @target_path ||= "app/helpers"
8
+ end
9
+
10
+ def helper_directory(name, _target_path = nil)
11
+ directory name.to_s, _target_path || "#{target_path}/#{name}"
12
+ end
13
+ end
14
+
15
+ class HelpersGenerator < Rails::Generators::Base
16
+ include HelperPathTemplates
17
+ source_root File.expand_path('../../../../app/helpers', __FILE__)
18
+ desc "Copies Chatroom helpers to your application."
19
+
20
+ def copy_helpers
21
+ helper_directory(:chatroom)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require "rails/generators"
2
+ module Chatroom
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc "Create a Chatroom initalizer and run generators."
8
+ class_option :orm
9
+
10
+ def install_app
11
+ generate "chatroom messages"
12
+ generate "chatroom:views"
13
+ generate "chatroom:helpers"
14
+ generate "chatroom:controllers"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ module Chatroom
2
+ module Generators
3
+ module OrmHelpers
4
+ def model_contents
5
+ buffer = <<-CONTENT
6
+ # validates
7
+ validates :content, :presence => true, :length => { :maximum => 250 }
8
+
9
+ EMOTIONS = [
10
+ "smile", "despressed", "like", "dull", "proud", "cry", "shy", "shut up",
11
+ "nap", "big cry", "awkward red", "angry", "naughty", "snag", "surprise", "bad",
12
+ "cool", "awkward", "scream", "vomit", "giggle", "lovely", "who cares", "zhuai",
13
+ "hungry", "sleepy", "scared", "sweat", "simper", "solider", "strive", "shout",
14
+ "questionaire", "hiss", "dizzy", "impantient", "be bombed", "skull", "hit head", "bye"
15
+ ]
16
+
17
+ # The created time of the message
18
+ def send_time
19
+ self.created_at.strftime("%Y-%m-%d %H:%M:%d")
20
+ end
21
+
22
+ # convert the marks to html tags
23
+ def html_content
24
+ return "" if content.blank?
25
+ str = content.gsub(/\\[bold\\]/, "<b>")
26
+ str = str.gsub(/\\[-bold\\]/, "</b>")
27
+ str = str.gsub(/\\[italic\\]/, "<i>")
28
+ str = str.gsub(/\\[-italic\\]/, "</i>")
29
+ str = str.gsub(/\\[color:(#.{6})\\]/){ |s| "<span style=\\"color:\#{$1}\\">" }
30
+ str = str.gsub(/\\[-color\\]/, "</span>")
31
+ str = str.gsub(/\\[(.+)\\]/) do |s|
32
+ emotion = EMOTIONS.index($1)
33
+ emotion.nil? ? "[\#{$1}]": "<img src=\\"/assets/emotions/\#{emotion}.gif\\" />"
34
+ end
35
+ return str
36
+ end
37
+ CONTENT
38
+ buffer
39
+ end
40
+
41
+ private
42
+ def model_exists?
43
+ File.exists?(File.join(destination_root, model_path))
44
+ end
45
+
46
+ def migration_exists?
47
+ Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
48
+ end
49
+
50
+ def migration_path
51
+ @migration_path ||= File.join("db", "migrate")
52
+ end
53
+
54
+ def model_path
55
+ @model_path ||= File.join("app", "models", "#{file_path}.rb")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,38 @@
1
+ module Chatroom
2
+ # Include this module in your generator to generate Chatroom views.
3
+ # 'copy_views' is the main method and by default copies all views.
4
+ module ViewPathTemplates
5
+
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def hide!
12
+ Rails::Generators.hide_namespace self.namespace
13
+ end
14
+ end
15
+
16
+ protected
17
+ def target_path
18
+ @target_path ||= "app/views/chatroom"
19
+ end
20
+
21
+ def view_directory(name, _target_path = nil)
22
+ directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
23
+ content
24
+ end
25
+ end
26
+ end
27
+
28
+ class ViewsGenerator < Rails::Generators::Base
29
+ include ViewPathTemplates
30
+ source_root File.expand_path('../../../../app/views/chatroom', __FILE__)
31
+
32
+ desc "Copies Chatroom views to your application."
33
+
34
+ def copy_views
35
+ view_directory :messages
36
+ end
37
+ end
38
+ end