adva-markup 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/content_slice.rb +9 -0
- data/app/models/section_slice.rb +6 -0
- data/app/views/admin/blogs/_form_slice.html.rb +14 -0
- data/app/views/admin/posts/_form_slice.html.rb +10 -0
- data/config/locales/en.yml +2 -0
- data/config/redirects.rb +3 -0
- data/config/routes.rb +3 -0
- data/lib/adva-markup.rb +1 -0
- data/lib/adva/markup.rb +48 -0
- data/lib/adva/markup/action_controller.rb +38 -0
- data/lib/adva/markup/active_record.rb +47 -0
- data/lib/adva_markup/version.rb +3 -0
- metadata +16 -5
- data/lib/bundler/repository.rb +0 -118
@@ -0,0 +1,14 @@
|
|
1
|
+
require_dependency 'admin/blogs/_form.html'
|
2
|
+
|
3
|
+
Admin::Blogs::Form.class_eval do
|
4
|
+
include do
|
5
|
+
def fields
|
6
|
+
super
|
7
|
+
fieldset do
|
8
|
+
column do
|
9
|
+
form.input :default_filter, :as => :select, :collection => Adva::Markup.options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/config/redirects.rb
ADDED
data/config/routes.rb
ADDED
data/lib/adva-markup.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'adva/markup'
|
data/lib/adva/markup.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'adva/core'
|
2
|
+
require 'RedCloth'
|
3
|
+
require 'rdiscount'
|
4
|
+
|
5
|
+
ERB::Util.send(:undef_method, :t) # wtf, redcloth!
|
6
|
+
|
7
|
+
module Adva
|
8
|
+
class Markup < ::Rails::Engine
|
9
|
+
include Adva::Engine
|
10
|
+
|
11
|
+
autoload :ActionController, 'adva/markup/action_controller'
|
12
|
+
autoload :ActiveRecord, 'adva/markup/active_record'
|
13
|
+
|
14
|
+
mattr_accessor :filters
|
15
|
+
self.filters = {
|
16
|
+
:markdown => 'RDiscount',
|
17
|
+
:textile => 'RedCloth'
|
18
|
+
}
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def apply(name, markup)
|
22
|
+
if filter = self.filter(name)
|
23
|
+
filter.new(markup).to_html
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def filter(name)
|
28
|
+
filters[name.to_sym].constantize if name.present? && filters[name.to_sym]
|
29
|
+
end
|
30
|
+
|
31
|
+
def keys
|
32
|
+
@keys ||= filters.keys.map(&:to_s).sort
|
33
|
+
end
|
34
|
+
|
35
|
+
def names
|
36
|
+
@names ||= keys.map { |key| key.titleize }
|
37
|
+
end
|
38
|
+
|
39
|
+
def options
|
40
|
+
@options ||= Hash[*names.zip(keys).flatten]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ActionController::Base.extend(Adva::Markup::ActionController::ActMacro)
|
47
|
+
ActiveRecord::Base.extend(Adva::Markup::ActiveRecord::ActMacro)
|
48
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Adva
|
2
|
+
class Markup
|
3
|
+
module ActionController
|
4
|
+
module ActMacro
|
5
|
+
def filtered_attributes(*models)
|
6
|
+
options = models.extract_options!
|
7
|
+
options[:models] = models.map(&:to_s).map(&:camelize)
|
8
|
+
options[:only] = Array(options[:only]).map(&:to_sym)
|
9
|
+
options[:except] = Array(options[:except]).map(&:to_sym)
|
10
|
+
|
11
|
+
class_inheritable_accessor :filtered_attribute_options
|
12
|
+
self.filtered_attribute_options = options
|
13
|
+
|
14
|
+
include InstanceMethods
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
def render(*args)
|
20
|
+
options = filtered_attribute_options
|
21
|
+
excluded = options[:except].include?(params[:action].to_sym)
|
22
|
+
included = options[:only].empty? || options[:only].include?(params[:action].to_sym)
|
23
|
+
|
24
|
+
!excluded && included ? with_filtered_attributes { super } : super
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_filtered_attributes
|
28
|
+
models = filtered_attribute_options[:models].map(&:constantize)
|
29
|
+
models.each { |model| model.read_filtered_attributes = true }
|
30
|
+
yield.tap do
|
31
|
+
models.each { |model| model.read_filtered_attributes = false }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Adva
|
2
|
+
class Markup
|
3
|
+
module ActiveRecord
|
4
|
+
module ActMacro
|
5
|
+
def filters(*attributes)
|
6
|
+
unless filters?
|
7
|
+
class_inheritable_accessor :filtered_attributes
|
8
|
+
class_inheritable_accessor :read_filtered_attributes
|
9
|
+
|
10
|
+
self.filtered_attributes = []
|
11
|
+
self.read_filtered_attributes = false
|
12
|
+
|
13
|
+
before_save :filter_attributes!
|
14
|
+
include InstanceMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
self.filtered_attributes += attributes
|
18
|
+
include attribute_readers_module(attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def attribute_readers_module(attributes)
|
22
|
+
Module.new.tap do |readers|
|
23
|
+
attributes.each do |name|
|
24
|
+
readers.module_eval <<-rb
|
25
|
+
def #{name}; read_filtered_attributes ? send(:#{name}_html) : super; end
|
26
|
+
rb
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def filters?
|
32
|
+
included_modules.include?(InstanceMethods)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module InstanceMethods
|
37
|
+
def filter_attributes!
|
38
|
+
filtered_attributes.each do |name|
|
39
|
+
value = self.send(name)
|
40
|
+
value = Adva::Markup.apply(filter, value) if respond_to?(:filter) && filter
|
41
|
+
write_attribute(:"#{name}_html", value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adva-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-03 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -69,7 +69,18 @@ extensions: []
|
|
69
69
|
extra_rdoc_files: []
|
70
70
|
|
71
71
|
files:
|
72
|
-
-
|
72
|
+
- app/views/admin/blogs/_form_slice.html.rb
|
73
|
+
- app/views/admin/posts/_form_slice.html.rb
|
74
|
+
- app/models/content_slice.rb
|
75
|
+
- app/models/section_slice.rb
|
76
|
+
- config/redirects.rb
|
77
|
+
- config/routes.rb
|
78
|
+
- config/locales/en.yml
|
79
|
+
- lib/adva_markup/version.rb
|
80
|
+
- lib/adva/markup.rb
|
81
|
+
- lib/adva/markup/action_controller.rb
|
82
|
+
- lib/adva/markup/active_record.rb
|
83
|
+
- lib/adva-markup.rb
|
73
84
|
has_rdoc: true
|
74
85
|
homepage: http://github.com/svenfuchs/adva-cms2
|
75
86
|
licenses: []
|
data/lib/bundler/repository.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
# Bundler gemfile support for local/remote workspaces/repositories for work in
|
4
|
-
# development teams.
|
5
|
-
#
|
6
|
-
# Usage:
|
7
|
-
#
|
8
|
-
# # define paths to be searched for repositories:
|
9
|
-
# workspace '~/.projects ~/Development/{projects,work}'
|
10
|
-
#
|
11
|
-
# # define developer preferences for using local or remote repositories (uses ENV['user']):
|
12
|
-
# developer :sven, :prefer => :local
|
13
|
-
#
|
14
|
-
# # define repositories to be used for particular gems:
|
15
|
-
# adva_cms = repository('adva-cms2', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de')
|
16
|
-
# adva_shop = repository('adva-shop', :source => :local)
|
17
|
-
#
|
18
|
-
# # now use repositories to define gems:
|
19
|
-
# adva_cms.gem 'adva-core'
|
20
|
-
# adva_shop.gem 'adva-catalog'
|
21
|
-
#
|
22
|
-
# # The gem definition will now be proxied to Bundler with arguments according
|
23
|
-
# # to the setup defined earlier. E.g. as:
|
24
|
-
#
|
25
|
-
# gem 'adva-core', :path => 'Development/projects/adva-cms2/adva-core' # for developer 'sven'
|
26
|
-
# gem 'adva-core', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de' # for other developers
|
27
|
-
# gem 'adva-catalog', :path => 'Development/projects/adva-shop/adva-catalog' # for all developers
|
28
|
-
#
|
29
|
-
# One can also set an environment variable FORCE_REMOTE which will force remote
|
30
|
-
# repositories to be used *except* when a repository was defined with :source => :local
|
31
|
-
# which always forces the local repository to be used.
|
32
|
-
#
|
33
|
-
class Repository
|
34
|
-
class << self
|
35
|
-
def paths
|
36
|
-
@paths ||= []
|
37
|
-
end
|
38
|
-
|
39
|
-
def path(*paths)
|
40
|
-
paths.join(' ').split(' ').each do |path|
|
41
|
-
self.paths.concat(Pathname.glob(File.expand_path(path)))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def developer(name, preferences)
|
46
|
-
developers[name] = preferences
|
47
|
-
workspaces(preferences[:workspace])
|
48
|
-
end
|
49
|
-
|
50
|
-
def current_developer
|
51
|
-
developers[ENV['USER'].to_sym] || {}
|
52
|
-
end
|
53
|
-
|
54
|
-
def developers(developers = nil)
|
55
|
-
@developers ||= {}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class Gem < Array
|
60
|
-
def initialize(name, repository)
|
61
|
-
if repository.local?
|
62
|
-
sub_path = repository.path.join(name)
|
63
|
-
super([name, { :path => sub_path.exist? ? sub_path.to_s : repository.path.to_s }])
|
64
|
-
else
|
65
|
-
super([name, repository.options.dup])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
attr_reader :bundler, :name, :options, :source
|
71
|
-
|
72
|
-
def initialize(bundler, name, options)
|
73
|
-
@bundler = bundler
|
74
|
-
@name = name
|
75
|
-
@source = options.delete(:source)
|
76
|
-
@options = options
|
77
|
-
end
|
78
|
-
|
79
|
-
def gem(name)
|
80
|
-
bundler.gem(*Gem.new(name, self))
|
81
|
-
end
|
82
|
-
|
83
|
-
def local?
|
84
|
-
source == :local # && path
|
85
|
-
end
|
86
|
-
|
87
|
-
def source
|
88
|
-
@source ||= forced_source || preferred_source || :remote
|
89
|
-
end
|
90
|
-
|
91
|
-
def forced_source
|
92
|
-
:remote if ENV['FORCE_REMOTE']
|
93
|
-
end
|
94
|
-
|
95
|
-
def preferred_source
|
96
|
-
self.class.current_developer[:prefer] || self.class.current_developer[name.to_sym]
|
97
|
-
end
|
98
|
-
|
99
|
-
def path
|
100
|
-
@path ||= begin
|
101
|
-
path = self.class.paths.detect { |path| path.join(name).exist? }
|
102
|
-
path ? path.join(name) : Pathname.new('.')
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def workspace(*paths)
|
108
|
-
Repository.path(*paths)
|
109
|
-
end
|
110
|
-
alias :workspaces :workspace
|
111
|
-
|
112
|
-
def developer(name, preferences)
|
113
|
-
Repository.developer(name, preferences)
|
114
|
-
end
|
115
|
-
|
116
|
-
def repository(*args)
|
117
|
-
Repository.new(self, *args)
|
118
|
-
end
|