loyal_core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +3 -0
  3. data/Rakefile +27 -0
  4. data/app/assets/images/loyal_core/down_rating.gif +0 -0
  5. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/ico_missing.gif +0 -0
  6. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/medium_missing.gif +0 -0
  7. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/mini_missing.gif +0 -0
  8. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/missing.gif +0 -0
  9. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/small_missing.gif +0 -0
  10. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/thumb_missing.gif +0 -0
  11. data/app/assets/images/loyal_core/fallbacks/loyal_core/skin/recipe/avatar/tiny_missing.gif +0 -0
  12. data/app/assets/images/loyal_core/fallbacks/user/avatar/ico_missing.gif +0 -0
  13. data/app/assets/images/loyal_core/fallbacks/user/avatar/medium_missing.gif +0 -0
  14. data/app/assets/images/loyal_core/fallbacks/user/avatar/mini_missing.gif +0 -0
  15. data/app/assets/images/loyal_core/fallbacks/user/avatar/missing.gif +0 -0
  16. data/app/assets/images/loyal_core/fallbacks/user/avatar/small_missing.gif +0 -0
  17. data/app/assets/images/loyal_core/fallbacks/user/avatar/thumb_missing.gif +0 -0
  18. data/app/assets/images/loyal_core/fallbacks/user/avatar/tiny_missing.gif +0 -0
  19. data/app/assets/images/loyal_core/liked.gif +0 -0
  20. data/app/assets/images/loyal_core/unlike.gif +0 -0
  21. data/app/assets/images/loyal_core/up_rating.gif +0 -0
  22. data/app/assets/javascripts/jquery.cookie.js +95 -0
  23. data/app/assets/javascripts/loyal_core/admin/skin/folders.js +2 -0
  24. data/app/assets/javascripts/loyal_core/admin/skin/recipes.js +2 -0
  25. data/app/assets/javascripts/loyal_core/ajax/captchas.js +2 -0
  26. data/app/assets/javascripts/loyal_core/ajax/like_tracks.js +2 -0
  27. data/app/assets/javascripts/loyal_core/ajax/rating_tracks.js +3 -0
  28. data/app/assets/javascripts/loyal_core/ajax/users/sessions.js +2 -0
  29. data/app/assets/javascripts/loyal_core/ajax.js +124 -0
  30. data/app/assets/javascripts/loyal_core/application.js +6 -0
  31. data/app/assets/javascripts/loyal_core/jumps.js +2 -0
  32. data/app/assets/javascripts/loyal_core/tools/append_params_return_to.js +21 -0
  33. data/app/assets/javascripts/loyal_core/tools/editor_content_mode_selector.js +8 -0
  34. data/app/assets/javascripts/loyal_core/tools/font_selector.js +83 -0
  35. data/app/assets/stylesheets/loyal_core/admin/skin/folders.css +4 -0
  36. data/app/assets/stylesheets/loyal_core/admin/skin/recipes.css +4 -0
  37. data/app/assets/stylesheets/loyal_core/ajax/captchas.css +4 -0
  38. data/app/assets/stylesheets/loyal_core/ajax/like_tracks.css +4 -0
  39. data/app/assets/stylesheets/loyal_core/ajax/rating_tracks.css +4 -0
  40. data/app/assets/stylesheets/loyal_core/ajax/users/sessions.css +4 -0
  41. data/app/assets/stylesheets/loyal_core/application.css.scss +18 -0
  42. data/app/assets/stylesheets/loyal_core/jumps.css +4 -0
  43. data/app/controllers/loyal_core/admin/skin/folders_controller.rb +54 -0
  44. data/app/controllers/loyal_core/admin/skin/recipes_controller.rb +52 -0
  45. data/app/controllers/loyal_core/ajax/captchas_controller.rb +26 -0
  46. data/app/controllers/loyal_core/ajax/like_tracks_controller.rb +33 -0
  47. data/app/controllers/loyal_core/ajax/rating_tracks_controller.rb +41 -0
  48. data/app/controllers/loyal_core/ajax/users/sessions_controller.rb +8 -0
  49. data/app/controllers/loyal_core/ajax_controller.rb +14 -0
  50. data/app/controllers/loyal_core/application_controller.rb +6 -0
  51. data/app/controllers/loyal_core/jumps_controller.rb +10 -0
  52. data/app/helpers/loyal_core/admin/skin/folders_helper.rb +5 -0
  53. data/app/helpers/loyal_core/admin/skin/recipes_helper.rb +5 -0
  54. data/app/helpers/loyal_core/ajax/captchas_helper.rb +6 -0
  55. data/app/helpers/loyal_core/ajax/like_tracks_helper.rb +6 -0
  56. data/app/helpers/loyal_core/ajax/rating_tracks_helper.rb +6 -0
  57. data/app/helpers/loyal_core/ajax/users/sessions_helper.rb +5 -0
  58. data/app/helpers/loyal_core/application_helper.rb +6 -0
  59. data/app/helpers/loyal_core/jumps_helper.rb +5 -0
  60. data/app/models/kindeditor/asset.rb +14 -0
  61. data/app/models/kindeditor/file.rb +4 -0
  62. data/app/models/kindeditor/flash.rb +4 -0
  63. data/app/models/kindeditor/image.rb +4 -0
  64. data/app/models/kindeditor/media.rb +4 -0
  65. data/app/models/loyal_core/like_track.rb +15 -0
  66. data/app/models/loyal_core/rating_track.rb +32 -0
  67. data/app/models/loyal_core/skin/dish.rb +10 -0
  68. data/app/models/loyal_core/skin/folder.rb +26 -0
  69. data/app/models/loyal_core/skin/recipe.rb +31 -0
  70. data/app/models/loyal_core/skin.rb +8 -0
  71. data/app/uploaders/loyal_core/asset_uploader.rb +128 -0
  72. data/app/uploaders/loyal_core/avatar_uploader.rb +37 -0
  73. data/app/views/layouts/loyal_core/application.html.erb +14 -0
  74. data/app/views/loyal_core/admin/skin/folders/_form.html.erb +9 -0
  75. data/app/views/loyal_core/admin/skin/folders/edit.html.erb +11 -0
  76. data/app/views/loyal_core/admin/skin/folders/index.html.erb +25 -0
  77. data/app/views/loyal_core/admin/skin/folders/new.html.erb +11 -0
  78. data/app/views/loyal_core/admin/skin/folders/show.html.erb +32 -0
  79. data/app/views/loyal_core/admin/skin/recipes/_form.html.erb +25 -0
  80. data/app/views/loyal_core/admin/skin/recipes/edit.html.erb +11 -0
  81. data/app/views/loyal_core/admin/skin/recipes/index.html.erb +37 -0
  82. data/app/views/loyal_core/admin/skin/recipes/new.html.erb +11 -0
  83. data/app/views/loyal_core/admin/skin/recipes/show.html.erb +16 -0
  84. data/app/views/loyal_core/ajax/captchas/_new.html.erb +1 -0
  85. data/app/views/loyal_core/ajax/captchas/new.html.erb +1 -0
  86. data/app/views/loyal_core/jumps/show.html.erb +12 -0
  87. data/app/views/simple_captcha/_simple_captcha.erb +16 -0
  88. data/config/locales/en/default.en.yml +139 -0
  89. data/config/locales/en/loyal_simple_captcha.en.yml +8 -0
  90. data/config/locales/zh-CN/action_view.zh-CN.yml +8 -0
  91. data/config/locales/zh-CN/default.zh-CN.yml +199 -0
  92. data/config/locales/zh-CN/loyal_simple_captcha.zh-CN.yml +8 -0
  93. data/config/locales/zh-CN/paginate.zh-CN.yml +8 -0
  94. data/config/routes.rb +24 -0
  95. data/db/migrate/20130331104216_create_loyal_core_rating_tracks.rb +19 -0
  96. data/db/migrate/20130331104822_create_loyal_core_like_tracks.rb +19 -0
  97. data/db/migrate/20130413061851_create_kindeditor_assets.rb +17 -0
  98. data/db/migrate/20130610091558_create_loyal_core_skin_folders.rb +48 -0
  99. data/db/migrate/20130610095635_create_loyal_core_skin_recipes.rb +28 -0
  100. data/db/migrate/20130610095938_create_loyal_core_skin_dishes.rb +13 -0
  101. data/lib/loyal_core/action_controller/request_init.rb +33 -0
  102. data/lib/loyal_core/action_controller/seo_methods.rb +47 -0
  103. data/lib/loyal_core/action_controller.rb +4 -0
  104. data/lib/loyal_core/action_helper/ajax/like_tracks_helper.rb +26 -0
  105. data/lib/loyal_core/action_helper/ajax/rating_tracks_helper.rb +35 -0
  106. data/lib/loyal_core/action_helper/font_selector_helper.rb +25 -0
  107. data/lib/loyal_core/action_helper.rb +27 -0
  108. data/lib/loyal_core/action_view/labeled_builder.rb +127 -0
  109. data/lib/loyal_core/action_view.rb +7 -0
  110. data/lib/loyal_core/active_model/fix_counter_cache.rb +39 -0
  111. data/lib/loyal_core/active_model/human_display_able.rb +26 -0
  112. data/lib/loyal_core/active_model/strip_whitespace.rb +27 -0
  113. data/lib/loyal_core/active_model.rb +16 -0
  114. data/lib/loyal_core/acts/bit_able.rb +139 -0
  115. data/lib/loyal_core/acts/content_depart_able.rb +102 -0
  116. data/lib/loyal_core/acts/content_mode_able.rb +88 -0
  117. data/lib/loyal_core/acts/has_avatar.rb +31 -0
  118. data/lib/loyal_core/acts/has_permalink.rb +43 -0
  119. data/lib/loyal_core/acts/like_track_able.rb +90 -0
  120. data/lib/loyal_core/acts/named_filter_able.rb +40 -0
  121. data/lib/loyal_core/acts/rating_track_able.rb +76 -0
  122. data/lib/loyal_core/acts/skin_dish_able.rb +56 -0
  123. data/lib/loyal_core/acts/tree.rb +104 -0
  124. data/lib/loyal_core/acts/uuid_ful.rb +39 -0
  125. data/lib/loyal_core/acts/views_count_able.rb +33 -0
  126. data/lib/loyal_core/acts.rb +35 -0
  127. data/lib/loyal_core/config.rb +116 -0
  128. data/lib/loyal_core/core_ext/singleton_class.rb +9 -0
  129. data/lib/loyal_core/engine.rb +11 -0
  130. data/lib/loyal_core/memoist.rb +204 -0
  131. data/lib/loyal_core/utils/array_util.rb +16 -0
  132. data/lib/loyal_core/utils/config_util.rb +186 -0
  133. data/lib/loyal_core/utils/data_util.rb +181 -0
  134. data/lib/loyal_core/utils/text_util.rb +49 -0
  135. data/lib/loyal_core/utils.rb +8 -0
  136. data/lib/loyal_core/version.rb +4 -0
  137. data/lib/loyal_core.rb +17 -0
  138. data/lib/tasks/loyal_core_tasks.rake +11 -0
  139. metadata +231 -0
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class Ajax::LikeTracksController < ::LoyalCore::AjaxController
4
+ before_filter :authenticate_user!
5
+
6
+ def touch
7
+ target_clazz = ::LoyalCore.config.clazz_alias[params[:target_type]]
8
+
9
+ result = {}
10
+
11
+ if target_clazz && (target_clazz = target_clazz.constantize)
12
+ target = target_clazz.find_by_uuid(params[:target_id])
13
+
14
+ _code = target.touch_liked_by!(current_user)
15
+
16
+ if target
17
+ result = {
18
+ :code => _code,
19
+ :count => target.liked_count
20
+ }
21
+ end
22
+ end
23
+
24
+ render :json => {
25
+ :response => {
26
+ :status => 200,
27
+ :code => :success
28
+ },
29
+ :result => result
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class Ajax::RatingTracksController < ::LoyalCore::AjaxController
4
+ before_filter :authenticate_user!
5
+
6
+ def up
7
+ down_or_up :up
8
+ end
9
+
10
+ def down
11
+ down_or_up :down
12
+ end
13
+
14
+ def down_or_up(action)
15
+ target_clazz = ::LoyalCore.config.clazz_alias[params[:target_type]]
16
+
17
+ result = {}
18
+
19
+ if target_clazz && (target_clazz = target_clazz.constantize)
20
+ target = target_clazz.find_by_uuid(params[:target_id])
21
+
22
+ if target
23
+ result = {
24
+ :code => target.send(:"#{action}_rating_by!", current_user),
25
+ :action => action,
26
+ :up_rating => target.up_rating,
27
+ :down_rating => target.down_rating
28
+ }
29
+ end
30
+ end
31
+
32
+ render :json => {
33
+ :response => {
34
+ :status => 200,
35
+ :code => :success
36
+ },
37
+ :result => result
38
+ }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class Ajax::Users::SessionsController < ::LoyalCore::AjaxController
4
+ def new
5
+
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ # 处理所有ajax请求
4
+ class AjaxController < ::LoyalCore::ApplicationController
5
+ before_filter :require_request_xhr!
6
+
7
+ protected
8
+
9
+ # 需要是ajax 请求
10
+ def require_request_xhr!
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class ApplicationController < ::ActionController::Base
4
+
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class JumpsController < ApplicationController
4
+ # TODO: 增加跳转页面的处理
5
+ # FIXME: 跳转页面不合理
6
+ def show
7
+ render 'loyal_core/jumps/show', :layout => nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Admin::Skin::FoldersHelper
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Admin::Skin::RecipesHelper
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Ajax::CaptchasHelper
4
+
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Ajax::LikeTracksHelper
4
+
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Ajax::RatingTracksHelper
4
+
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Ajax::Users::SessionsHelper
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module ApplicationHelper
4
+
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module JumpsHelper
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Kindeditor::Asset < ActiveRecord::Base
3
+ self.table_name = 'kindeditor_assets'
4
+ mount_uploader :asset, ::Kindeditor::AssetUploader
5
+ validates_presence_of :asset
6
+ before_save :update_asset_attributes
7
+ attr_accessible :asset
8
+
9
+ private
10
+ def update_asset_attributes
11
+ self.file_size = asset.file.size
12
+ self.file_type = asset.file.content_type
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Kindeditor::File < Kindeditor::Asset
3
+ mount_uploader :asset, Kindeditor::FileUploader
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Kindeditor::Flash < Kindeditor::Asset
3
+ mount_uploader :asset, Kindeditor::FlashUploader
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Kindeditor::Image < Kindeditor::Asset
3
+ mount_uploader :asset, Kindeditor::ImageUploader
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Kindeditor::Media < Kindeditor::Asset
3
+ mount_uploader :asset, Kindeditor::MediaUploader
4
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ #
4
+ class LikeTrack < ActiveRecord::Base
5
+ attr_accessible :position
6
+
7
+ # self.acts_as_tiny_cached
8
+
9
+ self.loyal_passport_acts_as_creator_able
10
+
11
+ belongs_to :target, :polymorphic => true, :counter_cache => :liked_count
12
+
13
+ validates_uniqueness_of :created_by, :scope => [:target_id, :target_type]
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class RatingTrack < ActiveRecord::Base
4
+ attr_accessible :score
5
+
6
+ # self.acts_as_tiny_cached
7
+
8
+ self.loyal_passport_acts_as_creator_able
9
+
10
+ # TODO: counter_cache 是否需要?
11
+ belongs_to :target, :polymorphic => true, :counter_cache => true
12
+
13
+ # 保存之后需要 更新好评度,与差评度
14
+ after_create do |r|
15
+ if r.score > 0
16
+ r.target_type.constantize.update_counters(r.target_id, :up_rating => r.score)
17
+ else
18
+ r.target_type.constantize.update_counters(r.target_id, :down_rating => r.score)
19
+ end
20
+ end
21
+
22
+ after_destroy do |r|
23
+ if r.score > 0
24
+ r.target_type.constantize.update_counters(r.target_id, :up_rating => -(r.score))
25
+ else
26
+ r.target_type.constantize.update_counters(r.target_id, :down_rating => -(r.score))
27
+ end
28
+ end
29
+
30
+ validates_uniqueness_of :created_by, :scope => [:target_id, :target_type]
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class Skin::Dish < ActiveRecord::Base
4
+ attr_accessible :recipe_id, :target_id, :target_type
5
+
6
+ belongs_to :recipe, :class_name => '::LoyalCore::Skin::Recipe'
7
+ belongs_to :target, :polymorphic => true
8
+
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class Skin::Folder < ActiveRecord::Base
4
+ # attr_accessible :title, :body
5
+
6
+ self.acts_as_paranoid
7
+
8
+ self.acts_as_tiny_cached
9
+
10
+ attr_accessible :name, :space, :permalink, :instroduction,
11
+ :description, :short_name
12
+
13
+ self.loyal_core_acts_as_tree
14
+
15
+ # 去空格
16
+ self.strip_whitespace_before_validation :name, :short_name, :space, :permalink
17
+
18
+ # 校验
19
+ validates :name, :short_name, :presence => true
20
+
21
+ self.loyal_core_acts_as_has_permalink :with_space => true
22
+
23
+ has_many :recipes, :class_name => '::LoyalCore::Skin::Recipe'
24
+
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ class Skin::Recipe < ActiveRecord::Base
4
+ attr_accessible :stylesheet_text, :assets_path, :folder_id,
5
+ :name, :short_name, :instroduction, :description,
6
+ :stored_tags, :avatar
7
+
8
+ scope :with_folder, ->(options={}) {
9
+ folder = ::LoyalCore::Skin::Folder.tiny_cache_find_by :space => options[:space], :permalink => options[:permalink]
10
+
11
+ if folder
12
+ where(:folder_id => folder.id)
13
+ else
14
+ where(:id => nil)
15
+ end
16
+ }
17
+
18
+ belongs_to :folder, :class_name => "::LoyalCore::Skin::Folder"
19
+
20
+ validates_presence_of :name
21
+
22
+ # 用于作者
23
+ self.loyal_passport_acts_as_creator_able
24
+
25
+ self.loyal_core_acts_as_has_avatar
26
+
27
+ # 去空格
28
+ self.strip_whitespace_before_validation :assets_path
29
+
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module LoyalCore
3
+ module Skin
4
+ def self.table_name_prefix
5
+ 'loyal_core_skin_'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,128 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module LoyalCore
4
+ class AssetUploader < ::CarrierWave::Uploader::Base
5
+ LOYAL_CORE_UPLOADER_IMAGE_EXT = %w[gif jpg jpeg png bmp]
6
+
7
+ LOYAL_CORE_UPLOADER_FLASH_EXT = %w[swf flv]
8
+
9
+ LOYAL_CORE_UPLOADER_MEDIA_EXT = %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb]
10
+
11
+ LOYAL_CORE_UPLOADER_FILE_EXT = %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]
12
+
13
+ # Include RMagick or MiniMagick support:
14
+ # include CarrierWave::RMagick
15
+ # include CarrierWave::MiniMagick
16
+
17
+ # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
18
+ # include Sprockets::Helpers::RailsHelper
19
+ # include Sprockets::Helpers::IsolatedHelper
20
+
21
+ # Choose what kind of storage to use for this uploader:
22
+ storage :file
23
+ # storage :fog
24
+
25
+ # Override the directory where uploaded files will be stored.
26
+ # This is a sensible default for uploaders that are meant to be mounted:
27
+ # def store_dir
28
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
29
+ # end
30
+
31
+ def store_dir
32
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model_id_partition}"
33
+ "uploads/first/#{impl_model_name_underscore}/#{mounted_as}/#{impl_integer_partition(model.created_at.to_i)}"
34
+ end
35
+
36
+ def model_id_partition
37
+ impl_integer_partition(model.id)
38
+ end
39
+
40
+ # Provide a default URL as a default if there hasn't been a file uploaded:
41
+ # def default_url
42
+ # # For Rails 3.1+ asset pipeline compatibility:
43
+ # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
44
+ #
45
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
46
+ # end
47
+
48
+ def default_url *args
49
+ if (version = args.first) && version.respond_to?(:to_sym)
50
+ raise ArgumentError, "Version #{version} doesn't exist!" if versions[version.to_sym].nil?
51
+ # recursively proxy to version
52
+ versions[version.to_sym].default_url(*args[1..-1])
53
+ else
54
+ ::ActionController::Base.helpers.asset_path(
55
+ "loyal_core/fallbacks/#{impl_model_name_underscore}/#{mounted_as}/" + [version_name, "missing.gif"].compact.join('_')
56
+ )
57
+ end
58
+
59
+ # For Rails 3.1+ asset pipeline compatibility:
60
+ # "/images/fallbacks/#{impl_model_name_underscore}/#{mounted_as}/" + ["missing.gif", version_name].compact.join('_')
61
+
62
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
63
+ end
64
+
65
+ def url *args
66
+ stored_file_name = model.send(mounted_as)
67
+
68
+ if stored_file_name.present?
69
+ _url = super
70
+
71
+ _url = "#{_url}?#{impl_generate_stmap_version}" unless _url.include?('?')
72
+
73
+ _url
74
+ else
75
+ default_url *args
76
+ end
77
+ end
78
+
79
+ # Process files as they are uploaded:
80
+ # process :scale => [200, 300]
81
+ #
82
+ # def scale(width, height)
83
+ # # do something
84
+ # end
85
+
86
+ # Create different versions of your uploaded files:
87
+ # version :thumb do
88
+ # process :scale => [50, 50]
89
+ # end
90
+
91
+ # Add a white list of extensions which are allowed to be uploaded.
92
+ # For images you might use something like this:
93
+ # def extension_white_list
94
+ # %w(jpg jpeg gif png)
95
+ # end
96
+
97
+ # Override the filename of the uploaded files:
98
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
99
+ # def filename
100
+ # "something.jpg" if original_filename
101
+ # end
102
+
103
+ def filename
104
+ if file
105
+ "#{Digest::MD5.hexdigest(impl_model_hash_data)}.#{file.extension}"
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def impl_generate_stmap_version
112
+ "#{model.updated_at.to_i}"
113
+ end
114
+
115
+ def impl_model_name_underscore
116
+ model.class.to_s.underscore
117
+ end
118
+
119
+ def impl_model_hash_data
120
+ "#{model.class.to_s}-#{model.id}-#{model.created_at.to_i}-ruby800.com-happy-&&-nice"
121
+ end
122
+
123
+ # e.g.: 1234 => "000/000/000/000/001/234"
124
+ def impl_integer_partition number
125
+ ("%018d" % number).scan(/\d{3}/).join("/")
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module LoyalCore
4
+ class AvatarUploader < ::LoyalCore::AssetUploader
5
+ include ::CarrierWave::MiniMagick
6
+
7
+ # 只能上传图片
8
+ def extension_white_list
9
+ LOYAL_CORE_UPLOADER_IMAGE_EXT
10
+ end
11
+
12
+ version :medium do
13
+ process :resize_to_fill => [360, 360]
14
+ end
15
+
16
+ version :small do
17
+ process :resize_to_fill => [180, 180]
18
+ end
19
+
20
+ version :thumb do
21
+ process :resize_to_fill => [100, 100]
22
+ end
23
+
24
+ version :mini do
25
+ process :resize_to_fill => [50, 50]
26
+ end
27
+
28
+ version :tiny do
29
+ process :resize_to_fill => [32, 32]
30
+ end
31
+
32
+ version :ico do
33
+ process :resize_to_fill => [16, 16]
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>LoyalCore</title>
5
+ <%= stylesheet_link_tag "loyal_core/application", :media => "all" %>
6
+ <%= javascript_include_tag "loyal_core/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,9 @@
1
+ <%= f.nested_parent_select :parent_id, nil %>
2
+ <%= f.text_field :name %>
3
+ <%= f.text_field :short_name %>
4
+ <%= f.text_field :space %>
5
+ <%= f.text_field :permalink %>
6
+ <%= f.text_area :instroduction, :style => "height: 50px;" %>
7
+ <%= f.text_area :description, :style => "height: 100px;" %>
8
+ <%= f.submit %>
9
+
@@ -0,0 +1,11 @@
1
+ <%= form_for(
2
+ @loyal_core_skin_folder,
3
+ :url => loyal_core_app.admin_skin_folder_url(:id => @loyal_core_skin_folder.id),
4
+ :builder => ::LoyalCore::ActionView::LabeledBuilder,
5
+ :as => :loyal_core_skin_folder
6
+ ) do |f| %>
7
+ <%= render :partial => 'form', :locals => { :f => f } %>
8
+ <% end %>
9
+
10
+ <%= link_to "新建", loyal_core_app.new_admin_skin_folder_url %>
11
+
@@ -0,0 +1,25 @@
1
+ <h1>皮肤分类列表</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>
6
+ ID
7
+ </th>
8
+ <th>名称</th>
9
+ <th col='3'>操作</th>
10
+ </tr>
11
+ <% ::LoyalCore::Skin::Folder.nested_set_options do |folder| %>
12
+ <tr>
13
+ <td><%= folder.id %></td>
14
+ <td><%= link_to "#{'- ' * folder.level} #{folder.name}", loyal_core_app.admin_skin_folder_url(
15
+ :id => folder.id
16
+ ) %></td>
17
+ <td>
18
+ <%= link_to "编辑", loyal_core_app.edit_admin_skin_folder_url(:id => folder.id) %>
19
+ <%= link_to "删除", loyal_core_app.admin_skin_folder_url(:id => folder.id), :method => :delete, :confirm => '确定要删除吗?' %>
20
+ </td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <%= link_to "新建", loyal_core_app.new_admin_skin_folder_url %>
@@ -0,0 +1,11 @@
1
+ <h1>新建新分区</h1>
2
+
3
+ <%= form_for(
4
+ @loyal_core_skin_folder,
5
+ :url => loyal_core_app.admin_skin_folders_url,
6
+ :builder => ::LoyalCore::ActionView::LabeledBuilder,
7
+ :as => :loyal_core_skin_folder
8
+ ) do |f| %>
9
+ <%= render :partial => 'form', :locals => { :f => f } %>
10
+ <% end %>
11
+
@@ -0,0 +1,32 @@
1
+ <h1>【皮肤分类】 <%= @loyal_core_skin_folder.name %></h1>
2
+
3
+ <div>
4
+ <b>短标题</b><%= @loyal_core_skin_folder.short_name %><br/>
5
+ <b>简介</b><%= @loyal_core_skin_folder.instroduction %><br/>
6
+ <b>描述</b><%= @loyal_core_skin_folder.description %><br/>
7
+ </div>
8
+
9
+
10
+ <%= link_to "编辑", loyal_core_app.edit_admin_skin_folder_url(:id => @loyal_core_skin_folder.id) %>
11
+ <%= link_to "返回列表", loyal_core_app.admin_skin_folders_url %>
12
+
13
+ <div>
14
+ <h3>皮肤</h3>
15
+ <%= paginate @loyal_core_skin_recipes %>
16
+
17
+ <ul>
18
+ <% @loyal_core_skin_recipes.each do |recipe| %>
19
+ <li>
20
+ <%= link_to "#{recipe.name}", loyal_core_app.admin_skin_recipe_url(
21
+ :id => recipe.id
22
+ ) %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
26
+
27
+ <% if @loyal_core_skin_recipes.empty? %>
28
+ 为空
29
+ <% end %>
30
+
31
+ <%= paginate @loyal_core_skin_recipes %>
32
+ </div>
@@ -0,0 +1,25 @@
1
+ <%= f.text_field :name %>
2
+ <%= f.text_field :short_name %>
3
+ <%= f.text_field :stored_tags %>
4
+
5
+ <p>
6
+ <%= f.label :avatar %>
7
+ <%= image_tag(f.object.avatar_url :small) if f.object.avatar? %>
8
+ <%= f.file_field :avatar %>
9
+ <%= f.hidden_field :avatar_cache %>
10
+ </p>
11
+
12
+ <%= f.nested_belongs_to_select :folder_id,
13
+ ::LoyalCore::Skin::Folder,
14
+ ::LoyalCore::Skin::Folder
15
+ %>
16
+
17
+ <%= f.text_field :assets_path %>
18
+
19
+ <%= f.text_area :stylesheet_text, :style => 'height: 500px;' %>
20
+
21
+ <%= f.text_area :instroduction, :style => 'height: 100px;' %>
22
+ <%= f.text_area :description, :style => 'height: 100px;' %>
23
+
24
+ <%= f.submit %>
25
+
@@ -0,0 +1,11 @@
1
+ <%= form_for(
2
+ @loyal_core_skin_recipe,
3
+ :url => loyal_core_app.admin_skin_recipe_url(:id => @loyal_core_skin_recipe.id),
4
+ :builder => ::LoyalCore::ActionView::LabeledBuilder,
5
+ :as => :loyal_core_skin_recipe
6
+ ) do |f| %>
7
+ <%= render :partial => 'form', :locals => { :f => f } %>
8
+ <% end %>
9
+
10
+ <%= link_to "新建", loyal_core_app.new_admin_skin_recipe_url %>
11
+