diff --git a/Gemfile b/Gemfile index 0ab1f27..735c8a4 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ end gem 'haml-rails' gem 'simple_form' gem 'jquery-rails' -gem "ember-rails" +gem 'rails_tokeninput' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index ad6f86b..595a2c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,9 +37,6 @@ GEM coffee-script-source execjs coffee-script-source (1.3.1) - ember-rails (0.4.0) - execjs (>= 1.2) - railties (~> 3.1) erubis (2.7.0) execjs (1.3.2) multi_json (~> 1.0) @@ -55,14 +52,14 @@ GEM jquery-rails (2.0.2) railties (>= 3.2.0, < 5.0) thor (~> 0.14) - json (1.7.2) + json (1.7.3) kgio (2.7.4) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.18) - multi_json (1.3.4) + multi_json (1.3.5) pg (0.13.2) polyglot (0.3.3) rack (1.4.1) @@ -80,6 +77,8 @@ GEM activesupport (= 3.2.3) bundler (~> 1.0) railties (= 3.2.3) + rails_tokeninput (1.6.0) + railties (>= 3.1.0) railties (3.2.3) actionpack (= 3.2.3) activesupport (= 3.2.3) @@ -122,11 +121,11 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 3.2.1) - ember-rails haml-rails jquery-rails pg rails (= 3.2.3) + rails_tokeninput sass-rails (~> 3.2.3) simple_form uglifier (>= 1.0.3) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index ac49a52..66525a2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,7 +12,5 @@ // //= require jquery //= require jquery_ujs -//= require ember -//= require ember -//= require ember/gifhub +//= require jquery.tokeninput //= require_tree . diff --git a/app/assets/javascripts/ember/controllers/.gitkeep b/app/assets/javascripts/ember/controllers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/ember/gifhub.js b/app/assets/javascripts/ember/gifhub.js deleted file mode 100644 index d231b0a..0000000 --- a/app/assets/javascripts/ember/gifhub.js +++ /dev/null @@ -1,8 +0,0 @@ -#= require_self -#= require_tree ./models -#= require_tree ./controllers -#= require_tree ./views -#= require_tree ./helpers -#= require_tree ./templates - -Gifhub = Ember.Application.create(); diff --git a/app/assets/javascripts/ember/helpers/.gitkeep b/app/assets/javascripts/ember/helpers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/ember/models/.gitkeep b/app/assets/javascripts/ember/models/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/ember/templates/.gitkeep b/app/assets/javascripts/ember/templates/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/ember/views/.gitkeep b/app/assets/javascripts/ember/views/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/gifs.js.coffee b/app/assets/javascripts/gifs.js.coffee index 2a5d841..31a0b37 100644 --- a/app/assets/javascripts/gifs.js.coffee +++ b/app/assets/javascripts/gifs.js.coffee @@ -1,3 +1,10 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ \ No newline at end of file +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ + +jQuery -> + $('#gif_tag_tokens').tokenInput '/tags.json' + theme: "facebook" + # prepopulate with tokens loaded from data-load attribute + # would be useful on a show page + # prePopulate: $('#gif_tag_tokens').data('load') \ No newline at end of file diff --git a/app/assets/javascripts/tags.js.coffee b/app/assets/javascripts/tags.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/tags.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css deleted file mode 100644 index 3b5cc66..0000000 --- a/app/assets/stylesheets/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * - *= require_self - *= require_tree . -*/ diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass new file mode 100644 index 0000000..ed79df7 --- /dev/null +++ b/app/assets/stylesheets/application.css.sass @@ -0,0 +1,10 @@ +//= require_self +//= require_tree . +//= require token-input-facebook + +body + font: + family: Helvetica, Arial, sans-serif + +h1 + font-size: 2em \ No newline at end of file diff --git a/app/assets/stylesheets/gifs.css.sass b/app/assets/stylesheets/gifs.css.sass new file mode 100644 index 0000000..525ffd9 --- /dev/null +++ b/app/assets/stylesheets/gifs.css.sass @@ -0,0 +1,30 @@ +// Place all the styles related to the gifs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +ul + padding-left: 0 + + li + list-style: none + +#new_gif + width: 400px + padding-bottom: 1em + .input + width: 30% + + input + font-size: 1em + padding: 3px 5px 4px 5px + margin-bottom: .5em + border: 1px solid black + border-radius: 2px + + input[type="submit"] + margin-top: 1em + float: right + + +#gif-list + clear: both \ No newline at end of file diff --git a/app/assets/stylesheets/gifs.css.scss b/app/assets/stylesheets/gifs.css.scss deleted file mode 100644 index d0ec7f0..0000000 --- a/app/assets/stylesheets/gifs.css.scss +++ /dev/null @@ -1,10 +0,0 @@ -// Place all the styles related to the gifs controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ - -ul { - padding-left: 0; -} -ul li { - list-style: none; -} \ No newline at end of file diff --git a/app/assets/stylesheets/tags.css.scss b/app/assets/stylesheets/tags.css.scss new file mode 100644 index 0000000..eb3f7cc --- /dev/null +++ b/app/assets/stylesheets/tags.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the tags controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 0000000..16256fa --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,22 @@ +class TagsController < ApplicationController + respond_to :json + def index + @tags = Tag.order(:name) + respond_with do |format| + format.json { render json: @tags.tokens(params[:q]) } + end + end + + def new + respond_with @tag = Tag.new + end + + def create + @tag = Tag.new(params[:tag]) + if @tag.save + respond_with @tag + else + render :new + end + end +end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 0000000..23450bc --- /dev/null +++ b/app/helpers/tags_helper.rb @@ -0,0 +1,2 @@ +module TagsHelper +end diff --git a/app/models/gif.rb b/app/models/gif.rb index 4b6caa0..26dcac3 100644 --- a/app/models/gif.rb +++ b/app/models/gif.rb @@ -1,8 +1,13 @@ class Gif < ActiveRecord::Base - attr_accessible :filename, :source_url + attr_accessible :filename, :source_url, :tag_tokens + attr_reader :tag_tokens has_and_belongs_to_many :tags + def tag_tokens=(tokens) + self.tag_ids = Tag.ids_from_tokens(tokens) + end + def to_s self.source_url end diff --git a/app/models/tag.rb b/app/models/tag.rb index 1716297..f3d753e 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -2,4 +2,22 @@ class Tag < ActiveRecord::Base attr_accessible :name has_and_belongs_to_many :gifs + + def to_s + self.name + end + + def self.tokens(query) + tags = where("name ILIKE ?", "%#{query}%") + if tags.empty? + [{id: "<<<#{query}>>>", name: "New: \"#{query}\""}] + else + tags + end + end + + def self.ids_from_tokens(tokens) + tokens.gsub!(/<<<(.+?)>>>/) { create!(name: $1).id } + tokens.split(',') + end end diff --git a/app/views/gifs/index.html.haml b/app/views/gifs/index.html.haml index 6f699d1..0658057 100644 --- a/app/views/gifs/index.html.haml +++ b/app/views/gifs/index.html.haml @@ -1,11 +1,12 @@ +%h2 Add a GIF += simple_form_for Gif.new do |f| + = f.input :source_url, label: "GIF URL" + = f.input :tag_tokens, label: "Keywords" #, input_html: { data: {load: Tag.all} } + = f.submit + - unless @gifs.empty? %ul#gif-list - - @gifs.each do |gif| - %li= image_tag(gif, height: "150") + - @gifs.reverse_each do |gif| + %li= image_tag(gif, alt: gif.source_url, title: gif.tags.to_sentence) - else - %p No GIFs to show. -%p= link_to "Add Gifs", new_gif_path - -= simple_form_for Gif.new do |f| - = f.input :source_url - = f.submit + %p No GIFs to show. \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index 8618b73..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - Gifhub - <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..03ec40a --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,11 @@ +!!! +%html +%head + %head + %title Gifhub + = stylesheet_link_tag "application", :media => "all" + = javascript_include_tag "application" + = csrf_meta_tags +%body + %h1 GifHub + = yield \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 17d3c67..722c7cd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,4 +2,5 @@ root to: "gifs#index" resources :gifs + resources :tags, only: [:index] end diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb new file mode 100644 index 0000000..f0919f8 --- /dev/null +++ b/test/functional/tags_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TagsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/tags_helper_test.rb b/test/unit/helpers/tags_helper_test.rb new file mode 100644 index 0000000..4b1935f --- /dev/null +++ b/test/unit/helpers/tags_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class TagsHelperTest < ActionView::TestCase +end