Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Commit

Permalink
Removed Ember, added keyword input with autocomplete.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlacan committed May 16, 2012
1 parent bff2a44 commit 1f7ab37
Show file tree
Hide file tree
Showing 26 changed files with 141 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -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'
Expand Down
11 changes: 5 additions & 6 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions app/assets/javascripts/application.js
Expand Up @@ -12,7 +12,5 @@
//
//= require jquery
//= require jquery_ujs
//= require ember
//= require ember
//= require ember/gifhub
//= require jquery.tokeninput
//= require_tree .
Empty file.
8 changes: 0 additions & 8 deletions app/assets/javascripts/ember/gifhub.js

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
9 changes: 8 additions & 1 deletion 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/
# 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')
3 changes: 3 additions & 0 deletions 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/
13 changes: 0 additions & 13 deletions app/assets/stylesheets/application.css

This file was deleted.

10 changes: 10 additions & 0 deletions 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
30 changes: 30 additions & 0 deletions 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
10 changes: 0 additions & 10 deletions app/assets/stylesheets/gifs.css.scss

This file was deleted.

3 changes: 3 additions & 0 deletions 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/
22 changes: 22 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions app/helpers/tags_helper.rb
@@ -0,0 +1,2 @@
module TagsHelper
end
7 changes: 6 additions & 1 deletion 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
Expand Down
18 changes: 18 additions & 0 deletions app/models/tag.rb
Expand Up @@ -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
17 changes: 9 additions & 8 deletions 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.
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

11 changes: 11 additions & 0 deletions 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
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -2,4 +2,5 @@
root to: "gifs#index"

resources :gifs
resources :tags, only: [:index]
end
7 changes: 7 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions test/unit/helpers/tags_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class TagsHelperTest < ActionView::TestCase
end

0 comments on commit 1f7ab37

Please sign in to comment.