loyal_core 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/loyal_core/action_helper.rb +12 -1
- data/lib/loyal_core/action_view/labeled_builder.rb +7 -1
- data/lib/loyal_core/acts.rb +3 -0
- data/lib/loyal_core/acts/content_depart_able.rb +1 -1
- data/lib/loyal_core/acts/publish_status_able.rb +75 -0
- data/lib/loyal_core/utils/config_util.rb +5 -80
- data/lib/loyal_core/utils/text_util.rb +5 -5
- data/lib/loyal_core/version.rb +1 -1
- metadata +5 -4
@@ -9,8 +9,19 @@ module LoyalCore
|
|
9
9
|
include ::LoyalCore::Ajax::LikeTracksHelper
|
10
10
|
include ::LoyalCore::FontSelectorHelper
|
11
11
|
|
12
|
-
|
12
|
+
def link_to_loyal_current yes_no, name, url, options={}
|
13
|
+
current_options = options.dup
|
14
|
+
current_options[:class] ||= ""
|
13
15
|
|
16
|
+
unless current_options[:class].include?('current')
|
17
|
+
current_options[:class] << ' ' if current_options[:class].present?
|
18
|
+
current_options[:class] << 'current'
|
19
|
+
end
|
20
|
+
|
21
|
+
link_to_if yes_no, name, url, current_options do
|
22
|
+
link_to name, url, options
|
23
|
+
end
|
24
|
+
end
|
14
25
|
|
15
26
|
def render_new_simple_captcha_partial options={}
|
16
27
|
render :partial => '/loyal_core/ajax/captchas/new', :locals => {
|
@@ -13,7 +13,7 @@ module LoyalCore::ActionView
|
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
16
|
-
%w[kindeditor url_field text_field text_area password_field collection_select].each do |method_name|
|
16
|
+
%w[kindeditor number_field url_field text_field text_area password_field collection_select].each do |method_name|
|
17
17
|
define_method method_name do |name, *args|
|
18
18
|
@template.content_tag :div, class: "field" do
|
19
19
|
(field_label name, *args) + @template.tag(:br) + super(name, *args)
|
@@ -72,6 +72,12 @@ module LoyalCore::ActionView
|
|
72
72
|
)
|
73
73
|
end
|
74
74
|
|
75
|
+
def labeled_check_box(name, *args)
|
76
|
+
@template.content_tag :div, class: 'field' do
|
77
|
+
check_box(name, *args) + ' ' + field_label(name, *args)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
75
81
|
# def check_box(name, *args)
|
76
82
|
# @template.content_tag :div, class: 'field' do
|
77
83
|
# super + ' ' + field_label(name, *args)
|
data/lib/loyal_core/acts.rb
CHANGED
@@ -17,6 +17,8 @@ module LoyalCore
|
|
17
17
|
autoload :ActsAsSkinDishAble, "#{File.dirname(__FILE__)}/acts/skin_dish_able"
|
18
18
|
|
19
19
|
autoload :ActsAsCreatorAble, "#{File.dirname(__FILE__)}/acts/creator_able"
|
20
|
+
|
21
|
+
autoload :ActsAsPublishStatusAble, "#{File.dirname(__FILE__)}/acts/publish_status_able"
|
20
22
|
end
|
21
23
|
|
22
24
|
if defined?(ActiveRecord::Base)
|
@@ -36,4 +38,5 @@ if defined?(ActiveRecord::Base)
|
|
36
38
|
::ActiveRecord::Base.send :include, ::LoyalCore::ActsAsSkinDishAble
|
37
39
|
|
38
40
|
::ActiveRecord::Base.send :include, ::LoyalCore::ActsAsCreatorAble
|
41
|
+
::ActiveRecord::Base.send :include, ::LoyalCore::ActsAsPublishStatusAble
|
39
42
|
end
|
@@ -50,7 +50,7 @@ module LoyalCore
|
|
50
50
|
worker_class.content_mode_config
|
51
51
|
end
|
52
52
|
|
53
|
-
delegate :
|
53
|
+
delegate :content=, :content, :content_text, :words_amount, :words_amount_more?,
|
54
54
|
:content_code=, :content_code,
|
55
55
|
:content_mode, :content_mode=,
|
56
56
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module LoyalCore
|
3
|
+
# 发布状态相关
|
4
|
+
module ActsAsPublishStatusAble
|
5
|
+
def self.included base
|
6
|
+
base.class_eval do
|
7
|
+
extend ClassMethods
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def loyal_core_acts_as_publish_status_able *args
|
13
|
+
_config = ::LoyalCore::ConfigUtil.new(
|
14
|
+
{:key => 'init', :value => 0, :desc => '初始'},
|
15
|
+
{:key => 'published', :value => 2**1, :desc => '已发布'},
|
16
|
+
{:key => 'blocked', :value => 2**2, :desc => '已屏蔽'}
|
17
|
+
)
|
18
|
+
|
19
|
+
define_singleton_method :publish_status_config do
|
20
|
+
_config
|
21
|
+
end
|
22
|
+
|
23
|
+
_config.pure_keys.each do |key, config|
|
24
|
+
define_method :"publish_status_#{key}?" do
|
25
|
+
self.publish_status_key == key
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
scope :of_publish_status, ->(status_name) do
|
30
|
+
if status_name
|
31
|
+
status_name = status_name.to_s unless status_name.is_a?(String)
|
32
|
+
config = _config.at(status_name)
|
33
|
+
status = config.nil? ? nil : config.value
|
34
|
+
|
35
|
+
where(:publish_status => status)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
scope :published, -> do
|
40
|
+
of_publish_status('published')
|
41
|
+
end
|
42
|
+
|
43
|
+
include InstanceMethods
|
44
|
+
end
|
45
|
+
|
46
|
+
module InstanceMethods
|
47
|
+
|
48
|
+
def publish_status_config
|
49
|
+
self.class.publish_status_config.item(self.publish_status)
|
50
|
+
end
|
51
|
+
|
52
|
+
def publish_status_key
|
53
|
+
self.publish_status_config.key if self.publish_status_config
|
54
|
+
end
|
55
|
+
|
56
|
+
def publish_status_name
|
57
|
+
self.publish_status_key
|
58
|
+
end
|
59
|
+
|
60
|
+
def publish_status_name= name
|
61
|
+
config = self.class.publish_status_config.at(name)
|
62
|
+
|
63
|
+
if config
|
64
|
+
self.publish_status = config.value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def publish_status_desc
|
69
|
+
self.publish_status_config.desc if self.publish_status_config
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module LoyalCore
|
3
3
|
class ConfigUtil
|
4
|
-
attr_reader :config_values_map, :
|
5
|
-
:default_item
|
4
|
+
attr_reader :config_values_map, :select_options,
|
5
|
+
:default_item, :config_keys_map, :pure_keys, :pure_values
|
6
6
|
|
7
7
|
# config*
|
8
8
|
# [
|
@@ -29,6 +29,9 @@ module LoyalCore
|
|
29
29
|
|
30
30
|
impl_collect_item args
|
31
31
|
|
32
|
+
@pure_values = @config_values_map.keys.freeze
|
33
|
+
@pure_keys = @config_keys_map.keys.freeze
|
34
|
+
|
32
35
|
@config_values_map.freeze
|
33
36
|
@config_keys_map.freeze
|
34
37
|
@select_options.freeze
|
@@ -106,81 +109,3 @@ module LoyalCore
|
|
106
109
|
end
|
107
110
|
end
|
108
111
|
|
109
|
-
# module LoyalCore
|
110
|
-
# # 配置工具类
|
111
|
-
# class ConfigUtil < ::Hash
|
112
|
-
# attr_reader :config_values_map, :pure_values
|
113
|
-
#
|
114
|
-
# #
|
115
|
-
# # configs:
|
116
|
-
# # {
|
117
|
-
# # :john => { :value => 1, :desc => '约翰' },
|
118
|
-
# # :liming => { :value => 2, :desc => '黎明' },
|
119
|
-
# # :have => {
|
120
|
-
# # :book => {
|
121
|
-
# # :value => 3, :desc => ''
|
122
|
-
# # }
|
123
|
-
# # }
|
124
|
-
# # ...
|
125
|
-
# # }
|
126
|
-
# def initialize(*args)
|
127
|
-
# configs = args.extract_options!
|
128
|
-
# @default_key = args.first
|
129
|
-
# @config_values_map = {}
|
130
|
-
#
|
131
|
-
# configs.each do |key, item|
|
132
|
-
# self[key] = ConfigUtilItem.new(item.merge(:key => key))
|
133
|
-
# @config_values_map[self[key].value] = self[key]
|
134
|
-
# end
|
135
|
-
#
|
136
|
-
# @config_values_map.freeze
|
137
|
-
# @pure_values = @config_values_map.keys.freeze
|
138
|
-
#
|
139
|
-
# @select_options = (
|
140
|
-
# self.values.map do |item|
|
141
|
-
# [item.desc, item.value]
|
142
|
-
# end
|
143
|
-
# ).freeze
|
144
|
-
#
|
145
|
-
# self.freeze
|
146
|
-
# end
|
147
|
-
#
|
148
|
-
# def at(key)
|
149
|
-
# self[key]
|
150
|
-
# end
|
151
|
-
#
|
152
|
-
# def item(value)
|
153
|
-
# @config_values_map[value] || ( self[@default_key] unless @default_key.nil? )
|
154
|
-
# end
|
155
|
-
#
|
156
|
-
# # options:
|
157
|
-
# # - include_blank:
|
158
|
-
# def select_options options={}
|
159
|
-
# result = @select_options.dup
|
160
|
-
#
|
161
|
-
# if options.key?(:include_blank)
|
162
|
-
# if options[:include_blank].is_a?(::Hash)
|
163
|
-
# result.insert(0, [options[:include_blank][:desc] || '- - 请选择 - -', options[:include_blank][:value].to_i])
|
164
|
-
# elsif options[:include_blank]
|
165
|
-
# result.insert(0, ['- - 请选择 - -', 0])
|
166
|
-
# end
|
167
|
-
# end
|
168
|
-
#
|
169
|
-
# result
|
170
|
-
# end
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# class ConfigUtilItem
|
174
|
-
# def initialize(item={})
|
175
|
-
# @item = item || {}
|
176
|
-
# end
|
177
|
-
#
|
178
|
-
# def [] key
|
179
|
-
# @item[key]
|
180
|
-
# end
|
181
|
-
#
|
182
|
-
# def method_missing(method_name, *args, &block)
|
183
|
-
# @item[method_name.to_sym]
|
184
|
-
# end
|
185
|
-
# end
|
186
|
-
# end
|
@@ -15,7 +15,7 @@ module LoyalCore
|
|
15
15
|
doc.search("//pre").each do |pre|
|
16
16
|
lang = pre.attr('lang')
|
17
17
|
|
18
|
-
if lang
|
18
|
+
if lang
|
19
19
|
_lang_class = pre.attr('class').to_s.split(' ').select {|_itm| _itm.include?('lang-') }.first
|
20
20
|
|
21
21
|
if _lang_class
|
@@ -24,11 +24,11 @@ module LoyalCore
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# debugger
|
27
|
-
if
|
27
|
+
if pre_code=pre.css('code')
|
28
28
|
lang = pre_code.attr('class').to_s
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
unless lang
|
32
32
|
lang = :text
|
33
33
|
end
|
34
34
|
|
@@ -37,11 +37,11 @@ module LoyalCore
|
|
37
37
|
begin
|
38
38
|
pre.replace ::CodeRay.scan(text, lang).div.to_s
|
39
39
|
rescue Exception => error
|
40
|
-
|
40
|
+
puts "#{__FILE__} syntax_highlighter error: \ntext => #{text} \nlang => #{lang}\n origin error:#{error}"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
doc.css('body').
|
44
|
+
doc.css('body').inner_html.to_s
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/loyal_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loyal_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: protected_attributes
|
@@ -496,6 +496,7 @@ files:
|
|
496
496
|
- lib/loyal_core/acts/creator_able.rb
|
497
497
|
- lib/loyal_core/acts/bit_able.rb
|
498
498
|
- lib/loyal_core/acts/uuid_ful.rb
|
499
|
+
- lib/loyal_core/acts/publish_status_able.rb
|
499
500
|
- lib/loyal_core/acts/skin_dish_able.rb
|
500
501
|
- lib/loyal_core/acts/like_track_able.rb
|
501
502
|
- lib/loyal_core/acts/tree.rb
|
@@ -529,7 +530,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
529
530
|
version: '0'
|
530
531
|
segments:
|
531
532
|
- 0
|
532
|
-
hash: -
|
533
|
+
hash: -2891372383451455765
|
533
534
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
534
535
|
none: false
|
535
536
|
requirements:
|
@@ -538,7 +539,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
538
539
|
version: '0'
|
539
540
|
segments:
|
540
541
|
- 0
|
541
|
-
hash: -
|
542
|
+
hash: -2891372383451455765
|
542
543
|
requirements: []
|
543
544
|
rubyforge_project:
|
544
545
|
rubygems_version: 1.8.25
|