bhf 0.7.16 → 0.8.0
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.
- checksums.yaml +4 -4
- data/Gemfile +16 -0
- data/Gemfile.lock +170 -0
- data/LICENSE.txt +20 -0
- data/README.md +18 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/app/assets/javascripts/bhf/application.js +41 -30
- data/app/assets/stylesheets/bhf/application.css.sass +19 -5
- data/app/controllers/bhf/application_controller.rb +7 -11
- data/app/controllers/bhf/embed_entries_controller.rb +16 -5
- data/app/controllers/bhf/entries_controller.rb +23 -5
- data/app/controllers/bhf/pages_controller.rb +4 -4
- data/app/helpers/bhf/frontend_helper.rb +1 -1
- data/app/views/bhf/_user.haml +2 -2
- data/app/views/bhf/application/index.haml +1 -1
- data/app/views/bhf/entries/_form.haml +7 -1
- data/app/views/bhf/entries/form/embeds_many/_static.haml +3 -3
- data/app/views/bhf/entries/form/embeds_one/_static.haml +3 -3
- data/app/views/bhf/entries/form/has_many/_static.haml +5 -2
- data/app/views/bhf/entries/form/has_one/_static.haml +1 -1
- data/app/views/bhf/pages/_platform.haml +5 -2
- data/app/views/bhf/pages/macro/column/_boolean.haml +1 -1
- data/app/views/layouts/bhf/application.haml +7 -5
- data/bhf.gemspec +200 -0
- data/config/locales/de.yml +8 -3
- data/config/locales/en.yml +8 -3
- data/lib/bhf.rb +23 -13
- data/lib/bhf/data.rb +2 -2
- data/lib/bhf/form.rb +5 -4
- data/lib/bhf/mongoid/document.rb +1 -2
- data/lib/bhf/platform.rb +40 -31
- data/lib/bhf/settings.rb +5 -4
- data/lib/bhf/{config_parser.rb → settings_parser.rb} +4 -4
- data/lib/rails/generators/bhf/templates/initializer.rb +12 -16
- data/test/database.yml +9 -0
- data/test/test_helper.rb +55 -0
- metadata +86 -7
data/config/locales/de.yml
CHANGED
@@ -2,9 +2,14 @@ de:
|
|
2
2
|
bhf:
|
3
3
|
helpers:
|
4
4
|
boolean:
|
5
|
-
|
6
|
-
|
5
|
+
'true': 'ja'
|
6
|
+
'false': 'nein'
|
7
7
|
link: Link ⬀
|
8
|
+
form:
|
9
|
+
buttons:
|
10
|
+
save: '%{platform_name} speichern'
|
11
|
+
and_edit: und editieren
|
12
|
+
and_add: und anlegen
|
8
13
|
searchform:
|
9
14
|
placeholder: Suche
|
10
15
|
promts:
|
@@ -60,7 +65,7 @@ de:
|
|
60
65
|
footer:
|
61
66
|
state: 'Seite wurde in ~%{time} Sekunden erstellt'
|
62
67
|
copy: 'Gemacht von <a href="http://twitter.com/antpaw">@antpaw</a> mit <a href="http://rubyonrails.org">Rails</a> und <a href="http://mootools.net">MooTools</a>'
|
63
|
-
info: 'Mehr Information auf <a href="http://github.
|
68
|
+
info: 'Mehr Information auf <a href="http://antpaw.github.io/bhf">GitHub</a>'
|
64
69
|
|
65
70
|
activerecord:
|
66
71
|
notices:
|
data/config/locales/en.yml
CHANGED
@@ -5,9 +5,14 @@ en:
|
|
5
5
|
page_title: "%{area} – %{title} – Admin"
|
6
6
|
helpers:
|
7
7
|
boolean:
|
8
|
-
|
9
|
-
|
8
|
+
'true': 'yes'
|
9
|
+
'false': 'no'
|
10
10
|
link: Link ⬀
|
11
|
+
form:
|
12
|
+
buttons:
|
13
|
+
save: 'Save %{platform_name}'
|
14
|
+
and_edit: and edit
|
15
|
+
and_add: and add another
|
11
16
|
searchform:
|
12
17
|
placeholder: Search
|
13
18
|
promts:
|
@@ -68,7 +73,7 @@ en:
|
|
68
73
|
footer:
|
69
74
|
state: 'Page rendered in ~%{time} seconds'
|
70
75
|
copy: 'Made by <a href="http://twitter.com/antpaw">@antpaw</a> with <a href="http://rubyonrails.org">Rails</a> and <a href="http://mootools.net">MooTools</a>'
|
71
|
-
info: 'More information on <a href="http://github.
|
76
|
+
info: 'More information on <a href="http://http://antpaw.github.io/bhf">GitHub</a>'
|
72
77
|
|
73
78
|
attributes:
|
74
79
|
_id: 'id'
|
data/lib/bhf.rb
CHANGED
@@ -6,29 +6,24 @@ require 'bhf/active_record/active_record'
|
|
6
6
|
require 'bhf/mongoid/document'
|
7
7
|
require 'bhf/data'
|
8
8
|
require 'bhf/platform'
|
9
|
-
require 'bhf/
|
9
|
+
require 'bhf/settings_parser'
|
10
10
|
require 'bhf/settings'
|
11
11
|
require 'bhf/pagination'
|
12
12
|
require 'bhf/form'
|
13
13
|
|
14
14
|
|
15
15
|
module Bhf
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Bhf::Configuration.new
|
18
|
+
end
|
19
|
+
def self.configure
|
20
|
+
yield configuration
|
21
|
+
end
|
22
|
+
|
16
23
|
class Engine < Rails::Engine
|
17
24
|
|
18
25
|
isolate_namespace Bhf
|
19
26
|
|
20
|
-
config.bhf = OpenStruct.new(
|
21
|
-
on_login_fail: :root_url,
|
22
|
-
logout_path: :logout_path,
|
23
|
-
session_auth_name: :is_admin,
|
24
|
-
session_account_id: :admin_account_id,
|
25
|
-
account_model: 'User',
|
26
|
-
account_model_find_method: 'find',
|
27
|
-
css: ['bhf/application'],
|
28
|
-
js: ['bhf/application'],
|
29
|
-
abstract_config: []
|
30
|
-
)
|
31
|
-
|
32
27
|
initializer 'bhf.helper' do
|
33
28
|
ActiveSupport.on_load :action_controller do
|
34
29
|
helper Bhf::FrontendHelper
|
@@ -45,4 +40,19 @@ module Bhf
|
|
45
40
|
end
|
46
41
|
end
|
47
42
|
PAPERCLIP_IMAGE_TYPES = ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/tif', 'image/gif']
|
43
|
+
|
44
|
+
class Configuration
|
45
|
+
include ActiveSupport::Configurable
|
46
|
+
|
47
|
+
config_accessor(:on_login_fail) { :root_url }
|
48
|
+
config_accessor(:logout_path) { :logout_path }
|
49
|
+
config_accessor(:session_auth_name) { :is_admin }
|
50
|
+
config_accessor(:session_account_id) { :admin_account_id }
|
51
|
+
config_accessor(:account_model) { 'User' }
|
52
|
+
config_accessor(:account_model_find_method) { 'find' }
|
53
|
+
config_accessor(:css) { ['bhf/application'] }
|
54
|
+
config_accessor(:js) { ['bhf/application'] }
|
55
|
+
config_accessor(:abstract_config) { [] }
|
56
|
+
end
|
57
|
+
|
48
58
|
end
|
data/lib/bhf/data.rb
CHANGED
@@ -12,7 +12,7 @@ module Bhf
|
|
12
12
|
@overwrite_display_type = props[:display_type]
|
13
13
|
@info = props[:info]
|
14
14
|
@macro = :column
|
15
|
-
@link = props[:link]
|
15
|
+
@link = props[:link] unless props[:link].blank?
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -99,7 +99,7 @@ module Bhf
|
|
99
99
|
def initialize(reflection, options = {})
|
100
100
|
@reflection = reflection
|
101
101
|
@info = options[:info]
|
102
|
-
@link = options[:link]
|
102
|
+
@link = options[:link] unless options[:link].blank?
|
103
103
|
|
104
104
|
@overwrite_type = options[:overwrite_type].to_sym if options[:overwrite_type]
|
105
105
|
@overwrite_display_type = options[:overwrite_display_type].to_sym if options[:overwrite_display_type]
|
data/lib/bhf/form.rb
CHANGED
@@ -18,15 +18,16 @@ module Bhf
|
|
18
18
|
|
19
19
|
def many_to_many_check_box(obj, ref_name, params)
|
20
20
|
mm = :has_and_belongs_to_many
|
21
|
+
id_string = obj.send(obj.class.bhf_primary_key).to_s
|
21
22
|
checked = if params[mm] && params[mm][ref_name]
|
22
|
-
params[mm][ref_name][
|
23
|
+
params[mm][ref_name][id_string] != ''
|
23
24
|
else
|
24
25
|
object.send(ref_name).include?(obj)
|
25
26
|
end
|
26
27
|
|
27
|
-
hidden_field_tag("#{mm}[#{ref_name}][#{
|
28
|
-
check_box_tag("#{mm}[#{ref_name}][#{
|
29
|
-
label_tag("#{mm}_#{ref_name}_#{
|
28
|
+
hidden_field_tag("#{mm}[#{ref_name}][#{id_string}]", '', id: "hidden_#{mm}_#{ref_name}_#{id_string}")+' '+
|
29
|
+
check_box_tag("#{mm}[#{ref_name}][#{id_string}]", id_string, checked)+' '+
|
30
|
+
label_tag("#{mm}_#{ref_name}_#{id_string}", obj.to_bhf_s)
|
30
31
|
end
|
31
32
|
|
32
33
|
end
|
data/lib/bhf/mongoid/document.rb
CHANGED
@@ -9,7 +9,7 @@ module Bhf
|
|
9
9
|
|
10
10
|
def initialize(mongoid_field)
|
11
11
|
@name = mongoid_field.name
|
12
|
-
@type = mongoid_field.type.to_s.downcase.to_sym
|
12
|
+
@type = mongoid_field.type.to_s.downcase.gsub('mongoid::', '').to_sym
|
13
13
|
@type = :primary_key if @type == :'bson::objectid'
|
14
14
|
end
|
15
15
|
end
|
@@ -141,7 +141,6 @@ module Bhf
|
|
141
141
|
|
142
142
|
def bhf_find_embed(parent_id, ref_id)
|
143
143
|
get_embedded_parent parent_id do |parent, meta|
|
144
|
-
# :forced_nil_inverse?, :foreign_key, :foreign_key_check, :foreign_key_setter, :index, :indexed?, :inspect, :inverses, :inverse, :inverse_class_name, :inverse_class_name?, :inverse_foreign_key, :inverse_klass, :inverse_metadata, :inverse_of, :inverse_of?, :inverse_setter, :inverse_type, :inverse_type_setter
|
145
144
|
key_name = if meta.inverse_of?
|
146
145
|
meta.inverse_of
|
147
146
|
else
|
data/lib/bhf/platform.rb
CHANGED
@@ -4,7 +4,7 @@ module Bhf
|
|
4
4
|
attr_accessor :pagination
|
5
5
|
attr_reader :name, :objects, :page_name, :title, :title_zero, :title_singular
|
6
6
|
|
7
|
-
def initialize(options, page_name, user = nil)
|
7
|
+
def initialize(options, page_name, config, user = nil)
|
8
8
|
@objects = []
|
9
9
|
|
10
10
|
if options.is_a?(String)
|
@@ -12,6 +12,8 @@ module Bhf
|
|
12
12
|
end
|
13
13
|
@name = options.keys[0]
|
14
14
|
@data = options.values[0] || {}
|
15
|
+
@user = user
|
16
|
+
@settings = config
|
15
17
|
@collection = get_collection
|
16
18
|
|
17
19
|
t_model_path = "activerecord.models.#{model.model_name.to_s.downcase}"
|
@@ -24,31 +26,6 @@ module Bhf
|
|
24
26
|
|
25
27
|
@model = model
|
26
28
|
@page_name = page_name
|
27
|
-
@user = user
|
28
|
-
end
|
29
|
-
|
30
|
-
def search?
|
31
|
-
table_options(:search) != false
|
32
|
-
end
|
33
|
-
|
34
|
-
def table_hide?
|
35
|
-
table_options(:hide) == true || model.bhf_embedded?
|
36
|
-
end
|
37
|
-
|
38
|
-
def search_field?
|
39
|
-
table_options(:search_field) != false
|
40
|
-
end
|
41
|
-
|
42
|
-
def custom_search
|
43
|
-
table_options(:custom_search)
|
44
|
-
end
|
45
|
-
|
46
|
-
def custom_columns?
|
47
|
-
table_options(:columns).is_a?(Array)
|
48
|
-
end
|
49
|
-
|
50
|
-
def user_scope?
|
51
|
-
@user && table_options(:user_scope)
|
52
29
|
end
|
53
30
|
|
54
31
|
def prepare_objects(options, paginate_options = nil)
|
@@ -92,7 +69,7 @@ module Bhf
|
|
92
69
|
end
|
93
70
|
|
94
71
|
def columns
|
95
|
-
default_attrs(
|
72
|
+
default_attrs(table_columns, @collection[0..5]).
|
96
73
|
each_with_object([]) do |field, obj|
|
97
74
|
obj << Bhf::Data::Column.new(field)
|
98
75
|
end
|
@@ -122,6 +99,34 @@ module Bhf
|
|
122
99
|
false
|
123
100
|
end
|
124
101
|
|
102
|
+
def search?
|
103
|
+
table_options(:search) != false
|
104
|
+
end
|
105
|
+
|
106
|
+
def table_hide?
|
107
|
+
table_options(:hide) == true || model.bhf_embedded?
|
108
|
+
end
|
109
|
+
|
110
|
+
def search_field?
|
111
|
+
table_options(:search_field) != false
|
112
|
+
end
|
113
|
+
|
114
|
+
def custom_search
|
115
|
+
table_options(:custom_search)
|
116
|
+
end
|
117
|
+
|
118
|
+
def table_columns
|
119
|
+
table_options(:display) || table_options(:columns)
|
120
|
+
end
|
121
|
+
|
122
|
+
def custom_columns?
|
123
|
+
table_columns.is_a?(Array)
|
124
|
+
end
|
125
|
+
|
126
|
+
def user_scope?
|
127
|
+
@user && table_options(:user_scope)
|
128
|
+
end
|
129
|
+
|
125
130
|
def table
|
126
131
|
@data['table']
|
127
132
|
end
|
@@ -157,7 +162,7 @@ module Bhf
|
|
157
162
|
end
|
158
163
|
|
159
164
|
def hide_create
|
160
|
-
table_options('hide_create') || table_options('hide_new')
|
165
|
+
table_options('hide_create') || table_options('hide_new') || table_options('hide_add')
|
161
166
|
end
|
162
167
|
|
163
168
|
def show_duplicate
|
@@ -165,7 +170,7 @@ module Bhf
|
|
165
170
|
end
|
166
171
|
|
167
172
|
def hide_delete
|
168
|
-
table_options
|
173
|
+
table_options('hide_delete') || table_options('hide_destroy')
|
169
174
|
end
|
170
175
|
|
171
176
|
def custom_link
|
@@ -179,6 +184,10 @@ module Bhf
|
|
179
184
|
def return_to
|
180
185
|
form_options 'return_to'
|
181
186
|
end
|
187
|
+
|
188
|
+
def to_s
|
189
|
+
@name
|
190
|
+
end
|
182
191
|
|
183
192
|
private
|
184
193
|
|
@@ -207,7 +216,7 @@ module Bhf
|
|
207
216
|
display_type: table_options(:types, attr_name) || attr_name,
|
208
217
|
show_type: show_options(:types, attr_name) || table_options(:types, attr_name) || attr_name,
|
209
218
|
info: I18n.t("bhf.platforms.#{@name}.infos.#{attr_name}", default: ''),
|
210
|
-
link: form_options(:links, attr_name)
|
219
|
+
link: (@settings.find_platform(form_options(:links, attr_name), @user, false) if @settings && form_options(:links, attr_name))
|
211
220
|
})
|
212
221
|
)
|
213
222
|
end
|
@@ -232,7 +241,7 @@ module Bhf
|
|
232
241
|
overwrite_display_type: table_options(:types, name),
|
233
242
|
overwrite_show_type: show_options(:types, name) || table_options(:types, name),
|
234
243
|
info: I18n.t("bhf.platforms.#{@name}.infos.#{name}", default: ''),
|
235
|
-
link: form_options(:links, name)
|
244
|
+
link: (@settings.find_platform(form_options(:links, name), @user, false) if @settings && form_options(:links, name))
|
236
245
|
})
|
237
246
|
|
238
247
|
fk = all[name.to_s].reflection.foreign_key
|
data/lib/bhf/settings.rb
CHANGED
@@ -11,7 +11,7 @@ module Bhf
|
|
11
11
|
end
|
12
12
|
end.flatten!
|
13
13
|
if t.nil?
|
14
|
-
raise Exception.new("No
|
14
|
+
raise Exception.new("No bhf pages found")
|
15
15
|
end
|
16
16
|
if t.uniq.length != t.length
|
17
17
|
raise Exception.new("Platforms with identical names: '#{t.detect{ |e| t.count(e) > 1 }}'")
|
@@ -39,13 +39,14 @@ module Bhf
|
|
39
39
|
nil
|
40
40
|
end
|
41
41
|
|
42
|
-
def find_platform(platform_name, current_account = nil)
|
42
|
+
def find_platform(platform_name, current_account = nil, config = nil)
|
43
43
|
pages.each do |page|
|
44
44
|
content_for_page(page).each do |platform|
|
45
|
-
bhf_platform = Bhf::Platform.new(platform, page, current_account)
|
46
|
-
return bhf_platform if bhf_platform.name == platform_name
|
45
|
+
bhf_platform = Bhf::Platform.new(platform, page, config == nil ? self : config, current_account)
|
46
|
+
return bhf_platform if bhf_platform.name.to_s == platform_name.to_s
|
47
47
|
end
|
48
48
|
end
|
49
|
+
nil
|
49
50
|
end
|
50
51
|
|
51
52
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Bhf
|
2
2
|
|
3
|
-
module
|
3
|
+
module SettingsParser
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def parse(roles_array, area = nil)
|
7
7
|
roles_config = roles_yml(roles_array, area)
|
8
8
|
|
9
|
-
if Bhf
|
9
|
+
if Bhf.configuration.abstract_config.any?
|
10
10
|
|
11
|
-
tmp_pages = get_config_array(Bhf
|
11
|
+
tmp_pages = get_config_array(Bhf.configuration.abstract_config, '/abstract')['pages']
|
12
12
|
abstract_platform_config = tmp_pages.each_with_object({}) do |abstract_pages, hash|
|
13
13
|
abstract_pages.each do |abstract_page|
|
14
14
|
abstract_page[1].each do |abstract_platform|
|
@@ -70,7 +70,7 @@ module Bhf
|
|
70
70
|
end
|
71
71
|
merged_files
|
72
72
|
else
|
73
|
-
load_yml
|
73
|
+
load_yml(area.present? ? "/#{area}/bhf" : nil)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -1,17 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# config.bhf.account_model = 'User'
|
14
|
-
# config.bhf.account_model_find_method = 'find'
|
15
|
-
|
16
|
-
end
|
1
|
+
Bhf.configure do |config|
|
2
|
+
# config.css << 'bhf'
|
3
|
+
# config.js << 'bhf'
|
4
|
+
# config.abstract_config << 'abstract'
|
5
|
+
|
6
|
+
# config.on_login_fail = :root_url
|
7
|
+
# config.logout_path = :logout_path
|
8
|
+
|
9
|
+
# config.session_account_id = :admin_account_id
|
10
|
+
# config.session_auth_name = :is_admin
|
11
|
+
# config.account_model = 'User'
|
12
|
+
# config.account_model_find_method = 'find'
|
17
13
|
end
|
data/test/database.yml
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'yaml'
|
6
|
+
require 'active_record'
|
7
|
+
require 'mysql'
|
8
|
+
|
9
|
+
require 'app/models/bhf/widget.rb'
|
10
|
+
|
11
|
+
def bhf_widget( fixture_name )
|
12
|
+
id = @@fixtures['bhf_widget'][ fixture_name.to_s ][ 'id' ]
|
13
|
+
Bhf::Widget.find( id )
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_schema
|
17
|
+
config = YAML::load( IO.read( File.dirname(__FILE__) + '/database.yml') )
|
18
|
+
|
19
|
+
# Manually initialize the database
|
20
|
+
conn = Mysql.real_connect( config['mysql']['host'], config['mysql']['username'], config['mysql']['password'] )
|
21
|
+
conn.query( "CREATE DATABASE IF NOT EXISTS #{config['mysql']['database']}" )
|
22
|
+
|
23
|
+
ActiveRecord::Base.establish_connection( config['mysql'] )
|
24
|
+
ActiveRecord::Base.connection()
|
25
|
+
|
26
|
+
load(File.dirname(__FILE__) + "/../lib/rails/generators/bhf/templates/schema.rb")
|
27
|
+
|
28
|
+
@@fixtures = {}
|
29
|
+
|
30
|
+
load_fixture( 'bhf_widget' )
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_fixture( table )
|
34
|
+
@@fixtures[ table ] = {}
|
35
|
+
fixture = YAML::load( IO.read( File.dirname(__FILE__) + "/fixtures/#{table}.yml") )
|
36
|
+
@@fixtures[ table ] = fixture
|
37
|
+
|
38
|
+
klass = class_eval table.titleize.gsub(/ /, '::')
|
39
|
+
|
40
|
+
fixture.each do |record_name, record|
|
41
|
+
record.each do |column, value|
|
42
|
+
if ( match = column.match(/(.*)_id/) )
|
43
|
+
fixture_reference = "bhf_" + match[1].pluralize
|
44
|
+
if value.is_a? Symbol
|
45
|
+
r = class_eval "#{fixture_reference}( '#{value}' )"
|
46
|
+
record[ column ] = r.id
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
r = klass.create( record )
|
52
|
+
@@fixtures[ table ][ record_name ][ 'id' ] = r.id
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|