Class: Caboose::FontsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::FontsController
- Defined in:
- app/controllers/caboose/fonts_controller.rb
Instance Method Summary collapse
- #admin_family_add ⇒ Object
- #admin_family_edit ⇒ Object
- #admin_family_index ⇒ Object
- #admin_family_json ⇒ Object
- #admin_family_json_single ⇒ Object
- #admin_index ⇒ Object
- #admin_update ⇒ Object
- #admin_variant_add ⇒ Object
- #admin_variant_edit ⇒ Object
- #admin_variant_update ⇒ Object
- #admin_variant_update_ttf_file ⇒ Object
- #admin_variant_update_woff_file ⇒ Object
Methods inherited from ApplicationController
#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_family_add ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/caboose/fonts_controller.rb', line 88 def admin_family_add return if !user_is_allowed('fonts', 'add') resp = StdClass.new if params[:name].blank? resp.error = "Name is required." render :json => resp and return end ff = FontFamily.new ff.name = params[:name] ff.save resp.redirect = "/admin/font-families/#{ff.id}" render :json => resp end |
#admin_family_edit ⇒ Object
104 105 106 107 |
# File 'app/controllers/caboose/fonts_controller.rb', line 104 def admin_family_edit return if !user_is_allowed('fonts', 'add') @ff = FontFamily.find(params[:id]) end |
#admin_family_index ⇒ Object
58 59 60 |
# File 'app/controllers/caboose/fonts_controller.rb', line 58 def admin_family_index return if !user_is_allowed('fonts', 'view') end |
#admin_family_json ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/caboose/fonts_controller.rb', line 63 def admin_family_json return if !user_is_allowed('fonts', 'view') pager = PageBarGenerator.new(params, { 'name_like' => '' },{ 'model' => 'Caboose::FontFamily', 'sort' => 'name', 'desc' => false, 'base_url' => '/admin/font-families', 'items_per_page' => 50 }) render :json => { :pager => pager, :models => pager.items.as_json } end |
#admin_family_json_single ⇒ Object
81 82 83 84 85 |
# File 'app/controllers/caboose/fonts_controller.rb', line 81 def admin_family_json_single return if !user_is_allowed('fonts', 'view') ff = FontFamily.find(params[:id]) render :json => ff.as_json end |
#admin_index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/caboose/fonts_controller.rb', line 6 def admin_index @hf = Font.where(:site_id => @site.id, :name => "heading-font").last if !@hf then @hf = Font.create(:site_id => @site.id, :name => "heading-font", :family => "Open Sans", :variant => "600", :url => "http://fonts.gstatic.com/s/opensans/v13/MTP_ySUJH_bn48VBG8sNSi3USBnSvpkopQaUR-2r7iU.ttf") end @bf = Font.where(:site_id => @site.id, :name => "body-font").last if !@bf then @bf = Font.create(:site_id => @site.id, :name => "body-font", :family => "Open Sans", :variant => "regular", :url => "http://fonts.gstatic.com/s/opensans/v13/IgZJs4-7SA1XX_edsoXWog.ttf") end @bfb = Font.where(:site_id => @site.id, :name => "body-font-bold").last if !@bfb then @bfb = Font.create(:site_id => @site.id, :name => "body-font-bold", :family => "Open Sans", :variant => "600", :url => "http://fonts.gstatic.com/s/opensans/v13/MTP_ySUJH_bn48VBG8sNSi3USBnSvpkopQaUR-2r7iU.ttf") end @bfi = Font.where(:site_id => @site.id, :name => "body-font-italic").last if !@bfi then @bfi = Font.create(:site_id => @site.id, :name => "body-font-italic", :family => "Open Sans", :variant => "italic", :url => "http://fonts.gstatic.com/s/opensans/v13/O4NhV7_qs9r9seTo7fnsVKCWcynf_cDxXwCLxiixG1c.ttf") end @bfbi = Font.where(:site_id => @site.id, :name => "body-font-bold-italic").last if !@bfbi then @bfbi = Font.create(:site_id => @site.id, :name => "body-font-bold-italic", :family => "Open Sans", :variant => "600italic", :url => "http://fonts.gstatic.com/s/opensans/v13/PRmiXeptR36kaC0GEAetxpZ7xm-Bj30Bj2KNdXDzSZg.ttf") end @btn = Font.where(:site_id => @site.id, :name => "button-font").last if !@btn then @btn = Font.create(:site_id => @site.id, :name => "button-font", :family => "Open Sans", :variant => "regular", :url => "http://fonts.gstatic.com/s/opensans/v13/IgZJs4-7SA1XX_edsoXWog.ttf") end @custom1 = Font.where(:site_id => @site.id, :name => "custom1-font").last if !@custom1 then @custom1 = Font.create(:site_id => @site.id, :name => "custom1-font", :family => "Open Sans", :variant => "regular", :url => "http://fonts.gstatic.com/s/opensans/v13/IgZJs4-7SA1XX_edsoXWog.ttf") end @custom2 = Font.where(:site_id => @site.id, :name => "custom2-font").last if !@custom2 then @custom2 = Font.create(:site_id => @site.id, :name => "custom2-font", :family => "Open Sans", :variant => "regular", :url => "http://fonts.gstatic.com/s/opensans/v13/IgZJs4-7SA1XX_edsoXWog.ttf") end @custom3 = Font.where(:site_id => @site.id, :name => "custom3-font").last if !@custom3 then @custom3 = Font.create(:site_id => @site.id, :name => "custom3-font", :family => "Open Sans", :variant => "regular", :url => "http://fonts.gstatic.com/s/opensans/v13/IgZJs4-7SA1XX_edsoXWog.ttf") end end |
#admin_update ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/caboose/fonts_controller.rb', line 28 def admin_update resp = StdClass.new family = params[:family] name = params[:name] url = params[:url] variant = params[:variant] if !family.blank? && !name.blank? && !url.blank? && !variant.blank? font = Font.where(:site_id => @site.id, :name => name).last if font fam = FontFamily.where(:name => family).first var = fam ? FontVariant.where(:font_family_id => fam.id).where("CONCAT(style,weight) = ?", variant).first : nil font.family = family font.url = url font.variant = variant font.variant_id = var.id if var font.save resp.success = "Font saved!" else resp.error = "Font doesn't exist yet" end else resp.error = "Error saving font" end render :json => resp end |
#admin_variant_add ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/caboose/fonts_controller.rb', line 116 def admin_variant_add return if !user_is_allowed('fonts', 'add') resp = StdClass.new if params[:variant].blank? resp.error = "Variant Name is required." render :json => resp and return end ff = FontVariant.new ff.font_family_id = params[:family_id] ff.weight = 'regular' ff.variant = params[:variant] ff.sort_order = 10 ff.save resp.redirect = "/admin/font-variants/#{ff.id}" render :json => resp end |
#admin_variant_edit ⇒ Object
110 111 112 113 |
# File 'app/controllers/caboose/fonts_controller.rb', line 110 def admin_variant_edit return if !user_is_allowed('fonts', 'edit') @variant = FontVariant.find(params[:id]) end |
#admin_variant_update ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/caboose/fonts_controller.rb', line 134 def admin_variant_update return unless user_is_allowed_to 'edit', 'fonts' resp = Caboose::StdClass.new variant = FontVariant.find(params[:id]) params.each do |k,v| case k when "variant" then variant.variant = v when "ttf_url" then (variant.ttf_url = v if (v.blank? || (v.include?('.ttf') && v.include?('http')))) when "weight" then variant.weight = v when "style" then variant.style = v when "sort_order" then variant.sort_order = v end end resp.success = variant.save render :json => resp end |
#admin_variant_update_ttf_file ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'app/controllers/caboose/fonts_controller.rb', line 152 def admin_variant_update_ttf_file return unless user_is_allowed_to 'edit', 'fonts' resp = Caboose::StdClass.new var = FontVariant.find(params[:id]) var.ttf_file = params[:ttf_file] var.save resp.success = true resp.attributes = { 'ttf_file' => { 'value' => var.ttf_file.url }} render :json => resp end |
#admin_variant_update_woff_file ⇒ Object
164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/caboose/fonts_controller.rb', line 164 def admin_variant_update_woff_file return unless user_is_allowed_to 'edit', 'fonts' resp = Caboose::StdClass.new var = FontVariant.find(params[:id]) var.woff_file = params[:woff_file] var.save resp.success = true resp.attributes = { 'woff_file' => { 'value' => var.woff_file.url }} render :json => resp end |