rooftop-rails-extras 0.0.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c74da683e1346ccbe1c23dddc3bca3a1861f9cc
4
- data.tar.gz: 1c03eb2c4d0d05828c2006014c472320317622fc
3
+ metadata.gz: 146aac62fdbc7ca8d90c1751b3ea0677c50d267e
4
+ data.tar.gz: 476df8a7cd38c68d0b1b71d748076ab4c813fd7b
5
5
  SHA512:
6
- metadata.gz: d82bded841f67c43b69db1c924c6507c53c36ff488a4abad9adc8c8f469f4171513807a1c5fe3024f2dfe7556516e1d2122f5909805dcf184f219e72f68edaa8
7
- data.tar.gz: f53e402415eef03fdb60bcd1c3c6c8f2399af67b7850167ad699febddd417a4bf9f07b094158aeedb3dc1c792725403c69a3efdd3ef4ac20520bece911a014d8
6
+ metadata.gz: 564b6903a2805f46de117e36ce67a7779119aa604e263c0602e65c6f462d07f99faaf8aa0f0d192e8fc56c952c36a1c6ad61e1ca1f1945bacf19670606439f3c
7
+ data.tar.gz: cb430ca435d51dbf74e181091a67c4b8d6afe61fa4890bf60f71ca043d25f41cf251d3cbd6a7a3c5062827b7870ebd223c21faebc79a2a132ce1a1d34fbadce0
data/README.md CHANGED
@@ -30,6 +30,12 @@ class SomePostType
30
30
  end
31
31
  ```
32
32
 
33
+ Then doing a search is as simple as:
34
+
35
+ ```
36
+ SomePostType.search("your string") #will return a collection of matching objects.
37
+ ```
38
+
33
39
  ## Contact form handling
34
40
  Almost every website we build needs a simple mail handler. Extending the [mail_form gem](https://github.com/plataformatec/mail_form), we've added a way to handle these with minimal fuss. Some assumptions are made in the name of expedience; if you need more than this, you probably need to use `mail_form` directly.
35
41
 
@@ -49,6 +55,7 @@ class ContactForm < Rooftop::Rails::Extras::ContactForm #you can call your class
49
55
  }
50
56
  self.to = "the email you want to send the contact messages to"
51
57
  self.from = "the email from which you want to send the messages"
58
+ self.setup! #you need to call setup! here because there's no elegant way to call it automatically in the parent class.
52
59
  end
53
60
  ```
54
61
 
@@ -38,7 +38,11 @@ module Rooftop
38
38
 
39
39
  private
40
40
  def contact_form_params
41
- params.require(self.class.contact_form.to_s.underscore.to_sym).permit(self.class.contact_form.fields.keys)
41
+ # Sometimes we might want to pass params into this which are arrays from e.g. checkboxes. So we allow the keys from the form as syms and also as hashes
42
+ permitted_keys = [self.class.contact_form.fields.keys, self.class.contact_form.fields.keys.inject({}) {|h,k| h[k] = []; h }]
43
+ self.class.contact_form.fields.keys
44
+ params.require(self.class.contact_form.to_s.underscore.to_sym).permit(*permitted_keys)
45
+
42
46
  end
43
47
  end
44
48
  end
@@ -10,10 +10,10 @@ module Rooftop
10
10
  }.merge(opts)
11
11
  raise ArgumentError, "#{entity.class} isn't a nested class" unless entity.respond_to?(:resolved_children)
12
12
  raise ArgumentError, "You passed a current #{entity.class.to_s.downcase} which isn't a #{entity.class} object" unless (default_opts[:current].nil? || default_opts[:current].is_a?(entity.class))
13
- if entity.resolved_children.any?
14
- # byebug
13
+ resolved_children = entity.resolved_children
14
+ if resolved_children.any?
15
15
  content_tag(:ul, class: default_opts[:class]) do
16
- items = entity.resolved_children.collect do |child|
16
+ items = resolved_children.collect do |child|
17
17
  subnavigation_item_for(child, default_opts)
18
18
  end
19
19
  items.join.html_safe
@@ -41,6 +41,10 @@ module Rooftop
41
41
  }.merge(opts)
42
42
  item_path = path_for_menu_item(item)
43
43
  item_class = path_matches?(item_path) ? default_opts[:current_class] : ""
44
+ # add the status into the item class
45
+ if item.respond_to?(:status)
46
+ item_class += " status-#{item.status}"
47
+ end
44
48
  content_tag :li, class: item_class do
45
49
  link = content_tag :a, href: item_path do
46
50
  item.title.html_safe
@@ -86,6 +90,10 @@ module Rooftop
86
90
  list_opts = {}
87
91
  opts.reverse_merge!({level: 1})
88
92
  list_opts[:class] = opts[:current_class] if opts[:current].present? && opts[:current].id == entity.id
93
+ # add the status if the item as a class
94
+ if entity.respond_to?(:status)
95
+ list_opts[:class] += " status-#{entity.status}"
96
+ end
89
97
  # The link to the entity
90
98
  content_tag :li, list_opts do
91
99
 
@@ -97,7 +105,7 @@ module Rooftop
97
105
 
98
106
  # Nested ul for children if necessary
99
107
  if opts[:current].present? && (opts[:current].ancestors.collect(&:id).include?(entity.id) || opts[:current].id == entity.id)
100
- children = entity.class.where(post_parent: entity.id)
108
+ children = entity.class.where(post_parent: entity.id, orderby: :menu_order, order: :asc)
101
109
  if children.any?
102
110
  child_links = content_tag :ul, class: "subnavigation-level-#{opts[:level]}" do
103
111
  items = children.collect do |child|
@@ -8,7 +8,7 @@ module Rooftop
8
8
  child_ids = children.collect(&:id)
9
9
 
10
10
  if child_ids.any?
11
- self.class.where(post__in: child_ids)
11
+ self.class.where(post__in: child_ids, orderby: :post__in)
12
12
  else
13
13
  []
14
14
  end
@@ -12,24 +12,16 @@ module Rooftop
12
12
  message: :text_area
13
13
  }
14
14
 
15
- def self.inherited(base)
16
- (base.fields || DEFAULT_FIELDS).keys.each do |field|
17
- base.send(:attribute,field, {validate: true})
15
+ def self.setup!
16
+ (self.fields || DEFAULT_FIELDS).keys.each do |field|
17
+ self.send(:attribute,field, {validate: true})
18
18
  end
19
19
 
20
- base.subject ||= "Contact form message"
21
- base.to ||= "change.me@#{base.to_s.underscore}"
22
- base.from ||= "change.me@#{base.to_s.underscore}"
23
- base.headers ||= {}
20
+ self.subject ||= "Contact form message"
21
+ self.to ||= "change.me@#{self.to_s.underscore}"
22
+ self.from ||= "change.me@#{self.to_s.underscore}"
23
+ self.headers ||= {}
24
24
  end
25
- #
26
- # attribute :salutation
27
- # attribute :first_name, validate: true
28
- # attribute :last_name, validate: true
29
- # attribute :email, validate: true
30
- # attribute :phone
31
- # attribute :message, validate: true
32
- # attribute :nickname, captcha: true
33
25
 
34
26
  # Declare the e-mail headers. It accepts anything the mail method
35
27
  # in ActionMailer accepts.
@@ -1,7 +1,7 @@
1
1
  module Rooftop
2
2
  module Rails
3
3
  module Extras
4
- VERSION = "0.0.3"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
 
24
24
  spec.add_dependency 'require_all', '~> 1.3'
25
- spec.add_dependency 'rooftop-rails', '0.0.6'
25
+ spec.add_dependency 'rooftop-rails', '~>0.1.0'
26
26
  spec.add_dependency 'mail_form', '~> 1.5'
27
27
 
28
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rooftop-rails-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-01 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rooftop-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.6
61
+ version: 0.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.6
68
+ version: 0.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mail_form
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,10 +95,10 @@ files:
95
95
  - app/controllers/concerns/rooftop/rails/extras/contact_form_handler.rb
96
96
  - app/helpers/rooftop/rails/extras/navigation_helper.rb
97
97
  - app/helpers/rooftop/rails/extras/related_fields_helper.rb
98
- - app/models/concerns/rooftop/rails/extras/contact_form.rb
99
98
  - app/models/concerns/rooftop/rails/extras/page_redirect.rb
100
99
  - app/models/concerns/rooftop/rails/extras/resolved_children.rb
101
100
  - app/models/concerns/rooftop/rails/extras/resource_search.rb
101
+ - app/models/rooftop/rails/extras/contact_form.rb
102
102
  - lib/generators/rooftop/extras_generator.rb
103
103
  - lib/generators/rooftop/page_generator.rb
104
104
  - lib/generators/rooftop/pages_controller_generator.rb