graph_starter 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ee7e090e013ceee1f953a9859c2d469ec6f82c1
4
- data.tar.gz: f039138c5c6fea91161098c1722979e5a85e2a40
3
+ metadata.gz: 2b2e596b661e3237c66ae3669285815df75ff358
4
+ data.tar.gz: 36bd129f1d9550d6698c07eee7cc668cc9ed61f4
5
5
  SHA512:
6
- metadata.gz: ff56c5adb8387d6d1ef8266faf4b07402548c7521a5dd668693c66f1507a2c4961241b99eae8231095178ad4daaf44c73c9f306247d0527001245b019c29754d
7
- data.tar.gz: 4eec5d0d5d330cece01ca5fb15f4d0c2acfe2a9e8c47307af807d87c6180b2ba0f5352e24d5ec737cf3e23680f03236a32e976e5e85ff74d876c1741b5d523c7
6
+ metadata.gz: de40337965b9d0cb120796b1808ba1abb9bcc523c91728eb31eaca56f4daba3fdb4d8e6b1f7c06db4ba7aa8a95a6a8ed8eeb976286251e850606ca2b8a441d52
7
+ data.tar.gz: 6119263e47a3ec28f5321d42b116a87a613bedfa7853a0d85a651291e8b4755e5f6bca018b4808dedefb087702d36314d89fe81f6c18037d518b32271e422bce
@@ -8,12 +8,20 @@ module GraphStarter
8
8
  yield eval("__FILE__.gsub(Rails.root.to_s, GraphStarter::Engine.root.to_s)",b.binding)
9
9
  end
10
10
 
11
- def render_body
12
- views = Dir.glob(Rails.root.join("app/views/#{@model_slug}/_body.html.*"))
11
+ def render_body(asset, model_slug)
12
+ views = Dir.glob(Rails.root.join("app/views/#{model_slug}/_body.html.*"))
13
13
 
14
- partial_path = views.present? ? "#{@model_slug}/body" : 'body'
14
+ partial_path = views.present? ? "#{model_slug}/body" : 'body'
15
15
 
16
- render partial: partial_path, locals: {asset: @asset}
16
+ render partial: partial_path, locals: {asset: asset}
17
+ end
18
+
19
+ def config
20
+ GraphStarter::CONFIG
21
+ end
22
+
23
+ def present_asset(object)
24
+ yield(AssetPresenter.new(object, self)) if block_given?
17
25
  end
18
26
  end
19
27
  end
@@ -209,10 +209,6 @@ module GraphStarter
209
209
  end
210
210
  end
211
211
 
212
- def name
213
- title
214
- end
215
-
216
212
  def as_json(_options = {})
217
213
  {self.class.model_slug =>
218
214
  {id: id,
@@ -293,7 +289,7 @@ module GraphStarter
293
289
  end
294
290
 
295
291
  def self.icon_class
296
- 'bookmark'
292
+ GraphStarter.configuration.icon_classes[self.name.to_sym]
297
293
  end
298
294
  end
299
295
  end
@@ -0,0 +1,12 @@
1
+ module GraphStarter
2
+ class ApplicationPresenter < SimpleDelegator
3
+ def initialize(object, view)
4
+ @object, @view = object, view
5
+ super(@object)
6
+ end
7
+
8
+ def h
9
+ @view
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module GraphStarter
2
+ class AssetPresenter < ApplicationPresenter
3
+ def asset
4
+ @object
5
+ end
6
+
7
+ def display_column_widths
8
+ if main_column_exists?
9
+ left_sidebar_exists? ? %w(three ten three) : [nil, 'thirteen', 'three']
10
+ else
11
+ ['eight', nil, 'eight']
12
+ end
13
+ end
14
+
15
+ def left_sidebar_exists?
16
+ @left_sidebar_exists ||= asset.class.authorized_associations.size > 2
17
+ end
18
+
19
+ def main_column_exists?
20
+ @main_column_exists ||= asset.class.has_images? && asset.images.present? || asset.body.present?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ .ui.items
2
+ .item
3
+ .ui.statistic
4
+ .label
5
+ | Views
6
+ .value
7
+ = asset.view_count || 0
8
+
9
+
10
+ - asset.class.authorized_associations.each do |name, association|
11
+ - result = asset.send(name)
12
+ - if result.present?
13
+ .item
14
+ .content
15
+ .ui.horizontal.divider = name.to_s.humanize
16
+ .description
17
+ - case association.type
18
+ - when :has_one
19
+ - object = result
20
+ i class="#{association.target_class.icon_class} icon"
21
+ = link_to object.title, asset_path(object)
22
+ - when :has_many
23
+ .ui.middle.aligned.big.divided.list
24
+ - result.each do |object|
25
+ .item
26
+ i class="#{association.target_class.icon_class} icon"
27
+ .content
28
+ = link_to object.title, asset_path(object)
29
+
30
+ - recommendations = asset.secret_sauce_recommendations
31
+ - if recommendations.present?
32
+ .item
33
+ .content
34
+ .ui.horizontal.divider Recommended
35
+ .description
36
+ .ui.middle.aligned.big.divided.list
37
+ - recommendations.each do |recommendation|
38
+ .item data-score="#{recommendation.score}"
39
+ .content = link_to recommendation.asset.title, asset_path(recommendation.asset)
40
+
41
+
@@ -0,0 +1,51 @@
1
+ - if @current_user_is_admin
2
+ a.ui.labeled.icon.button.right.floated data-authorizable="#{asset.to_json}"
3
+ | Edit Permissions
4
+
5
+ - if @current_user_is_admin
6
+ a.ui.labeled.icon.button.right.floated href="#{edit_asset_path(id: asset)}"
7
+ i.edit.icon
8
+ | Edit
9
+
10
+ .ui.items
11
+ - if asset.class.rated? && defined?(current_user) && current_user
12
+ .item
13
+ .content
14
+ .ui.horizontal.divider Rating
15
+ .description
16
+ .ui.star.rating data-max-rating="5" data-rating="#{asset.rating_level_for(current_user)}"
17
+ coffee:
18
+ $('#right-column .ui.rating').rating
19
+ clearable: true
20
+ onRate: (new_rating) ->
21
+ $.ajax
22
+ method: 'PUT'
23
+ url: "/#{model_slug}/#{asset_id}/rate/#{new_rating}"
24
+
25
+
26
+ - asset.class.authorized_properties(defined?(current_user) && current_user).each do |property|
27
+ - next if !asset.class.display_property?(property.name)
28
+ - next if asset.class.name_property?(property.name) || asset.class.body_property?(property.name)
29
+
30
+ - if asset.read_attribute(property.name).present?
31
+ .item
32
+ .content
33
+ .ui.horizontal.divider data-authorizable="#{property.to_json}"
34
+ = property.name.humanize
35
+ - if property.private?
36
+ i.red.hide.icon
37
+ .description
38
+ = render partial: 'graph_starter/properties/property', locals: {property: property, asset: asset, level: 'read'}
39
+
40
+ - if asset.class.display_property?(:created_at)
41
+ .item
42
+ .content
43
+ .ui.horizontal.divider Created
44
+ .description = asset.created_at
45
+
46
+ - if asset.class.display_property?(:updated_at)
47
+ .item
48
+ .content
49
+ .ui.horizontal.divider Last updated
50
+ .description = asset.updated_at
51
+
@@ -3,108 +3,26 @@ javascript:
3
3
  var asset_id = '#{@asset.id}';
4
4
  var model_slug = '#{@asset.class.model_slug}';
5
5
 
6
- - main_column_exists = @asset.class.has_images? && @asset.images.present? || @asset.body.present?
7
- - side_column_width = (main_column_exists ? 'three' : 'eight')
8
- - column_count = (main_column_exists ? 'three' : 'two')
6
+ - present_asset(@asset) do |asset_presenter|
7
+ .ui.huge.centered.header
8
+ .content
9
+ = @asset.title
9
10
 
10
- .ui.huge.centered.header
11
- .content
12
- = @asset.title
13
11
 
14
- .ui.grid
15
- div class="#{side_column_width} wide column"
16
- .ui.items
17
- .item
18
- .ui.statistic
19
- .label
20
- | Views
21
- .value
22
- = @asset.view_count || 0
12
+ - left_width, center_width, right_width = asset_presenter.display_column_widths
23
13
 
14
+ .ui.grid
15
+ - if asset_presenter.left_sidebar_exists?
16
+ div class="#{left_width} wide column"
17
+ = render partial: 'dynamic_items', locals: {asset: @asset}
24
18
 
25
- - @asset.class.authorized_associations.each do |name, association|
26
- - result = @asset.send(name)
27
- - if result.present?
28
- .item
29
- .content
30
- .ui.horizontal.divider = name.to_s.humanize
31
- .description
32
- - case association.type
33
- - when :has_one
34
- - object = result
35
- i class="#{association.target_class.icon_class} icon"
36
- = link_to object.title, asset_path(object)
37
- - when :has_many
38
- .ui.middle.aligned.big.divided.list
39
- - result.each do |object|
40
- .item
41
- i class="#{association.target_class.icon_class} icon"
42
- .content
43
- = link_to object.title, asset_path(object)
19
+ - if asset_presenter.main_column_exists?
20
+ div class="#{center_width} wide column"
21
+ = render_body(@asset, @model_slug)
44
22
 
45
- - recommendations = @asset.secret_sauce_recommendations
46
- - if recommendations.present?
47
- .item
48
- .content
49
- .ui.horizontal.divider Recommended
50
- .description
51
- .ui.middle.aligned.big.divided.list
52
- - recommendations.each do |recommendation|
53
- .item data-score="#{recommendation.score}"
54
- .content = link_to recommendation.asset.title, asset_path(recommendation.asset)
23
+ div class="#{right_width} wide column" id="right-column"
24
+ - if !asset_presenter.left_sidebar_exists?
25
+ = render partial: 'dynamic_items', locals: {asset: @asset}
55
26
 
56
- - if main_column_exists
57
- .ten.wide.column
58
- = render_body
27
+ = render partial: 'property_items', locals: {asset: @asset}
59
28
 
60
- div class="#{side_column_width} wide column" id="right-column"
61
- - if @current_user_is_admin
62
- a.ui.labeled.icon.button.right.floated data-authorizable="#{@asset.to_json}"
63
- | Edit Permissions
64
-
65
- - if @current_user_is_admin
66
- a.ui.labeled.icon.button.right.floated href="#{edit_asset_path(id: @asset)}"
67
- i.edit.icon
68
- | Edit
69
-
70
- .ui.items
71
- - if @asset.class.rated? && defined?(current_user) && current_user
72
- .item
73
- .content
74
- .ui.horizontal.divider Rating
75
- .description
76
- .ui.star.rating data-max-rating="5" data-rating="#{@asset.rating_level_for(current_user)}"
77
- coffee:
78
- $('#right-column .ui.rating').rating
79
- clearable: true
80
- onRate: (new_rating) ->
81
- $.ajax
82
- method: 'PUT'
83
- url: "/#{model_slug}/#{asset_id}/rate/#{new_rating}"
84
-
85
-
86
- - @asset.class.authorized_properties(defined?(current_user) && current_user).each do |property|
87
- - next if !@asset.class.display_property?(property.name)
88
- - next if @asset.class.name_property?(property.name) || @asset.class.body_property?(property.name)
89
-
90
- - if @asset.read_attribute(property.name).present?
91
- .item
92
- .content
93
- .ui.horizontal.divider data-authorizable="#{property.to_json}"
94
- = property.name.humanize
95
- - if property.private?
96
- i.red.hide.icon
97
- .description
98
- = render partial: 'graph_starter/properties/property', locals: {property: property, asset: @asset, level: 'read'}
99
-
100
- - if @asset.class.display_property?(:created_at)
101
- .item
102
- .content
103
- .ui.horizontal.divider Created
104
- .description = @asset.created_at
105
-
106
- - if @asset.class.display_property?(:updated_at)
107
- .item
108
- .content
109
- .ui.horizontal.divider Last updated
110
- .description = @asset.updated_at
@@ -1,6 +1,8 @@
1
1
  #menu.ui.secondary.pointing.menu
2
2
  = link_to 'Home', '/', class: "item #{'active' if request.path == '/'}"
3
+ - menu_models = config.menu_models && config.menu_models.map(&:to_s)
3
4
  - GraphStarter::Asset.descendants.each do |model_class|
5
+ - next if menu_models && !model_class.name.in?(menu_models)
4
6
  - path = graph_starter.assets_path(model_slug: model_class.model_slug)
5
7
  = link_to model_class.name.tableize.humanize, path, class: "item #{'active' if request.path.match(/^#{path}/)}"
6
8
 
@@ -2,9 +2,27 @@ module GraphStarter
2
2
  class Configuration
3
3
  attr_writer :user_class
4
4
 
5
+ attr_accessor :menu_models, :icon_classes
6
+
7
+ def initialize
8
+ @icon_classes = {}
9
+ end
10
+
5
11
  def user_class
6
12
  @user_class || (:User if defined?(::User))
7
13
  end
14
+
15
+ def validation_errors
16
+ {}.tap do |errors|
17
+ if !(@menu_models.respond_to?(:each) || @menu_models.nil?)
18
+ errors[:menu_models] = 'should be enumerable or nil'
19
+ end
20
+
21
+ if !@icon_classes.is_a?(Hash)
22
+ errors[:icon_classes] = 'should be a Hash'
23
+ end
24
+ end
25
+ end
8
26
  end
9
27
  end
10
28
 
@@ -13,12 +31,16 @@ module GraphStarter
13
31
 
14
32
  def self.configure(config_hash = nil)
15
33
  if config_hash.nil?
16
- yield Configuration.new
34
+ yield CONFIG
17
35
  else
18
36
  config_hash.each do |key, value|
19
37
  CONFIG.send("#{key}=", value)
20
38
  end
21
39
  end
40
+
41
+ errors = CONFIG.validation_errors
42
+
43
+ fail "GraphStarter validation errors: #{errors.inspect}" if errors.size > 0
22
44
  end
23
45
 
24
46
  def self.configuration
@@ -12,6 +12,7 @@ module GraphStarter
12
12
  isolate_namespace GraphStarter
13
13
 
14
14
  config.autoload_paths << File.expand_path("../../", __FILE__)
15
+ config.autoload_paths << File.expand_path("../../../app/presenters", __FILE__)
15
16
 
16
17
  config.neo4j._active_record_destroyed_behavior = true
17
18
 
@@ -1,3 +1,3 @@
1
1
  module GraphStarter
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph_starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -130,9 +130,13 @@ files:
130
130
  - app/models/graph_starter/property.rb
131
131
  - app/models/graph_starter/rating.rb
132
132
  - app/models/graph_starter/view.rb
133
+ - app/presenters/graph_starter/application_presenter.rb
134
+ - app/presenters/graph_starter/asset_presenter.rb
133
135
  - app/views/graph_starter/assets/TODO.md
134
136
  - app/views/graph_starter/assets/_body.html.slim
135
137
  - app/views/graph_starter/assets/_cards.html.slim
138
+ - app/views/graph_starter/assets/_dynamic_items.html.slim
139
+ - app/views/graph_starter/assets/_property_items.html.slim
136
140
  - app/views/graph_starter/assets/edit.html.slim
137
141
  - app/views/graph_starter/assets/home.html.slim
138
142
  - app/views/graph_starter/assets/index.html.slim