diff --git a/Gemfile b/Gemfile index d31f62a..9d73a1f 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,11 @@ group :doc do gem 'sdoc', require: false end +group :development do + gem 'better_errors' + gem "binding_of_caller" +end + # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.1.2' diff --git a/Gemfile.lock b/Gemfile.lock index 9c88ff4..d568df6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,6 +60,11 @@ GEM arel (4.0.1) atomic (1.1.14) bcrypt-ruby (3.1.2) + better_errors (1.1.0) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) bootstrap-sass (3.1.1.0) sass (~> 3.2) bson (2.0.0) @@ -73,6 +78,7 @@ GEM carrierwave-mongoid (0.1.0) carrierwave mongoid + coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -81,6 +87,7 @@ GEM execjs coffee-script-source (1.6.3) connection_pool (1.2.0) + debug_inspector (0.0.2) devise (3.2.1) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -194,6 +201,8 @@ PLATFORMS ruby DEPENDENCIES + better_errors + binding_of_caller bootstrap-sass (= 3.1.1) bson_ext cancan diff --git a/app/assets/fonts/glyphicons-halflings-regular.eot b/app/assets/fonts/glyphicons-halflings-regular.eot new file mode 100644 index 0000000..423bd5d Binary files /dev/null and b/app/assets/fonts/glyphicons-halflings-regular.eot differ diff --git a/app/assets/fonts/glyphicons-halflings-regular.svg b/app/assets/fonts/glyphicons-halflings-regular.svg new file mode 100644 index 0000000..4469488 --- /dev/null +++ b/app/assets/fonts/glyphicons-halflings-regular.svg @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/assets/fonts/glyphicons-halflings-regular.ttf b/app/assets/fonts/glyphicons-halflings-regular.ttf new file mode 100644 index 0000000..a498ef4 Binary files /dev/null and b/app/assets/fonts/glyphicons-halflings-regular.ttf differ diff --git a/app/assets/fonts/glyphicons-halflings-regular.woff b/app/assets/fonts/glyphicons-halflings-regular.woff new file mode 100644 index 0000000..d83c539 Binary files /dev/null and b/app/assets/fonts/glyphicons-halflings-regular.woff differ diff --git a/app/assets/stylesheets/store_front/store_fonts.css.erb b/app/assets/stylesheets/store_front/store_fonts.css.erb index 2392d72..e90260b 100644 --- a/app/assets/stylesheets/store_front/store_fonts.css.erb +++ b/app/assets/stylesheets/store_front/store_fonts.css.erb @@ -1,5 +1,5 @@ @font-face { font-family: 'Glyphicons Halflings'; - src: url('/assets/glyphicons-halflings-regular.eot'); - src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg'); + src: url(<%= asset_path 'glyphicons-halflings-regular.eot' %>); + src: url(<%= asset_path 'glyphicons-halflings-regular.eot?#iefix' %>) format('embedded-opentype'), url(<%= asset_path 'glyphicons-halflings-regular.woff' %>) format('woff'), url(<%= asset_path 'glyphicons-halflings-regular.ttf' %>) format('truetype'), url(<%= asset_path 'glyphicons-halflings-regular.svg#glyphicons_halflingsregular' %>) format('svg'); } \ No newline at end of file diff --git a/app/controllers/extensions_controller.rb b/app/controllers/extensions_controller.rb index 67cd5c2..7fd3949 100644 --- a/app/controllers/extensions_controller.rb +++ b/app/controllers/extensions_controller.rb @@ -78,7 +78,7 @@ class ExtensionsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def extension_params - params.require(:extension).permit(:title, :author, :description, :preview, :preview_cache, :extension, :extension_cache, :key, :repository, :git_url, :tag) + params.require(:extension).permit(:title, :author, :description, :extension, :extension_cache,:thumbnail, :thumbnail_cache, :key, :repository, :git_url, :price, :tag, previews_attributes: ['id', 'image', 'image_cache', '_destroy']) end end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index ddf1737..94cb0e4 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -76,6 +76,6 @@ class TemplatesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def template_params - params.require(:template).permit(:title, :author,:preview, :preview_cache, :template, :template_cache) + params.require(:template).permit(:title, :author,:thumbnail, :thumbnail_cache, :template, :template_cache, previews_attributes: ['id', 'image', 'image_cache', '_destroy']) end end diff --git a/app/models/client.rb b/app/models/client.rb index cb3e48b..dbcd438 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -12,7 +12,6 @@ class Client index({ confirmation_token: 1}, { unique: true }) - validates :site_id, :uniqueness => true validates :site_token, :uniqueness => true def generate_confirmation_token diff --git a/app/models/extension.rb b/app/models/extension.rb index 947a0f4..0797a9d 100644 --- a/app/models/extension.rb +++ b/app/models/extension.rb @@ -8,7 +8,6 @@ class Extension field :title, type: String field :author, type: String - field :preview, type: String field :extension, type: String field :description, type: String field :category_id, type: String @@ -21,14 +20,14 @@ class Extension slug :title, history: true + has_many :previews, class_name: 'Preview' + accepts_nested_attributes_for :previews, :allow_destroy => true + belongs_to :category - IMAGE_SIZES = { - :thumb => [100, 100] - } - - mount_uploader :preview, ImageUploader mount_uploader :extension, ProductUploader + mount_uploader :thumbnail, ImageUploader + elasticsearch! diff --git a/app/models/preview.rb b/app/models/preview.rb new file mode 100644 index 0000000..3d34b6f --- /dev/null +++ b/app/models/preview.rb @@ -0,0 +1,9 @@ +class Preview + include Mongoid::Document + field :image, type: String + + belongs_to :extension + belongs_to :templates + + mount_uploader :image, PreviewUploader +end diff --git a/app/models/template.rb b/app/models/template.rb index 2be0987..5c3a38b 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -7,7 +7,6 @@ class Template field :title, type: String field :author, type: String - field :preview, type: String field :template, type: String field :category_id, type: String field :price, type: Float @@ -16,12 +15,11 @@ class Template slug :title, history: true belongs_to :category - IMAGE_SIZES = { - :thumb => [256, 180] - } + has_many :previews, class_name: 'Preview' + accepts_nested_attributes_for :previews - mount_uploader :preview, ImageUploader mount_uploader :template, ProductUploader + mount_uploader :thumbnail, ImageUploader elasticsearch! diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index aaff446..923eb0a 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -37,28 +37,31 @@ class ImageUploader < CarrierWave::Uploader::Base # end - version :thumb, :if => :has_thumb_size? do - process :dynamic_resize_to_fit => :thumb + version :thumb_template, :if => :is_template? do + process :resize_to_fit => [480,300] end - def dynamic_resize_to_fit(size) - resize_to_fit *(model.class::IMAGE_SIZES[size]) + version :thumb_extension, :if => :is_extension? do + process :resize_to_fit => [300,300] end - def method_missing(method, *args) - return false if method.to_s.match(/has_(.*)_size\?/) - super + version :thumb_index do + process :resize_to_fit => [100,100] end -# protected + version :thumb_template_index, :if => :is_template? do + process :resize_to_fit => [256,180] + end -# def setup_available_sizes(file) -# model.class::IMAGE_SIZES.keys.each do |key| -# self.class_eval do -# define_method("has_#{key}_size?".to_sym) { true } -# end -# end -# end + +protected + def is_template? file + model.class.to_s == "Template" + end + + def is_extension? file + model.class.to_s == "Extension" + end # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: diff --git a/app/uploaders/preview_uploader.rb b/app/uploaders/preview_uploader.rb new file mode 100644 index 0000000..67c23a0 --- /dev/null +++ b/app/uploaders/preview_uploader.rb @@ -0,0 +1,50 @@ +# encoding: utf-8 + +class PreviewUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + include CarrierWave::RMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + + process :resize_to_fit => [1024, 768] + + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/extensions/_form.html.erb b/app/views/extensions/_form.html.erb index 31a2fb5..6da67b4 100644 --- a/app/views/extensions/_form.html.erb +++ b/app/views/extensions/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for(@extension) do |f| %> +<%= nested_form_for(@extension, :html=>{:multipart => true}) do |f| %> <% if @extension.errors.any? %>

<%= pluralize(@extension.errors.count, "error") %> prohibited this extension from being saved:

@@ -50,10 +50,18 @@ <%= f.text_field :tag %>
- - <%= f.file_field :preview %> - <%= f.hidden_field :preview_cache %> -

+ + <%= f.file_field :thumbnail %> + <%= f.hidden_field :thumbnail_cache %> +

+ + + <%= f.fields_for :previews do |p| %> + <%= p.file_field :image %> + <%= p.hidden_field :image_cache %> + <%= p.link_to_remove "Remove this file" %> + <% end %> +

<%= f.link_to_add "Add a file", :previews %>

diff --git a/app/views/extensions/index.html.erb b/app/views/extensions/index.html.erb index e6892c7..d4a5b28 100644 --- a/app/views/extensions/index.html.erb +++ b/app/views/extensions/index.html.erb @@ -1,13 +1,3 @@ - - <%= render :partial => "shared/sort_bar" %> <%= render :partial => "shared/item_cluster", :locals => {:type => "extensions", :title => "Popular Apps", :moreLink => "#", :frequency => 12} %> diff --git a/app/views/extensions/show.html.erb b/app/views/extensions/show.html.erb index 5c025e8..eff3f43 100644 --- a/app/views/extensions/show.html.erb +++ b/app/views/extensions/show.html.erb @@ -1,32 +1 @@ - - <%= render :partial => "shared/item_details", :locals => {:type => "extensions"} %> \ No newline at end of file diff --git a/app/views/shared/_banner.html.erb b/app/views/shared/_banner.html.erb index 530a5a9..d061535 100644 --- a/app/views/shared/_banner.html.erb +++ b/app/views/shared/_banner.html.erb @@ -1 +1,54 @@ -

\ No newline at end of file +
+ +
\ No newline at end of file diff --git a/app/views/shared/_item_card.html.erb b/app/views/shared/_item_card.html.erb index 90ca7ec..d821816 100644 --- a/app/views/shared/_item_card.html.erb +++ b/app/views/shared/_item_card.html.erb @@ -1,5 +1,4 @@ <% @products = (@templates if type.eql?('templates')) || (@extensions if type.eql?('extensions')) %> - <% cache [ 'product list', expires_in: 60.seconds ] do %> <% @products.each do |product| %>
@@ -7,7 +6,11 @@
<%= link_to "", product, :class=> "details-link" %>
- <%= placeholdit_image_tag (type == 'templates' ? "256x180" : '100x100'), background_color: "#3f3f3f" %> + <% if product.thumbnail.present? %> + <%= image_tag(type == "templates" ? product.thumbnail.thumb_template_index.url : (type == "extensions" ? product.thumbnail.thumb_index.url : ""))%> + <% else%> + <%= placeholdit_image_tag (type == 'templates' ? "256x180" : '100x100'), background_color: "#3f3f3f" %> + <% end %>
diff --git a/app/views/shared/_item_details.html.erb b/app/views/shared/_item_details.html.erb index 3e9b494..1ccff11 100644 --- a/app/views/shared/_item_details.html.erb +++ b/app/views/shared/_item_details.html.erb @@ -3,7 +3,11 @@
- <%= placeholdit_image_tag (type == "templates" ? "480x300" : (type == "extensions" ? "300x300" : "")), background_color: "#3f3f3f" %> + <% if @product.thumbnail.present? %> + <%= image_tag(type == "templates" ? @product.thumbnail.thumb_template.url : (type == "extensions" ? @product.thumbnail.thumb_extension.url : ""))%> + <% else %> + <%= placeholdit_image_tag (type == "templates" ? "480x300" : (type == "extensions" ? "300x300" : "")), background_color: "#3f3f3f" %> + <% end %>

<%= @product.title %>

@@ -37,10 +41,18 @@
    - <% 5.times do %> + <% if @product.previews.present? %> + <% @product.previews.each do |p|%> +
  • + <%=image_tag p.image.url, width: "1024", height: "768" %> +
  • + <% end %> + <% else%> + <% 5.times do%>
  • <%= placeholdit_image_tag ("1024x768"), background_color: "#3f3f3f" %>
  • + <% end %> <% end %>
diff --git a/app/views/templates/_form.html.erb b/app/views/templates/_form.html.erb index dddbbb9..83007c5 100644 --- a/app/views/templates/_form.html.erb +++ b/app/views/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for(@template, :html => {:multipart => true}) do |f| %> +<%= nested_form_for(@template, :html => {:multipart => true}) do |f| %> <% if @template.errors.any? %>

<%= pluralize(@template.errors.count, "error") %> prohibited this template from being saved:

@@ -19,12 +19,20 @@ <%= f.label :author %>
<%= f.text_field :author %>
+

- - <%= f.file_field :preview %> - <%= f.hidden_field :preview_cache %> + + <%= f.file_field :thumbnail %> + <%= f.hidden_field :thumbnail_cache %>

+ <%= f.fields_for :previews do |p| %> + <%= p.file_field :image %> + <%= p.hidden_field :image_cache %> + <%= p.link_to_remove "Remove this file" %> + <% end %> +

<%= f.link_to_add "Add a file", :previews %>

+

<%= f.file_field :template %> diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb index 0061f2e..3f5bd67 100644 --- a/app/views/templates/index.html.erb +++ b/app/views/templates/index.html.erb @@ -3,7 +3,6 @@

<%=link_to template.title, template %>

Author: <%= template.author %>

-

<%=image_tag template.preview.thumb.url%>

<%=link_to 'Download', template.template.url, :class=> 'btn btn-success'%>

<%= link_to 'View details »'.html_safe ,template, :class=>"btn btn-primary"%>

diff --git a/app/views/templates/show.html.erb b/app/views/templates/show.html.erb index 5d6adb1..318361d 100644 --- a/app/views/templates/show.html.erb +++ b/app/views/templates/show.html.erb @@ -1,25 +1 @@ - - - <%= render :partial => "shared/item_details", :locals => {:type => "templates"} %> \ No newline at end of file +<%= render :partial => "shared/item_details", :locals => {:type => "templates"} %> \ No newline at end of file diff --git a/test/fixtures/previews.yml b/test/fixtures/previews.yml new file mode 100644 index 0000000..722f56a --- /dev/null +++ b/test/fixtures/previews.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + file: MyString + +two: + file: MyString diff --git a/test/models/preview_test.rb b/test/models/preview_test.rb new file mode 100644 index 0000000..04ab578 --- /dev/null +++ b/test/models/preview_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PreviewTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end