Skip to content

Commit

Permalink
basic tagging of tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
JuddL333 committed Jun 27, 2013
1 parent 61c5f3c commit d88748b
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.3-p392
1.9.3-p429
31 changes: 15 additions & 16 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ gem 'twitter-bootstrap-rails', '2.0.7'
gem 'therubyracer', :platform => :ruby
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem "sidekiq", '~> 2.12.3'
gem 'sidekiq', '~> 2.12.3'
gem 'rest-client'
gem 'sinatra', require: false
gem 'slim'
gem 'capistrano-unicorn', :require => false
gem 'dotenv-rails', '0.8.0'
gem 'airbrake'
gem 'pg'
gem 'unicorn'
gem 'simple_form'

group :assets do
gem 'sass-rails', '~> 3.2.3'
Expand All @@ -39,16 +41,16 @@ def linux_only(require_as)
end

group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'capistrano'
gem "rspec-rails"
gem "guard-rspec"
gem "guard-spork"
gem "sqlite3"
gem 'sqlite3'
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'

# mac
gem "rb-fsevent", require: darwin_only('rb-fsevent')
gem "growl", require: darwin_only('growl')
gem 'rb-fsevent', require: darwin_only('rb-fsevent')
gem 'growl', require: darwin_only('growl')

# linux
gem 'rb-inotify', require: linux_only('rb-inotify')
Expand All @@ -58,13 +60,10 @@ group :development do
end

group :test do
gem "rspec-rails"
gem "factory_girl_rails"
gem "database_cleaner"
gem "capybara"
gem 'shoulda-matchers'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'capybara'
end

group :production do
gem "mysql2"
gem "unicorn"
end
19 changes: 15 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ GEM
builder
json
arel (3.0.2)
better_errors (0.9.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-will_paginate (0.0.9)
will_paginate
builder (3.0.4)
Expand Down Expand Up @@ -68,6 +73,7 @@ GEM
connection_pool (1.1.0)
daemons (1.1.9)
database_cleaner (0.9.1)
debug_inspector (0.0.2)
diff-lcs (1.1.3)
dotenv (0.8.0)
dotenv-rails (0.8.0)
Expand Down Expand Up @@ -131,7 +137,6 @@ GEM
mime-types (1.21)
multi_json (1.7.6)
multipart-post (1.1.5)
mysql2 (0.3.11)
net-scp (1.1.1)
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
Expand Down Expand Up @@ -221,12 +226,17 @@ GEM
sextant (0.2.2)
activesupport (>= 3.2)
rails (>= 3.2)
shoulda-matchers (1.1.0)
activesupport (>= 3.0.0)
sidekiq (2.12.3)
celluloid (>= 0.14.1)
connection_pool (>= 1.0.0)
json
redis (>= 3.0)
redis-namespace
simple_form (2.1.0)
actionpack (~> 3.0)
activemodel (~> 3.0)
simple_oauth (0.1.9)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
Expand All @@ -242,7 +252,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
temple (0.5.5)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
Expand Down Expand Up @@ -289,6 +298,8 @@ PLATFORMS

DEPENDENCIES
airbrake
better_errors
binding_of_caller
bootstrap-will_paginate
capistrano
capistrano-unicorn
Expand All @@ -303,7 +314,6 @@ DEPENDENCIES
guard-spork
jquery-rails
libnotify
mysql2
omniauth-twitter
pg
rails (= 3.2.12)
Expand All @@ -314,10 +324,11 @@ DEPENDENCIES
rspec-rails
sass-rails (~> 3.2.3)
sextant
shoulda-matchers
sidekiq (~> 2.12.3)
simple_form
sinatra
slim
sqlite3
therubyracer
tweetstream (~> 1.0)
twitter
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ def show
@story = Story.find(params[:id])
@comments = @story.comments.order('votes_count desc, created_at')
end

def edit
@story = Story.find(params[:id])
end

def update
@story = Story.find(params[:id])

if @story.update_attributes(params[:story])
redirect_to root_url, notice: 'Tags have been updated.'
else
render :edit
end
end
end
5 changes: 4 additions & 1 deletion app/models/story.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
class Story < Post
has_many :comments
has_many :taggings
has_many :tags, through: :taggings


validates :twitter_id, :uniqueness => true

# after_create :queue_reply_checker
after_save :self_love #:promote_tweet

attr_accessible :twitter_id, :twitter_profile_image_url
attr_accessible :twitter_id, :twitter_profile_image_url, :tag_ids

def self.create_from_tweet(tweet)
story = self.create(
Expand Down
7 changes: 7 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Tag < ActiveRecord::Base
attr_accessible :name

has_many :taggings
has_many :stories, through: :taggings

end
6 changes: 6 additions & 0 deletions app/models/tagging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Tagging < ActiveRecord::Base
attr_accessible :story_id, :tag_id

belongs_to :story
belongs_to :tag
end
26 changes: 0 additions & 26 deletions app/views/stories/_form.html.erb

This file was deleted.

8 changes: 8 additions & 0 deletions app/views/stories/_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=simple_form_for(@story, :html => { :class => 'form-horizontal' }) do |f|

.form-inputs
= f.association :tags, collection: Tag.order('name DESC'), :as => :check_boxes


.form-actions
= f.submit "Update Tags", class: 'btn-cta'
4 changes: 4 additions & 0 deletions app/views/stories/_story.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<span class="comments">
<%= link_to("#{story.comments.size.to_i} Comments", story_path(story)) %>
</span>
<span class="comments">
<%= link_to("Add Tags", edit_story_path(story)) %>
</span>

</div>
</div>

Expand Down
6 changes: 4 additions & 2 deletions app/views/stories/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%- model_class = @story.class -%>
<h1><%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human,
:default => "Edit #{model_class.model_name.human}") %></h1>
<h1><%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human, :default => "Edit #{model_class.model_name.human}") %></h1>

<%= render :partial => 'story', :locals => {:story => @story} %>

<%= render :partial => 'form' %>
142 changes: 142 additions & 0 deletions config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
# You can make any of these extensions optional by
# renaming `b.use` to `b.optional`.

# Determines whether to use HTML5 (:email, :url, ...)
# and required attributes
b.use :html5

# Calculates placeholders automatically from I18n
# You can also pass a string as f.input :placeholder => "Placeholder"
b.use :placeholder

## Optional extensions
# They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
# to the input. If so, they will retrieve the values from the model
# if any exists. If you want to enable the lookup for any of those
# extensions by default, you can change `b.optional` to `b.use`.

# Calculates maxlength from length validations for string inputs
b.optional :maxlength

# Calculates pattern from format validations for string inputs
b.optional :pattern

# Calculates min and max from length validations for numeric inputs
b.optional :min_max

# Calculates readonly automatically from readonly attributes
b.optional :readonly

## Inputs
b.use :label_input
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
b.use :error, :wrap_with => { :tag => :span, :class => :error }
end

# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default

# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
# :inline => input + label
# :nested => label > input
config.boolean_style = :nested

# Default class for buttons
config.button_class = 'btn'

# Method used to tidy up errors. Specify any Rails Array method.
# :first lists the first message for each field.
# Use :to_sentence to list all errors for each field.
# config.error_method = :first

# Default tag used for error notification helper.
config.error_notification_tag = :div

# CSS class to add for error notification helper.
config.error_notification_class = 'alert alert-error'

# ID to add for error notification helper.
# config.error_notification_id = nil

# Series of attempts to detect a default label method for collection.
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]

# Series of attempts to detect a default value method for collection.
# config.collection_value_methods = [ :id, :to_s ]

# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
# config.collection_wrapper_tag = nil

# You can define the class to use on all collection wrappers. Defaulting to none.
# config.collection_wrapper_class = nil

# You can wrap each item in a collection of radio/check boxes with a tag,
# defaulting to :span. Please note that when using :boolean_style = :nested,
# SimpleForm will force this option to be a label.
# config.item_wrapper_tag = :span

# You can define a class to use in all item wrappers. Defaulting to none.
# config.item_wrapper_class = nil

# How the label text should be generated altogether with the required text.
# config.label_text = lambda { |label, required| "#{required} #{label}" }

# You can define the class to use on all labels. Default is nil.
config.label_class = 'control-label'

# You can define the class to use on all forms. Default is simple_form.
# config.form_class = :simple_form

# You can define which elements should obtain additional classes
# config.generate_additional_classes_for = [:wrapper, :label, :input]

# Whether attributes are required by default (or not). Default is true.
# config.required_by_default = true

# Tell browsers whether to use default HTML5 validations (novalidate option).
# Default is enabled.
config.browser_validations = false

# Collection of methods to detect if a file type was given.
# config.file_methods = [ :mounted_as, :file?, :public_filename ]

# Custom mappings for input types. This should be a hash containing a regexp
# to match as key, and the input type that will be used when the field name
# matches the regexp as value.
# config.input_mappings = { /count/ => :integer }

# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
# config.wrapper_mappings = { :string => :prepend }

# Default priority for time_zone inputs.
# config.time_zone_priority = nil

# Default priority for country inputs.
# config.country_priority = nil

# Default size for text inputs.
# config.default_input_size = 50

# When false, do not use translations for labels.
# config.translate_labels = true

# Automatically discover new inputs in Rails' autoload path.
# config.inputs_discovery = true

# Cache SimpleForm inputs discovery
# config.cache_discovery = !Rails.env.development?
end
Loading

0 comments on commit d88748b

Please sign in to comment.