Refactor "unless blank?" into "if present?"

This commit is contained in:
Mindaugas Mozūras 2013-09-13 15:40:09 +03:00
parent 4ca6114b76
commit 25e764b21a
15 changed files with 27 additions and 27 deletions

View file

@ -338,7 +338,7 @@ class ProjectsController < ApplicationController
default_context_name = p['default_context_name']
p.delete('default_context_name')
unless default_context_name.blank?
if default_context_name.present?
default_context = current_user.contexts.where(:name => default_context_name).first_or_create
p['default_context_id'] = default_context.id
end

View file

@ -129,7 +129,7 @@ class RecurringTodosController < ApplicationController
end
@saved = @recurring_todo.save
unless (@saved == false) || p.tag_list.blank?
if @saved && p.tag_list.present?
@recurring_todo.tag_with(p.tag_list)
@recurring_todo.tags.reload
end
@ -255,14 +255,14 @@ class RecurringTodosController < ApplicationController
end
def project_specified_by_name?
return false unless @attributes['project_id'].blank?
return false if @attributes['project_id'].present?
return false if project_name.blank?
return false if project_name == 'None'
true
end
def context_specified_by_name?
return false unless @attributes['context_id'].blank?
return false if @attributes['context_id'].present?
return false if context_name.blank?
true
end

View file

@ -102,14 +102,14 @@ module Todos
end
def project_specified_by_name?
return false unless @attributes['project_id'].blank?
return false if @attributes['project_id'].present?
return false if project_name.blank?
return false if project_name == 'None'
true
end
def context_specified_by_name?
return false unless @attributes['context_id'].blank?
return false if @attributes['context_id'].present?
return false if context_name.blank?
true
end

View file

@ -74,7 +74,7 @@ class TodosController < ApplicationController
def create
@source_view = params['_source_view'] || 'todo'
@default_context = current_user.contexts.where(:name => params['default_context_name']).first
@default_project = current_user.projects.where(:name => params['default_project_name']).first unless params['default_project_name'].blank?
@default_project = current_user.projects.where(:name => params['default_project_name']).first if params['default_project_name'].present?
@tag_name = params['_tag_name']
@ -157,7 +157,7 @@ class TodosController < ApplicationController
# first build all todos and check if they would validate on save
params[:todo][:multiple_todos].split("\n").map do |line|
unless line.blank? #ignore blank lines
if line.present? #ignore blank lines
@todo = current_user.todos.build({:description => line, :context_id => p.context_id, :project_id => p.project_id})
validates &&= @todo.valid?
@ -175,8 +175,8 @@ class TodosController < ApplicationController
todo.add_predecessor(@predecessor)
todo.block!
end
todo.tag_with(tag_list) unless (@saved == false) || tag_list.blank?
todo.tag_with(tag_list) if @saved && tag_list.present?
@todos << todo
@not_done_todos << todo if p.new_context_created || p.new_project_created
@ -203,7 +203,7 @@ class TodosController < ApplicationController
else
@multiple_error = @todos.size > 0 ? "" : t('todos.next_action_needed')
@saved = false
@default_tags = current_user.projects.where(:name => @initial_project_name).default_tags unless @initial_project_name.blank?
@default_tags = current_user.projects.where(:name => @initial_project_name).default_tags if @initial_project_name.present?
end
@status_message = @todos.size > 1 ? t('todos.added_new_next_action_plural') : t('todos.added_new_next_action_singular')

View file

@ -30,10 +30,10 @@ module ProjectsHelper
next_project = content_tag(:li, link_to_project_mobile(@next_project, "6", @next_project.shortened_name), :class=>"next") if @next_project
return content_tag(:ul, "#{prev_project}#{next_project}".html_safe, :class=>"next-prev-project")
end
def project_summary(project)
project_description = ''
project_description += Tracks::Utils.render_text( project.description ) unless project.description.blank?
project_description += Tracks::Utils.render_text( project.description ) if project.description.present?
project_description += content_tag(:p,
"#{count_undone_todos_phrase(p)}. #{t('projects.project_state', :state => project.state)}".html_safe
)

View file

@ -408,7 +408,7 @@ module TodosHelper
end
def format_ical_notes(notes)
unless notes.nil? || notes.blank?
if notes.present?
split_notes = notes.split(/\n/)
joined_notes = split_notes.join("\\n")
end
@ -426,7 +426,7 @@ module TodosHelper
def render_animation(animation)
html = ""
animation.each do |step|
unless step.blank?
if step.present?
html += step + "({ go: function() {\r\n"
end
end

View file

@ -299,7 +299,7 @@ class Todo < ActiveRecord::Base
return unless predecessor_list.kind_of? String
@predecessor_array=predecessor_list.split(",").inject([]) do |list, todo_id|
predecessor = self.user.todos.find( todo_id.to_i ) unless todo_id.blank?
predecessor = self.user.todos.find( todo_id.to_i ) if todo_id.present?
list << predecessor unless predecessor.nil?
list
end
@ -341,7 +341,7 @@ class Todo < ActiveRecord::Base
# value will be a string. In that case convert to array
deps = [deps] unless deps.class == Array
deps.each { |dep| self.add_predecessor(self.user.todos.find(dep.to_i)) unless dep.blank? }
deps.each { |dep| self.add_predecessor(self.user.todos.find(dep.to_i)) if dep.present? }
end
alias_method :original_context=, :context=

View file

@ -16,7 +16,7 @@ class TodoFromRichMessage
project = extractor.project
context_id = default_context_id
unless context.blank?
if context.present?
found_context = user.contexts.active.where("name like ?", "%#{context}%").first
found_context = user.contexts.where("name like ?", "%#{context}%").first if !found_context
context_id = found_context.id if found_context
@ -27,7 +27,7 @@ class TodoFromRichMessage
end
project_id = nil
unless project.blank?
if project.present?
if project[0..3].downcase == "new:"
found_project = user.projects.build
found_project.name = project[4..259].strip

View file

@ -17,7 +17,7 @@
<% end -%>
<%= link_to_edit_project(project, t('projects.edit_project_settings')) %>
</div>
<% unless project.description.blank? -%>
<% if project.description.present? -%>
<div class="project_description"><%= Tracks::Utils.render_text(project.description) %></div>
<% end -%>
</div>

View file

@ -1,6 +1,6 @@
<% @projects.each do |p| -%>
<%= p.name.upcase %>
<%= p.description + "\n" unless p.description.blank? -%>
<%= p.description + "\n" if p.description.present? -%>
<%= count_undone_todos_phrase_text(p)%>. Project is <%= p.state %>.
<% end -%>
<% end -%>

View file

@ -1,7 +1,7 @@
<% project = @project %>
<%= project_next_prev_mobile %>
<h2><%=project.name%></h2>
<% unless @project.description.blank? -%>
<% if @project.description.present? -%>
<div class="project_description"><%= sanitize(@project.description) %></div>
<% end -%>
<ul class="c">

View file

@ -39,7 +39,7 @@ cache [todo, current_user.date.strftime("%Y%m%d"), @source_view, current_user.pr
<%= tag_list(todo) %>
<%= deferred_due_date(todo) %>
<%= project_and_context_links( todo, parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %>
<%= collapsed_notes_image(todo) unless todo.notes.blank? %>
<%= collapsed_notes_image(todo) if todo.notes.present? %>
<%= collapsed_successors_image(todo) if todo.has_pending_successors %>
</div>
</div>

View file

@ -2,7 +2,7 @@
<li id="<%= dom_id(todo) %>" >
<%= remote_mobile_checkbox(todo) %>
<%= date_span -%> <%= link_to todo.description, todo_path(todo, :format => 'm') -%>
<% unless todo.notes.blank? %>
<% if todo.notes.present? %>
<%= link_to(image_tag("mobile_notes.png", :border => "0"), show_notes_todo_path(todo, :format => 'm')) -%>
<% end %>
<% if todo.starred? %>

View file

@ -4,7 +4,7 @@
function html_for_error_messages() {
<%
# add error about missing todo description that is not available in @todos
@multiple_error = content_tag(:div, content_tag(:p, @multiple_error), {:class => 'errorExplanation', :id => 'errorExplanation'}) unless @multiple_error.blank?
@multiple_error = content_tag(:div, content_tag(:p, @multiple_error), {:class => 'errorExplanation', :id => 'errorExplanation'}) if @multiple_error.present?
error_messages = @multiple_error || ""
# add errors of individual @todos
@todos.each do |todo|

View file

@ -49,7 +49,7 @@ module IsTaggable
def _add_tags incoming
tag_cast_to_string(incoming).each do |tag_name|
# added following check to prevent empty tags from being saved (which will fail)
unless tag_name.blank?
if tag_name.present?
begin
tag = Tag.where(:name => tag_name).first_or_create
raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?