Skip to content

Commit

Permalink
Adds a few plugins and fixes
Browse files Browse the repository at this point in the history
* Adds basic styling for sidebar
* Adds link plugin
* Adds image plugin
* Adds Youtube plugin
* Adds basic music player plugin [WIP]
* Adds a stub Kandan.Store API to get music player working
* View fix: escapes message if not processed by a modifier
* Template fix: unescape certain elements in templates
* Switch from jquery template to underscore templates
* Deletes unnecessary templates
* Removes ember-rails dependency

Signed-off-by: Akash Manohar J <akash@akash.im>
  • Loading branch information
HashNuke committed Mar 15, 2012
1 parent 75afafb commit 1c64ec5
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 31 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ group :assets do
gem 'uglifier', '>= 1.0.3'
end

# TODO remove git dependency after development
gem 'ember-rails', :git => "https://github.com/emberjs/ember-rails.git"
gem 'jquery-rails'

gem 'jasmine', :git => "https://github.com/pivotal/jasmine-gem.git", :branch => "1.2.rc1", :group => [:development, :test]
Expand Down
9 changes: 0 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
GIT
remote: https://github.com/emberjs/ember-rails.git
revision: 1614e7dac6dcd83a68b4f5ea479d2fec7094d781
specs:
ember-rails (0.2.4)
execjs (>= 1.2)
railties (>= 3.0)

GIT
remote: https://github.com/pivotal/jasmine-gem.git
revision: 5a7524ae9eaea4fe106a7aaa90ccfb1bc137abe7
Expand Down Expand Up @@ -224,7 +216,6 @@ DEPENDENCIES
devise
devise_bushido_authenticatable
eco
ember-rails!
execjs
factory_girl_rails
faye
Expand Down
2 changes: 0 additions & 2 deletions app/assets/javascripts/backbone/modifiers.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class Kandan.Modifiers

@process: (message, state)->
for modifier in @modifiers
console.log "pre message", message.content
if message.content.match(modifier.regex)!=null
modified_object = modifier.callback(message, state)
console.log "modified", modified_object
return modified_object if modified_object != false
false
11 changes: 11 additions & 0 deletions app/assets/javascripts/backbone/plugins/image_embed.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Kandan.Plugins.ImageEmbed
@regex: /^http.*\.(jpg|jpeg|gif|png)/i
@image_template: _.template('<a target="_blank" href="<%= image_url %>"><img class="image-embed" src="<%= image_url %>" height="200" width="200" /></a>')

@init: ()->
Kandan.Modifiers.register @regex, (message, state)=>
message.content = @image_template({ image_url: message.content })
console.log message.content
return Kandan.Helpers.Activities.build_from_message_template(message)

Kandan.Plugins.register "Kandan.Plugins.ImageEmbed"
8 changes: 5 additions & 3 deletions app/assets/javascripts/backbone/plugins/link.js.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class Kandan.Plugins.Link
class Kandan.Plugins.LinkEmbed

@regex: /http:\S*/g
@link_template: _.template('<a target="_blank" href="<%- url %>"><%- url %></a>')

@init: ()->
Kandan.Modifiers.register @regex, (message, state)=>
message.content = message.content.replace @regex, '<a target="_blank" href="$1">$1</a>'
message.content = message.content
.replace(@regex, @link_template({ url: "$1" }))
return Kandan.Helpers.Activities.build_from_message_template(message)

Kandan.Plugins.register "Kandan.Plugins.Link"
Kandan.Plugins.register "Kandan.Plugins.LinkEmbed"
84 changes: 84 additions & 0 deletions app/assets/javascripts/backbone/plugins/music_player.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class Kandan.Plugins.MusicPlayer

@plugin_namespace: "Kandan.Plugins.MusicPlayer"
@plugin_id: ""
@widget_name: "music_player"
@play_regex: /^\/play .+/
@stop_regex: /^\/stop/
@local_song_data: false


@play_template: _.template('<strong><a class="audio-play">playing</a> <a target="_blank" href="<%- url %>"><%- url %></a></strong>')
@song_template: _.template('<li><%= song.split("/").pop() %></li>')


@set_error: (error_message)->
console.log "music player error", error_message


@create_song_list: (songs)->
$songs = $('<ul class="songs"></ul>')
if songs.length == 0
$songs = "No songs! Maybe add some?"
else
$songs.append(@song_template({song: song})) for song in songs
return $songs


@render: ($widget_el)->
$widget_element_class = $widget_el.attr('class')

if @local_song_data
$songs = @create_song_list(@local_song_data)
else
@get_songs({
success: (songs)=>
$songs = @create_song_list(songs)

failure: ()->
@set_error("Could not load songs")
})
$widget_el.html($songs)


# TODO add support for sounds
@init: (plugin_id)->
@plugin_id = plugin_id
@register_modifier()
@register_widget()


@register_widget: ()->
Kandan.Widgets.register @widget_name, @plugin_namespace


@register_modifier: ()->
Kandan.Modifiers.register @play_regex, (message, state)=>
if state == Kandan.Helpers.Activities.ACTIVE_STATE
console.log "add song to player and play song"
@store_song url
else
console.log "song is history"

message.content = @play_template({url: message.content.split @play_regex})
return Kandan.Helpers.Activities.build_from_base_template message


# TODO display error about song not being added by creating an activity locally
@store_song: (url)->
@get_songs({
success: (data)=>
data.push url
Kandan.Store.set @plugin_id, {
success: (data)->
@local_song_data = data
Kandan.Widgets.render_widget @widget_name
}
})


@get_songs: (callbacks)->
Kandan.Store.get @plugin_id, callbacks


Kandan.Plugins.register "Kandan.Plugins.MusicPlayer"
3 changes: 1 addition & 2 deletions app/assets/javascripts/backbone/plugins/user_list.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ class Kandan.Plugins.UserList
@widget_name: "user_list"

@render: ($el)->
console.log "rendering user list"
$users = $("<ul></ul>")

for user in Kandan.Data.ActiveUsers.all()
$users.append "<li>#{user.first_name} #{user.last_name}</li>"
$el.html($users)


@init: ()->
console.log "init user plugin"
Kandan.Widgets.register(@widget_name, "Kandan.Plugins.UserList")
Kandan.Data.ActiveUsers.register_callback "change", ()=>
Kandan.Widgets.render(@widget_name)
Expand Down
18 changes: 18 additions & 0 deletions app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Kandan.Plugins.YoutubeEmbed

@regex: /^http(s)?:\/\/www.youtube.com\/watch/i
@youtube_id_pattern: /\Wv=([\w|\-]*)/

@youtube_embed_template: _.template('<div class="youtube-preview"><a target="_blank" class="youtube-preview-link" href="<%= video_url %>"><img class="youtube-preview-image" src="<% thumb_url %>" /></a></div>')

@init: ()->
Kandan.Modifiers.register @regex, (message, state)=>
video_id = message.content.match(@youtube_id_pattern)[1]
thumb_url = "http://img.youtube.com/vi/#{ video_id }/0.jpg"
message.content = @youtube_embed_template({
video_url: message.content,
image_url: thumb_url
})
return Kandan.Helpers.Activities.build_from_message_template(message)

Kandan.Plugins.register "Kandan.Plugins.YoutubeEmbed"
5 changes: 0 additions & 5 deletions app/assets/javascripts/backbone/post_init.js.coffee

This file was deleted.

8 changes: 8 additions & 0 deletions app/assets/javascripts/backbone/store.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Kandan.Store
@get: (plugin_id, callbacks)->
# TODO this should change
data = ["http://google.com/song.mp3", "http://google.com/song2.mp3"]
callbacks.success(data)

@set: (plugin_id, callbacks)->
callbacks.success(data)
8 changes: 4 additions & 4 deletions app/assets/javascripts/backbone/views/show_activity.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class Kandan.Views.ShowActivity extends Backbone.View
if activity.action != "message"
@compiled_template = JST['user_notification']({activity: activity})
else
modifier = Kandan.Modifiers.process(activity, @options.state)
if modifier != false
@compiled_template = modifier
modified_message = Kandan.Modifiers.process(activity, @options.state)
if modified_message != false
@compiled_template = modified_message
else
@compiled_template = Kandan.Helpers.Activities.build_from_message_template activity
@compiled_template = Kandan.Helpers.Activities.build_from_message_template $.extend(activity, {content: _.escape(activity.content)})


$(@el).html(@compiled_template)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
*= require_self
*= require_tree .
*/

.container {width: 80%; float: left}
.sidebar {width: 20%; float: right}
1 change: 0 additions & 1 deletion app/assets/templates/activity.jst.eco

This file was deleted.

2 changes: 1 addition & 1 deletion app/assets/templates/activity_base.jst.eco
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= @activity.content %>
<%- @activity.content %>
2 changes: 1 addition & 1 deletion app/assets/templates/message.jst.eco
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= @activity.user.first_name %>: <%= @activity.content %>
<%= @activity.user.first_name %>: <%- @activity.content %>
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class User < ActiveRecord::Base

# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :devise_authenticatable, :token_authenticatable, :trackable
devise :bushido_authenticatable, :token_authenticatable, :trackable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :ido_id, :first_name, :last_name, :locale
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"

config.cas_base_url = "http://noshido.com:3000/cas" if Rails.env.development?

# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"

Expand Down

0 comments on commit 1c64ec5

Please sign in to comment.