transit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/Gemfile +19 -11
  2. data/app/assets/images/transit/icon24x24.png +0 -0
  3. data/app/assets/images/transit/icon24x24_files.png +0 -0
  4. data/app/assets/images/transit/jplayer.swf +0 -0
  5. data/app/assets/images/transit/uploadify.swf +0 -0
  6. data/app/assets/images/transit/video_player.swf +0 -0
  7. data/app/assets/javascripts/jqtools/expose.js +224 -0
  8. data/app/assets/javascripts/jqtools/flashembed.js +300 -0
  9. data/app/assets/javascripts/jqtools/overlay.js +294 -0
  10. data/app/assets/javascripts/jqtools/scrollable.js +3 -0
  11. data/app/assets/javascripts/jqtools/scrollable/autoscroll.js +81 -0
  12. data/app/assets/javascripts/jqtools/scrollable/base.js +335 -0
  13. data/app/assets/javascripts/jqtools/scrollable/navigator.js +139 -0
  14. data/app/assets/javascripts/jqtools/validator.js +590 -0
  15. data/app/assets/javascripts/jqueryui/accordion.js +611 -0
  16. data/app/assets/javascripts/jqueryui/autocomplete.js +612 -0
  17. data/app/assets/javascripts/jqueryui/button.js +388 -0
  18. data/app/assets/javascripts/jqueryui/core.js +312 -0
  19. data/app/assets/javascripts/jqueryui/datepicker.js +1791 -0
  20. data/app/assets/javascripts/jqueryui/dialog.js +878 -0
  21. data/app/assets/javascripts/jqueryui/draggable.js +815 -0
  22. data/app/assets/javascripts/jqueryui/droppable.js +285 -0
  23. data/app/assets/javascripts/jqueryui/effects/blind.js +49 -0
  24. data/app/assets/javascripts/jqueryui/effects/bounce.js +78 -0
  25. data/app/assets/javascripts/jqueryui/effects/clip.js +54 -0
  26. data/app/assets/javascripts/jqueryui/effects/core.js +746 -0
  27. data/app/assets/javascripts/jqueryui/effects/drop.js +50 -0
  28. data/app/assets/javascripts/jqueryui/effects/explode.js +79 -0
  29. data/app/assets/javascripts/jqueryui/effects/fade.js +32 -0
  30. data/app/assets/javascripts/jqueryui/effects/fold.js +56 -0
  31. data/app/assets/javascripts/jqueryui/effects/highlight.js +50 -0
  32. data/app/assets/javascripts/jqueryui/effects/pulsate.js +51 -0
  33. data/app/assets/javascripts/jqueryui/effects/scale.js +178 -0
  34. data/app/assets/javascripts/jqueryui/effects/shake.js +57 -0
  35. data/app/assets/javascripts/jqueryui/effects/slide.js +50 -0
  36. data/app/assets/javascripts/jqueryui/effects/transfer.js +45 -0
  37. data/app/assets/javascripts/jqueryui/mouse.js +160 -0
  38. data/app/assets/javascripts/jqueryui/position.js +252 -0
  39. data/app/assets/javascripts/jqueryui/progressbar.js +109 -0
  40. data/app/assets/javascripts/jqueryui/resizable.js +814 -0
  41. data/app/assets/javascripts/jqueryui/selectable.js +266 -0
  42. data/app/assets/javascripts/jqueryui/slider.js +666 -0
  43. data/app/assets/javascripts/jqueryui/sortable.js +1077 -0
  44. data/app/assets/javascripts/jqueryui/tabs.js +758 -0
  45. data/app/assets/javascripts/jqueryui/widget.js +262 -0
  46. data/app/assets/javascripts/libs/backbone.js +1152 -0
  47. data/app/assets/javascripts/libs/cookie.js +89 -0
  48. data/app/assets/javascripts/libs/fileinput.js +130 -0
  49. data/app/assets/javascripts/libs/jplayer.js +1768 -0
  50. data/app/assets/javascripts/libs/proper.js +541 -0
  51. data/app/assets/javascripts/libs/sanitize.js +282 -0
  52. data/app/assets/javascripts/libs/selecttolist.js +75 -0
  53. data/app/assets/javascripts/libs/underscore.js +807 -0
  54. data/app/assets/javascripts/libs/uploadify.js +677 -0
  55. data/app/assets/javascripts/libs/wymeditor.js +9538 -0
  56. data/app/assets/javascripts/transit.js +4 -0
  57. data/app/assets/javascripts/transit/admin.js +22 -0
  58. data/app/assets/javascripts/transit/admin/contexts.js +52 -0
  59. data/app/assets/javascripts/transit/admin/fields.js +36 -0
  60. data/app/assets/javascripts/transit/admin/upload.js +109 -0
  61. data/app/assets/javascripts/transit/config.js.erb +101 -0
  62. data/app/assets/javascripts/transit/contexts/audio.js +39 -0
  63. data/app/assets/javascripts/transit/contexts/video.js +79 -0
  64. data/app/assets/javascripts/transit/core.js +171 -0
  65. data/app/assets/javascripts/transit/frontend.js +3 -0
  66. data/app/assets/javascripts/transit/lib/base64.js +120 -0
  67. data/app/assets/javascripts/transit/lib/editor.js +177 -0
  68. data/app/assets/javascripts/transit/views/audio_player.jst +22 -0
  69. data/app/assets/javascripts/transit/views/editor_toolbar.jst +12 -0
  70. data/app/assets/javascripts/transit/views/file_upload.jst +5 -0
  71. data/app/assets/javascripts/transit/views/video_player.jst +20 -0
  72. data/app/assets/javascripts/transit/views/wym_box.jst +4 -0
  73. data/app/assets/javascripts/transit/views/wym_iframe.jst +3 -0
  74. data/app/assets/stylesheets/transit.css.scss.erb +42 -0
  75. data/app/assets/stylesheets/transit/forms.css.scss +66 -0
  76. data/app/assets/stylesheets/transit/media/audio.css.scss +65 -0
  77. data/app/assets/stylesheets/transit/media/video.css.scss +30 -0
  78. data/app/assets/stylesheets/transit/panel.css.scss +100 -0
  79. data/app/assets/stylesheets/transit/ui.css.scss +507 -0
  80. data/app/controllers/pages_controller.rb +3 -0
  81. data/app/controllers/posts_controller.rb +3 -0
  82. data/app/controllers/transit/assets_controller.rb +38 -0
  83. data/app/controllers/transit/contexts_controller.rb +12 -9
  84. data/app/controllers/transit/pages_controller.rb +26 -0
  85. data/app/controllers/transit/posts_controller.rb +31 -0
  86. data/app/controllers/transit/topics_controller.rb +5 -0
  87. data/app/controllers/transit_controller.rb +16 -0
  88. data/app/helpers/transit/admin_helper.rb +43 -0
  89. data/app/helpers/transit/form_helper.rb +17 -0
  90. data/app/helpers/transit/package_helper.rb +41 -0
  91. data/app/helpers/transit/pagination_helper.rb +58 -0
  92. data/app/helpers/transit_helper.rb +42 -0
  93. data/app/models/comment.rb +37 -0
  94. data/app/models/contexts/audio.rb +12 -0
  95. data/app/models/{text.rb → contexts/text.rb} +0 -0
  96. data/app/models/contexts/video.rb +24 -0
  97. data/app/models/topic.rb +19 -0
  98. data/app/models/transit/asset.rb +68 -0
  99. data/{lib → app/models}/transit/context.rb +29 -0
  100. data/app/views/contexts/_text.html.erb +1 -1
  101. data/app/views/posts/index.rss.builder +18 -0
  102. data/app/views/transit/assets/_file.html.erb +4 -0
  103. data/app/views/transit/assets/_image.html.erb +13 -0
  104. data/app/views/transit/assets/create.js.erb +8 -0
  105. data/app/views/transit/assets/destroy.js.erb +3 -0
  106. data/app/views/transit/assets/manage.html.erb +20 -0
  107. data/app/views/transit/contexts/_audio.html.erb +18 -0
  108. data/app/views/transit/contexts/_text.html.erb +6 -0
  109. data/app/views/transit/contexts/_video.html.erb +13 -0
  110. data/app/views/transit/contexts/destroy.js.erb +1 -0
  111. data/app/views/transit/contexts/index.html.erb +5 -0
  112. data/app/views/transit/contexts/new.js.erb +7 -0
  113. data/app/views/transit/contexts/show.html.erb +8 -0
  114. data/app/views/transit/index.html.erb +26 -0
  115. data/app/views/transit/index.js.erb +1 -0
  116. data/app/views/transit/interface/post_panel.html.erb +96 -0
  117. data/app/views/transit/pages/_table.html.erb +7 -0
  118. data/app/views/transit/pages/edit.html.erb +17 -0
  119. data/app/views/transit/pages/index.html.erb +17 -0
  120. data/app/views/transit/pages/update.js.erb +1 -0
  121. data/app/views/transit/posts/_form.html.erb +49 -0
  122. data/app/views/transit/posts/edit.html.erb +14 -0
  123. data/app/views/transit/posts/new.html.erb +21 -0
  124. data/app/views/transit/table.html.erb +13 -0
  125. data/app/views/transit/table.js.erb +8 -0
  126. data/app/views/transit/topics/manage.html.erb +28 -0
  127. data/config/locales/en.yml +22 -0
  128. data/config/routes.rb +3 -3
  129. data/lib/transit.rb +51 -17
  130. data/lib/transit/admin.rb +85 -0
  131. data/lib/transit/builders/form_builder.rb +319 -0
  132. data/lib/transit/builders/jst_builder.rb +38 -0
  133. data/lib/transit/builders/package_builder.rb +45 -0
  134. data/lib/transit/config.rb +20 -0
  135. data/lib/transit/controller/generator.rb +42 -0
  136. data/lib/transit/controller/responder.rb +34 -0
  137. data/lib/transit/core_ext.rb +18 -0
  138. data/lib/transit/errors/resource_not_found.rb +6 -0
  139. data/lib/transit/model/assets.rb +14 -0
  140. data/lib/transit/model/attachments.rb +55 -0
  141. data/lib/transit/model/auto_increment.rb +22 -0
  142. data/lib/transit/model/base.rb +56 -0
  143. data/lib/transit/model/comments.rb +19 -0
  144. data/lib/transit/model/hooks.rb +38 -0
  145. data/lib/transit/model/owners.rb +14 -0
  146. data/lib/transit/model/paginator.rb +92 -0
  147. data/lib/transit/model/topics.rb +14 -0
  148. data/lib/transit/package/page.rb +20 -12
  149. data/lib/transit/package/post.rb +87 -33
  150. data/lib/transit/package/post/validations.rb +14 -0
  151. data/lib/transit/rails/engine.rb +29 -13
  152. data/lib/transit/rails/railtie.rb +31 -0
  153. data/lib/transit/rails/routing.rb +11 -6
  154. data/lib/transit/services.rb +13 -0
  155. data/lib/transit/services/base.rb +14 -0
  156. data/lib/transit/services/facebook.rb +13 -0
  157. data/lib/transit/services/ted.rb +10 -0
  158. data/lib/transit/services/twitter.rb +13 -0
  159. data/lib/transit/services/vimeo.rb +10 -0
  160. data/lib/transit/services/you_tube.rb +12 -0
  161. data/lib/transit/version.rb +1 -1
  162. metadata +178 -31
  163. data/app/assets/stylesheets/includes/_compat.scss +0 -24
  164. data/app/assets/stylesheets/includes/_defaults.scss +0 -99
  165. data/app/assets/stylesheets/includes/_global.scss +0 -16
  166. data/app/assets/stylesheets/includes/_imports.scss +0 -27
  167. data/app/assets/stylesheets/includes/_mixins.scss +0 -38
  168. data/app/assets/stylesheets/includes/_setup.scss +0 -85
  169. data/app/assets/stylesheets/layout.css.scss +0 -29
  170. data/app/assets/stylesheets/transit.css +0 -3
  171. data/app/controllers/application_controller.rb +0 -5
  172. data/app/controllers/transit/index_controller.rb +0 -7
  173. data/app/controllers/transit/packages_controller.rb +0 -64
  174. data/app/controllers/transit/transit_controller.rb +0 -4
  175. data/app/helpers/routing_helpers.rb +0 -7
  176. data/app/models/audio.rb +0 -4
  177. data/app/models/package_asset.rb +0 -11
  178. data/app/models/video.rb +0 -8
  179. data/app/views/contexts/_audio.html.erb +0 -1
  180. data/app/views/contexts/_video.html.erb +0 -1
  181. data/app/views/layouts/transit.html.erb +0 -31
  182. data/app/views/transit/index/index.html.erb +0 -0
  183. data/lib/transit/helpers/controller_helpers.rb +0 -40
  184. data/lib/transit/helpers/model_helpers.rb +0 -26
  185. data/lib/transit/package.rb +0 -25
  186. data/lib/transit/package/base.rb +0 -49
@@ -0,0 +1,3 @@
1
+ class PagesController < ApplicationController
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class PostsController < ApplicationController
2
+
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'mime/types'
2
+ class Transit::AssetsController < TransitController
3
+
4
+ before_filter :update_params, :only => [:create, :update]
5
+ respond_to :js, :json, :html
6
+ skip_before_filter :verify_authenticity_token
7
+
8
+ def create
9
+ @asset = Transit::Asset.new(params[:asset])
10
+ @parent = params[:resource_type].constantize.find(params[:resource_id])
11
+ @asset.assetable = @parent
12
+ @asset.save
13
+ flash[:success] = "Upload successful!"
14
+ respond_with(@asset)
15
+ end
16
+
17
+ def show
18
+ @asset = Transit::Asset.find(params[:id])
19
+ end
20
+
21
+ def update
22
+
23
+ end
24
+
25
+ def destroy
26
+ @asset = Transit::Asset.find(params[:id])
27
+ @asset.destroy
28
+ respond_with(@asset)
29
+ end
30
+
31
+ private
32
+
33
+ def update_params
34
+ return true unless params[:asset][:file]
35
+ params[:asset][:file].content_type = ::MIME::Types.type_for(params[:asset][:file].original_filename).first.to_s
36
+ end
37
+
38
+ end
@@ -1,20 +1,23 @@
1
- class Transit::ContextsController < Transit::TransitController
2
- include Transit::Helpers::ControllerHelpers
3
- unloadable
1
+ class Transit::ContextsController < TransitController
2
+
4
3
  respond_to :js
4
+ belongs_to :post, :page, polymorphic: true
5
+ actions :new, :destroy
5
6
 
6
7
  def new
7
- @package = scope_class.find(params["#{scope_name}"])
8
- @context = params[:type].classify.constantize.new
8
+ ptype = symbols_for_association_chain.first.to_s
9
+ parent_obj = ptype.classify.constantize.find(params["#{ptype}_id"])
10
+ set_resource_ivar(parent_obj)
11
+ @context = parent_obj.contexts.build({}, params[:type].classify.constantize)
9
12
  respond_with(@context)
10
13
  end
11
14
 
15
+
12
16
  def destroy
13
- @package = scope_class.find(params["#{scope_name}"])
14
- @context = scope_class.find(params[:id])
15
- @field.destroy
17
+ parent.contexts.find(params[:id])
18
+ @context.destroy
16
19
  flash[:success] = "The selected field has been removed."
17
- respond_with(@field)
20
+ respond_with(@context)
18
21
  end
19
22
 
20
23
  end
@@ -0,0 +1,26 @@
1
+ class Transit::PagesController < TransitController
2
+ respond_to :html, :js, :json
3
+
4
+ def index
5
+ @pages = scope_class.descending(:post_date).page((params[:page] || 1))
6
+ respond_with(@pages) do |format|
7
+ format.js{ render :partial => 'table' }
8
+ format.any
9
+ end
10
+ end
11
+
12
+ def edit
13
+ @page = scope_class.find(params[:id])
14
+ respond_with(@page)
15
+ end
16
+
17
+ def update
18
+ @page = scope_class.find(params[:id])
19
+ unless @page.update_attributes(params[:page])
20
+ flash.now[:error] = "Looks like you were missing a few fields!"
21
+ render :action => :edit and return
22
+ end
23
+ respond_with(@post, :location => edit_polymorphic_path(@page), :success => "The page '#{@page.name}' has been updated.")
24
+ end
25
+
26
+ end
@@ -0,0 +1,31 @@
1
+ class Transit::PostsController < TransitController
2
+ defaults collection_name: 'posts', instance_name: 'post'
3
+
4
+ respond_to :html, :js, :json
5
+
6
+ def collection
7
+ @posts ||= end_of_association_chain.page((params[:page] || 1), per: 20)
8
+ end
9
+
10
+ def create
11
+ @post = resource_class.new(params[:post])
12
+ set_resource_ivar(@post)
13
+ unless @post.save
14
+ render action: 'new', error: 'Oops, looks like you forgot something!' and return
15
+ end
16
+ redirect_to transit.edit_polymorphic_path(resource), success: 'Your post was created!'
17
+ end
18
+
19
+ def update
20
+ @post = Post.find(params[:id])
21
+ unless @post.update_attributes(params[:post])
22
+ render action: :edit, error: 'Looks like you forgot a couple fields' and return
23
+ end
24
+ redirect_to transit.edit_polymorphic_path(@post), success: 'Your post was updated.'
25
+ end
26
+
27
+ def destroy
28
+ destroy!(success: 'The selected post has been deleted.')
29
+ end
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ class Transit::TopicsController < TransitController
2
+ belongs_to :post, optional: true
3
+ respond_to :js
4
+
5
+ end
@@ -0,0 +1,16 @@
1
+ class TransitController < InheritedResources::Base
2
+
3
+ helper_method :edit_mode_enabled?
4
+ respond_to :html, :js
5
+ before_filter :authenticate_admin!
6
+
7
+ def edit_mode_enabled?
8
+ true
9
+ end
10
+
11
+ def render(*args)
12
+ args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
13
+ super
14
+ end
15
+
16
+ end
@@ -0,0 +1,43 @@
1
+ module Transit::AdminHelper
2
+ unloadable
3
+
4
+ def context_field_item(field, form)
5
+ idfield = field.new_record? ? "" : form.hidden_field(:id)
6
+ content_tag(:li, { id:"context_#{field.id.to_s}", class: "field field_#{field.class.to_s.underscore}" }) do
7
+ form.hidden_field(:_type, value: field.class.to_s) <<
8
+ form.hidden_field(:position, rel: 'field_position') <<
9
+ idfield <<
10
+ render(partial: "transit/contexts/#{field.class.to_s.underscore}", locals: { form: form, context: field })
11
+ end.html_safe
12
+ end
13
+
14
+ def transit_toolbar(model, &block)
15
+ content_tag(:div, capture(&block), { class: 'ui-widget-header ui-state-default', id: 'transit_toolbar' })
16
+ end
17
+
18
+ def toolbar_button(text, url, attrs)
19
+ klasses = attrs[:class].to_s.split(" ").push('transit_toolbar_button')
20
+ if attrs[:icon].present?
21
+ (attrs[:data] ||= {}).merge!("ui-icon" => "ui-icon-#{attrs.delete(:icon)}")
22
+ end
23
+ link_to text.html_safe, url, attrs.merge(class: klasses.join(" "))
24
+ end
25
+
26
+ def file_icon_class(asset)
27
+ ext = File.extname(asset.file_file_name.to_s.downcase).gsub('.', '')
28
+ extnames = {
29
+ 'powerpoint' => ['ppt','pptx','key'],
30
+ 'audio' => ['mp3', 'wav'],
31
+ 'video' => ['mp4', 'wmv', 'mov', 'mpeg'],
32
+ 'flash' => ['swf', 'flv', 'fla'],
33
+ 'pdf' => ['pdf'],
34
+ 'word' => ['doc', 'docx', 'pages'],
35
+ 'excel' => ['xls', 'csv', 'xlsx', 'numbers'],
36
+ 'image' => ['tiff', 'tif', 'bmp', 'jpeg', 'jpg', 'png', 'gif'],
37
+ 'vector' => ['ai', 'eps']
38
+ }
39
+ choice = 'file'
40
+ extnames.each_pair{ |key, value| choice = key if value.include?(ext) }
41
+ "file_icon_#{choice}"
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ module Transit
2
+ module FormHelper
3
+ unloadable
4
+
5
+ def form_for(record_name_or_array, *args, &proc)
6
+
7
+ options = args.extract_options!
8
+ options.reverse_merge!(:builder => Transit::Builders::FormBuilder)
9
+ options[:html] ||= {}
10
+ options[:html].merge!('data-js-validatable' => true) if options.delete(:validate)
11
+
12
+ super(record_name_or_array, *(args << options), &proc)
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ module Transit
2
+ module PackageHelper
3
+ unloadable
4
+
5
+ def deliver_content(resource, force_edit = false, &block)
6
+ return capture(resource, &block).html_safe unless force_edit || edit_mode_enabled?
7
+ tpl = resource.delivery_template
8
+ with_output_buffer do
9
+ concat(form_for([transit, resource], as: tpl, html: { remote: true, id: "transit_edit_#{tpl.to_s}" }) do |dform|
10
+ concat(capture(Transit::Builders::PackageBuilder.new(resource, dform, nil), &block))
11
+ end)
12
+ end
13
+ end
14
+
15
+ def deliver(obj)
16
+ if obj.respond_to?(:deliver)
17
+ return obj.deliver
18
+ end
19
+ obj.contexts.ascending(:position).map do |field|
20
+ unless field.media_context?
21
+ render(:partial => "contexts/#{field.class.to_s.underscore}", :format => :html, :locals => { :context => field }).html_safe
22
+ else
23
+ deliver_media_context(field, field.to_backbone)
24
+ end
25
+ end.join("\n").html_safe
26
+ end
27
+
28
+ def deliver_rss(post)
29
+ send(:"#{post.class.name.to_s.underscore}_path", post.slug)
30
+ end
31
+
32
+ private
33
+
34
+ def deliver_media_context(context, attrs = {})
35
+ type = context.class.name.underscore
36
+ attrs = { transit_context: type, context_attributes: attrs }
37
+ content_tag(:div, "", { id: "#{type}_context_#{context.id}", data: attrs, class: "#{type}_player" })
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,58 @@
1
+ module Transit
2
+ module PaginationHelper
3
+ unloadable
4
+
5
+ def paginate(collection, html_attrs = {})
6
+ return "" if collection.total_count <= 0
7
+
8
+ total_pages = collection.total_pages
9
+ current_page = collection.current_page
10
+ html_classes = (html_attrs.delete(:class) || "").split(" ")
11
+ window_min = [(current_page - 5), 1].max
12
+ window_max = [(current_page + 5), total_pages].min
13
+ page_links = []
14
+
15
+ html_attrs.merge!('class' => html_classes.push('pagination_link').uniq.join(" "))
16
+
17
+ (window_min..window_max).to_a.each do |page|
18
+ unless page == current_page
19
+ page_links << pagination_link(page, html_attrs)
20
+ else
21
+ page_links << content_tag(:span, page, class: 'current').to_s
22
+ end
23
+ end
24
+
25
+ unless current_page == 1
26
+ page_links.unshift pagination_link_previous(current_page - 1, html_attrs).html_safe
27
+ end
28
+ unless current_page == total_pages
29
+ page_links << pagination_link_next(current_page + 1, total_pages, html_attrs).html_safe
30
+ end
31
+
32
+ content_tag(:p, class: 'pagination') do
33
+ content_tag(:span, "Viewing page #{current_page} of #{total_pages}", class: 'pagination_detail') <<
34
+ content_tag(:span, page_links.join(" ").html_safe, class: 'pagination_links')
35
+ end.html_safe
36
+
37
+ end
38
+
39
+ private
40
+
41
+ def pagination_link_previous(prev_page, attrs)
42
+ pagination_link(1, attrs, "&lArr;") <<
43
+ pagination_link(prev_page, attrs, "&laquo;")
44
+ end
45
+
46
+ def pagination_link_next(next_page, last_page, attrs)
47
+ pagination_link(next_page, attrs, "&raquo;") <<
48
+ pagination_link(last_page, attrs, "&rArr;")
49
+ end
50
+
51
+ def pagination_link(page, attrs, text = nil)
52
+ text ||= page
53
+ qstring = CGI.parse(request.query_string).merge('page' => page )
54
+ link_to(text.to_s.html_safe, "?#{qstring.to_query}", attrs).html_safe.to_s
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,42 @@
1
+ module TransitHelper
2
+ unloadable
3
+
4
+ include Transit::PackageHelper
5
+ include Transit::PaginationHelper
6
+ include Transit::FormHelper
7
+
8
+ def transit_assets
9
+ return '' unless controller.class.name.match(/Transit/)
10
+ stylesheet_link_tag('transit') <<
11
+ javascript_include_tag('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js') <<
12
+ javascript_include_tag('transit/admin')
13
+ end
14
+
15
+ def video_player(source, html_attrs = {})
16
+ attrs = {
17
+ id: "video_player_#{Time.now.to_i}",
18
+ class: 'video_player'
19
+ }
20
+ wrapper = html_attrs.delete(:wrapper) || :div
21
+ data_attrs = { source: source, ext: File.extname(source).sub('.','') };
22
+
23
+ if img = html_attrs.delete(:image)
24
+ data_attrs.merge!(image: img)
25
+ end
26
+
27
+ html_attrs.reverse_merge!( attrs.merge!(data: { context_attributes: Base64.encode64s(data_attrs.to_json) } ))
28
+ content_tag(wrapper, "", html_attrs)
29
+ end
30
+
31
+ def audio_player(source, html_attrs = {})
32
+ attrs = {
33
+ id: "audio_player_#{Time.now.to_i}",
34
+ class: 'audio_player'
35
+ }
36
+ wrapper = html_attrs.delete(:wrapper) || :div
37
+ data_attrs = { source: source }
38
+ html_attrs.reverse_merge!( attrs.merge!(data: { context_attributes: Base64.encode64s(data_attrs.to_json) }) )
39
+ content_tag(wrapper, "", html_attrs)
40
+ end
41
+
42
+ end
@@ -0,0 +1,37 @@
1
+ class Comment
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :body, :type => String
6
+
7
+ belongs_to :commentable, :polymorphic => true
8
+ belongs_to :user
9
+
10
+ validates :body, :presence => { :allow_blank => false, :message => 'required' }
11
+ after_create :update_comment_count
12
+ after_destroy :cleanup_comment_count
13
+ delegate :username, :to => :user
14
+
15
+ # Stringify the created_at date.
16
+ def timestamp
17
+ self.created_at.in_time_zone("Eastern Time (US & Canada)").strftime("%m/%d/%Y at %I:%M %P")
18
+ end
19
+
20
+ private
21
+
22
+ ##
23
+ # When created increment a comment_count field on the parent
24
+ # to avoid parent.comments.count calls and the db overhead.
25
+ #
26
+ def update_comment_count
27
+ self.commentable.inc(:comment_count, 1)
28
+ end
29
+
30
+ ##
31
+ # Inverse of update_comment_count to ensure comment counts are updated on delete/destroy
32
+ #
33
+ def cleanup_comment_count
34
+ self.commentable.update_attribute(:comment_count, (self.commentable.comment_count - 1))
35
+ end
36
+
37
+ end
@@ -0,0 +1,12 @@
1
+ class Audio < Transit::Context
2
+ alias_attribute :source, :body
3
+
4
+ def media_context?
5
+ true
6
+ end
7
+
8
+ def to_js( attrs = {} )
9
+ super({ source: source, ext: file_ext }.reverse_merge!(attrs))
10
+ end
11
+
12
+ end
File without changes
@@ -0,0 +1,24 @@
1
+ class Video < Transit::Context
2
+ alias_attribute :source, :body
3
+
4
+ def self.sources
5
+ ['URL', 'Uploaded Video', 'YouTube', 'Vimeo', 'Ted'].collect{ |src| [src, src.underscore ] }
6
+ end
7
+
8
+ def video_type=(t)
9
+ self.meta['video_type'] = t
10
+ end
11
+
12
+ def video_type
13
+ self.meta['video_type']
14
+ end
15
+
16
+ def media_context?
17
+ true
18
+ end
19
+
20
+ def to_js( attrs = {} )
21
+ super({ source: source, type: video_type, ext: file_ext }.reverse_merge!(attrs))
22
+ end
23
+
24
+ end