diff --git a/app/assets/stylesheets/rulingorbit.css.erb b/app/assets/stylesheets/rulingorbit.css.erb index dd53ef193..db2be30b9 100644 --- a/app/assets/stylesheets/rulingorbit.css.erb +++ b/app/assets/stylesheets/rulingorbit.css.erb @@ -287,7 +287,7 @@ header { } #content .main { float: right; - width: 680px; + width: 676px; } #item-info .item-thumb { width: 210px; diff --git a/app/controllers/admin/purchases_controller.rb b/app/controllers/admin/purchases_controller.rb index f4d1ae2a2..f1663c95e 100644 --- a/app/controllers/admin/purchases_controller.rb +++ b/app/controllers/admin/purchases_controller.rb @@ -9,6 +9,17 @@ class Admin::PurchasesController < ApplicationController @purchases = Purchase.all.entries end + def buy_template + original_file, zip_name = download_template(params[:id]) + temp_file = Tempfile.new("temp_file_zip") + temp_file.binmode + temp_file.write original_file + temp_file.rewind + unzip_design(temp_file, zip_name) + temp_file.close + temp_file.unlink + end + def download @purchase = Purchase.first(:conditions => {:id => params[:id]}) download_purchase(@purchase, request.env['REQUEST_URI'].split('admin')[0].chop) @@ -183,4 +194,66 @@ class Admin::PurchasesController < ApplicationController end + + def download_template(id) + uri = URI.parse("http://#{APP_CONFIG['store_ip']}/download/design/#{id}") + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + [response.body, (response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue '')] + end + + def unzip_design(input_file, zip_name) + temp_file = Tempfile.new("temp_file") + temp_file.write(input_file.read.force_encoding('UTF-8')) + temp_file.rewind + Zip::ZipFile.open(temp_file) { |zip_file| + design = Design.new.from_json(zip_file.read("#{zip_name}/info.json")) + Dir.mktmpdir('f_path') { |dir| + themes_entries = [] + javascripts_entries = [] + images_entries = [] + screenshots_entries = [] + + zip_file.entries.each do |entry| + case (path = entry.to_s) + when /\A(#{zip_name})\/(default\.css)\z/ #for default css + design.build_css_default(:file => get_temp_file(zip_file, dir, entry)) + when /\A(#{zip_name})\/(reset\.css)\z/ #for reset css + design.build_css_reset(:file => get_temp_file(zip_file, dir, entry)) + when /\A(#{zip_name})\/(layout\.html)\z/ #for layout html + design.build_layout(:file => get_temp_file(zip_file, dir, entry)) + when /\A(#{zip_name})\/(thumb((\.jpg)|(\.png)|(\.gif)))\z/ #for thumb + design.build_thumb(:file => get_temp_file(zip_file, dir, entry)) + when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css + themes_entries << entry + when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js + javascripts_entries << entry + when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img + images_entries << entry + when /\A(#{zip_name})\/(screenshots)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img + screenshots_entries << entry + end + end + + ['themes', 'javascripts', 'images', 'screenshots'].each do |type| + eval("#{type}_entries").each do |entry| + eval("design.#{type}").build(:file => get_temp_file(zip_file, dir, entry)) + end + end + } + design.zip_file = input_file + design.save + } + temp_file.close + temp_file.unlink + end + + def get_temp_file(zip_file, dir, entry) + filename = File.basename(entry.to_s) + temp_file = File.new(dir + '/' + filename, 'w+') + temp_file.write (zip_file.read entry ).force_encoding('UTF-8') + temp_file + end + end \ No newline at end of file diff --git a/app/controllers/admin/template_store_controller.rb b/app/controllers/admin/template_store_controller.rb index cdda6ff90..16e8fc056 100644 --- a/app/controllers/admin/template_store_controller.rb +++ b/app/controllers/admin/template_store_controller.rb @@ -3,9 +3,29 @@ class Admin::TemplateStoreController < ApplicationController layout "new_admin" def index + @templates = JSON.parse(get_templates) end def show + @template = JSON.parse(get_template(params[:id])) + end + + protected + + def get_template(id) + uri = URI.parse("http://#{APP_CONFIG['store_ip']}/store/design/#{id}") + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + response.body + end + + def get_templates + uri = URI.parse("http://#{APP_CONFIG['store_ip']}/store/designs") + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + response.body end end \ No newline at end of file diff --git a/app/models/design/design.rb b/app/models/design/design.rb index aa43368a3..d6de4a75b 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -8,62 +8,26 @@ class Design field :title, :type => String field :version, :type => String + mount_uploader :zip_file, AssetUploader + has_one :css_default, as: :css, :autosave => true, :dependent => :destroy has_one :layout, :autosave => true, :dependent => :destroy has_one :css_reset, :autosave => true, :dependent => :destroy + has_one :thumb, :autosave => true, :dependent => :destroy has_many :images, as: :imgs, :autosave => true, :dependent => :destroy has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy has_many :pages + has_many :screenshots, :autosave => true, :dependent => :destroy has_many :themes, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :images, :allow_destroy => true accepts_nested_attributes_for :javascripts, :allow_destroy => true + accepts_nested_attributes_for :screenshots, :allow_destroy => true accepts_nested_attributes_for :themes, :allow_destroy => true validates_presence_of :author, :title after_save :parse_css_for_images - - - def new_files=(*attrs) - attrs[0].map do |key,items_ary| #Loop by JSs,Themes,Imgs - self.files=([items_ary, key]) - end - end - - # def javascripts=(*attrs) - # self.files = (attrs << 'javascripts') - # end - # - # def themes=(*attrs) - # self.files = (attrs << 'themes') - # end - # - # def images=(*attrs) - # self.files = (attrs << 'images') - # end - - # Update or create the attribute records - def files=(attrs) - case attrs.last - when 'layout' - files = self.layout.build - else - files = eval(attrs.last) - end - attrs[0].each do |a| - - if a[:id].blank? && !a[:file].blank? - files.build(:file => a[:file], :to_save => true) - else - files.each do |file| - if file.id.to_s == a[:id] - file.to_destroy = a[:to_destroy] - end - end - end - end - end protected diff --git a/app/models/design/screenshot.rb b/app/models/design/screenshot.rb new file mode 100644 index 000000000..f0116e147 --- /dev/null +++ b/app/models/design/screenshot.rb @@ -0,0 +1,3 @@ +class Screenshot < Image + belongs_to :design +end \ No newline at end of file diff --git a/app/models/design/thumb.rb b/app/models/design/thumb.rb new file mode 100644 index 000000000..5c2265420 --- /dev/null +++ b/app/models/design/thumb.rb @@ -0,0 +1,3 @@ +class Thumb < Image + belongs_to :design +end \ No newline at end of file diff --git a/app/views/admin/designs/_design.html.erb b/app/views/admin/designs/_design.html.erb index bf75bd657..3f5798448 100644 --- a/app/views/admin/designs/_design.html.erb +++ b/app/views/admin/designs/_design.html.erb @@ -1,6 +1,6 @@ - <%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %> - + <%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %> + <%= design.title %>
- <%= design.author %> - <%= design.intro %> + <%= design.intro %> + <%= design.author %> \ No newline at end of file diff --git a/app/views/admin/designs/_designs.html.erb b/app/views/admin/designs/_designs.html.erb index 838057f22..48d2f3644 100644 --- a/app/views/admin/designs/_designs.html.erb +++ b/app/views/admin/designs/_designs.html.erb @@ -1,8 +1,8 @@ - + diff --git a/app/views/admin/designs/_sort_headers.html.erb b/app/views/admin/designs/_sort_headers.html.erb index ff03706fd..2fb84f60d 100644 --- a/app/views/admin/designs/_sort_headers.html.erb +++ b/app/views/admin/designs/_sort_headers.html.erb @@ -1,4 +1,4 @@ <%= render_sort_bar(true, delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), - ['title', 'title','span7', :title], - ['author', 'author', 'span2', :author], - ['intro', 'intro', 'span2', :intro]).html_safe %> + ['title', 'title','span2', :title], + ['intro', 'intro', 'span7', :intro], + ['author', 'author', 'span2', :author]).html_safe %> diff --git a/app/views/admin/template_store/index.html.erb b/app/views/admin/template_store/index.html.erb index fee46fee2..18754f398 100644 --- a/app/views/admin/template_store/index.html.erb +++ b/app/views/admin/template_store/index.html.erb @@ -76,18 +76,20 @@
diff --git a/app/views/admin/template_store/show.html.erb b/app/views/admin/template_store/show.html.erb index 7b39093df..4df566cbb 100644 --- a/app/views/admin/template_store/show.html.erb +++ b/app/views/admin/template_store/show.html.erb @@ -13,35 +13,68 @@ <%= javascript_include_tag "rulingorbit" %> <% end %> -
-
- -
-
-
-
- -

Template Name

- free download -
    -
  • views15,241
  • -
  • color
  • -
-
+<% if @template %> +
+ -
-

description

-
Pixel Union’s Jitensha defines storefront minimalism. Japanese for “bicycle,” Jitensha offers clean typography and easy usability, including full color, font, logo, and footer customization. With its painless social media and blog integration, Jitensha gorgeously accomodates every aspect of your business. Any questions before you launch? Don’t hesitate to email us: Support@PixelUnion.net.
-

screen shot

-
-
- Thumbnail 1 - Thumbnail 2 - Thumbnail 3 - Thumbnail 4 - Thumbnail 5 +
+
+
+ <%= image_tag "http://#{APP_CONFIG['store_ip']}#{@template['thumb']}", :class => "item-thumb" %> +

<%= @template['title'] %>

+ <%= link_to 'free download', buy_template_admin_purchase_path(@template['id']), :id => "download" %> +
    +
  • views15,241
  • +
  • color
  • +
+
+
+
+

description

+
<%= @template['intro'] %>
+

screen shot

+
+
+ <% @template['screenshots'].each do |screenshot| %> + <%= image_tag "http://#{APP_CONFIG['store_ip']}#{screenshot}", :class => "preview item-thumb" %> + <% end %> +
-
\ No newline at end of file +<% else %> +
+ +
+
+
+ +

Template Name

+ free download +
    +
  • views15,241
  • +
  • color
  • +
+
+
+
+

description

+
Pixel Union’s Jitensha defines storefront minimalism. Japanese for “bicycle,” Jitensha offers clean typography and easy usability, including full color, font, logo, and footer customization. With its painless social media and blog integration, Jitensha gorgeously accomodates every aspect of your business. Any questions before you launch? Don’t hesitate to email us: Support@PixelUnion.net.
+

screen shot

+
+
+ Thumbnail 1 + Thumbnail 2 + Thumbnail 3 + Thumbnail 4 + Thumbnail 5 +
+
+
+
+
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 32d8430a3..c7de04fbc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,6 +112,7 @@ Orbit::Application.routes.draw do get 'install_app' end member do + get 'buy_template' get 'download' end end @@ -137,14 +138,14 @@ Orbit::Application.routes.draw do end resources :member_selects do - match 'member_select_search' => "member_selects#member_select_search" ,:as => :member_select_search,:via => "post" - match 'member_select_add' => "member_selects#member_select_add" ,:as => :member_select_add,:via => "post" - end + match 'member_select_search' => "member_selects#member_select_search" ,:as => :member_select_search,:via => "post" + match 'member_select_add' => "member_selects#member_select_add" ,:as => :member_select_add,:via => "post" + end - match 'module_store' => 'module_store#index' - match 'module_store/show' => 'module_store#show' - match 'template_store' => 'template_store#index' - match 'template_store/show' => 'template_store#show' + match 'module_store' => 'module_store#index' + match 'module_store/show' => 'module_store#show' + match 'template_store' => 'template_store#index' + match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template end # end admin