Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to upload custom Favicon #55 #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/models/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ class Campaign < ActiveRecord::Base
:stats_number_of_contributions, :stats_raised_amount, :stats_tilt_percent,
:stats_unique_contributors, :published_flag, :collect_shipping_flag, :production_flag,
:include_rewards, :reward_reference, :collect_additional_info, :additional_info_label,
:include_comments, :comments_shortname, :include_rewards_claimed
:include_comments, :comments_shortname, :include_rewards_claimed, :favicon, :favicon_delete

attr_accessor :main_image_delete, :video_placeholder_delete, :facebook_image_delete
attr_accessor :main_image_delete, :video_placeholder_delete, :facebook_image_delete, :favicon_delete

validates :name, :expiration_date, presence: true
validates :min_payment_amount, numericality: { greater_than_or_equal_to: 1.0 }
validates :fixed_payment_amount, numericality: { greater_than_or_equal_to: 1.0 }
validate :expiration_date_cannot_be_in_the_past, :payments_can_be_activated

before_validation { facebook_image.clear if favicon_delete == '1' }
before_validation { main_image.clear if main_image_delete == '1' }
before_validation { video_placeholder.clear if video_placeholder_delete == '1' }
before_validation { facebook_image.clear if facebook_image_delete == '1' }

has_attached_file :favicon #, :url => "/:basename.:extension", :path => ":rails_root/public/:basename.:extension"
has_attached_file :main_image,
styles: { main: "512x385!", medium: "640x360!", small: "190x143!", thumb: "100x100#" }

Expand Down
2 changes: 1 addition & 1 deletion app/serializers/campaign_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CampaignSerializer < ActiveModel::Serializer
:stats_number_of_contributions, :stats_raised_amount, :stats_tilt_percent,
:stats_unique_contributors, :published_flag, :collect_shipping_flag, :production_flag,
:include_rewards, :reward_reference, :collect_additional_info, :additional_info_label, :url, :payments_uri,
:include_comments, :comments_shortname
:include_comments, :comments_shortname, :favicon, :favicon_delete

def url
campaign_home_url(object)
Expand Down
16 changes: 15 additions & 1 deletion app/views/admin/campaigns/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,21 @@
<% end %>
</div>
</div>


<div class="field clearfix">
<p class="explanation">This'll be the favorite icon placed in the browser window</p>
<label>Favorite Icon</label>
<div id="image-options">
<% if @campaign.favicon.file? %>
<%= image_tag @campaign.favicon.url %><br/>
<%= f.file_field :favicon %><br/>
<%= f.check_box :favicon_delete %><span>Delete current image</span>
<% else %>
<%= f.file_field :favicon %>
<% end %>
</div>
</div>

<div class="field clearfix">
<p class="explanation">This text is displayed on the primary call to action button. Common choices include 'Pay', 'Contribute', 'Back this Project', 'Reserve for $199', etc.</p>
<label>Primary Call to Action Button</label>
Expand Down
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<%= render 'layouts/mobile_bookmark_metas' %>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag "application" %>

<% if [email protected]? && @campaign.favicon.file? %>
<link rel="shortcut icon" type="image/x-icon" href="<%= @campaign.favicon.url %>">
<% end %>
<style type="text/css"><%= raw(@settings.custom_css) %></style>

<%= javascript_include_tag "application" %>
Expand Down
8 changes: 8 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Application < Rails::Application
config.assets.initialize_on_precompile = false

#Paperclip default options
if ENV['ENABLE_ASSET_SYNC'] == 'true'
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
Expand All @@ -52,6 +53,13 @@ class Application < Rails::Application
s3_protocol: 'https',
default_url: '/images/missing_:style.jpg'
}
else
config.paperclip_defaults = {
path: ":rails_root/public/assets/:id_partition/:basename.:extension",
url: "/assets/:id_partition/:basename.:extension",
default_url: '/images/missing_:style.jpg'
}
end

#Mailgun options
config.action_mailer.smtp_settings = {
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20140120234217_add_attachment_favicon_to_campaigns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddAttachmentFaviconToCampaigns < ActiveRecord::Migration
def self.up
change_table :campaigns do |t|
t.attachment :favicon
end
end

def self.down
drop_attached_file :campaigns, :favicon
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140116122844) do
ActiveRecord::Schema.define(:version => 20140120234217) do

create_table "campaigns", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -71,6 +71,13 @@
t.boolean "include_comments", :default => false, :null => false
t.string "comments_shortname"
t.boolean "include_rewards_claimed"
t.boolean "accept_closed_project_payment"
t.string "comment_type"
t.string "comment_facebook_url"
t.string "favicon_file_name"
t.string "favicon_content_type"
t.integer "favicon_file_size"
t.datetime "favicon_updated_at"
end

add_index "campaigns", ["slug"], :name => "index_campaigns_on_slug", :unique => true
Expand Down
Binary file added public/assets/000/000/003/mnatiq.ico
Binary file not shown.