chili_pepper 0.0.2 → 0.0.8

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: f0549b3418e8a065e5638d7fa82a122496418aa0
4
- data.tar.gz: e57bb127cbe1436ca6766b93fde4391bd050bf4e
3
+ metadata.gz: a2cc9fbae80c7d653e65073069858aae7fc85a56
4
+ data.tar.gz: 1b135bb9920088588544dfa0814c031ce1b6f428
5
5
  SHA512:
6
- metadata.gz: dd6ca94fe0bbe93c5f4b424c9756cbb3eb824a1cfceba57d9db3ef094e1b89973bbdc5cf02607362a93db60257f3515406ef96e0544f7e3f9ffeb4473625e15f
7
- data.tar.gz: 22865f5bf949c91955237fc9a90a116110142e19bc4eb9cf52ec5c38bcd26eef70c32fa0b02d720b9149d205314608c192cefa6649c3f7d16ce1cbfbba4a366c
6
+ metadata.gz: 4571c0de0c25107aa800b93373fd75486e83f2110b58fe1bd085a3b2df94798c280a4e974bab5f09cbacb378d51a256210075712b0327e06ed9f94690ac6ba59
7
+ data.tar.gz: c8849f2f6a703977c9bbcc48bb2c48b3dd2b4dc794c03fa9c6df0750a2f2f3097f01ff5924b939dbaa59ce63fd4b476e5c8c7e8d800885947ede37cbf99431f4
@@ -6,5 +6,7 @@ jQuery ->
6
6
  if $('#new_dish').length
7
7
  DishForm.act_on_select()
8
8
 
9
+ MenuForm.init()
10
+
9
11
 
10
12
 
@@ -0,0 +1,20 @@
1
+ @MenuForm =
2
+ init: ->
3
+ $('.admin_form form').on 'click', '.remove_fields', (event) ->
4
+ $(this).prev('ul').find('li input[type=hidden]').val('1')
5
+ $(this).parent('li').hide()
6
+ event.preventDefault()
7
+ $('.admin_form form').on 'click', '.add_fields', (event) ->
8
+ time = new Date().getTime()
9
+ regexp = new RegExp($(this).data('id'), 'g')
10
+ $(this).parent('li').before($(this).data('fields').replace(regexp, time))
11
+ event.preventDefault()
12
+
13
+ # @MenusAdminControls =
14
+ # init_sort: ->
15
+ # $('#menu_nav ul').removeClass('regular').addClass('sortable').sortable(
16
+ # axis: 'x'
17
+ # update: ->
18
+ # $.post($(this).data('update-url'), $(this).sortable('serialize'))
19
+ # )
20
+
@@ -75,7 +75,7 @@ module ChiliPepper
75
75
  :picture,
76
76
  :coeliac,
77
77
  :vegetarian,
78
- items_attributes: [:section_id, :price, :column, :dish_id, :id]
78
+ items_attributes: [:section_id, :price, :column, :dish_id, :id, :annotation_id]
79
79
  )
80
80
  end
81
81
  end
@@ -88,7 +88,8 @@ module ChiliPepper
88
88
  :price,
89
89
  :published,
90
90
  :downloadable_pdf,
91
- :image
91
+ :image,
92
+ annotations_attributes: [:id, :description, :_destroy]
92
93
  )
93
94
  end
94
95
  end
@@ -24,6 +24,12 @@ module ChiliPepper
24
24
  end
25
25
  end
26
26
 
27
+ def show_annotation
28
+ if annotation.present?
29
+ h.content_tag(:span, annotation.description, class: 'annotation')
30
+ end
31
+ end
32
+
27
33
  def show_description
28
34
  if dish.description?
29
35
  h.content_tag(:p, h.markdown(dish.description), class: 'dish_description')
@@ -1,23 +1,32 @@
1
1
  module ChiliPepper
2
2
  module ApplicationHelper
3
- def markdown(text)
4
- renderer = Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: true)
5
- options = {
6
- autolink: true,
7
- no_intra_emphasis: true
8
- }
9
- rtxt = Redcarpet::Markdown.new(renderer, options).render(text)
10
- return Regexp.new(/\A<p>(.*)<\/p>\Z/m).match(rtxt)[1].html_safe
11
- end
3
+ def markdown(text)
4
+ renderer = Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: true)
5
+ options = {
6
+ autolink: true,
7
+ no_intra_emphasis: true
8
+ }
9
+ rtxt = Redcarpet::Markdown.new(renderer, options).render(text)
10
+ return Regexp.new(/\A<p>(.*)<\/p>\Z/m).match(rtxt)[1].html_safe
11
+ end
12
12
 
13
- def cache_or_admin(fragment_name, &block_to_be_executed)
14
- if !admin_signed_in?
15
- cache(fragment_name) do
16
- block_to_be_executed.call
17
- end
18
- else
13
+ def cache_or_admin(fragment_name, &block_to_be_executed)
14
+ if !admin_signed_in?
15
+ cache(fragment_name) do
19
16
  block_to_be_executed.call
20
17
  end
18
+ else
19
+ block_to_be_executed.call
20
+ end
21
+ end
22
+
23
+ def link_to_add_fields(name, f, association)
24
+ new_object = f.object.send(association).klass.new
25
+ id = new_object.object_id
26
+ fields = f.fields_for(association, new_object, child_index: id) do |builder|
27
+ render(association.to_s.singularize + "_fields", f: builder)
21
28
  end
29
+ link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
30
+ end
22
31
  end
23
32
  end
@@ -0,0 +1,7 @@
1
+ module ChiliPepper
2
+ class Annotation < ActiveRecord::Base
3
+ belongs_to :menu, touch: true
4
+ has_many :items, dependent: :nullify
5
+ acts_as_list scope: :menu
6
+ end
7
+ end
@@ -16,6 +16,7 @@ module ChiliPepper
16
16
  class Item < ActiveRecord::Base
17
17
  belongs_to :dish, class_name: 'ChiliPepper::Dish'
18
18
  belongs_to :section, class_name: 'ChiliPepper::Section'
19
+ belongs_to :annotation, class_name: 'ChiliPepper::Annotation'
19
20
  validates :section, presence: true
20
21
  acts_as_list scope: :section
21
22
  after_destroy :check_dish_relevance
@@ -32,6 +32,9 @@ module ChiliPepper
32
32
  extend FriendlyId
33
33
  friendly_id :name, use: :slugged
34
34
 
35
+ has_many :annotations, dependent: :destroy
36
+ accepts_nested_attributes_for :annotations, allow_destroy: true
37
+
35
38
  has_attached_file :image,
36
39
  styles: {
37
40
  medium: ChiliPepper.menu_medium_image,
@@ -19,7 +19,7 @@
19
19
  %fieldset
20
20
  = item_form.input :section_id, :as => :hidden, :input_html => { :value => @item.section_id}
21
21
  = item_form.input :column, :as => :hidden, :input_html => { :value => @item.column}
22
- / = item_form.association :menu_annotation, :collection => @section.menu.menu_annotations, :value_method => lambda {|x| x.id}, :label_method => lambda {|x| x.description}
22
+ = item_form.association :annotation, :collection => @menu.annotations, :value_method => lambda {|x| x.id}, :label_method => lambda {|x| x.description}
23
23
  = hidden_field_tag 'section_id', @section.id
24
24
  - if @item.present?
25
25
  = hidden_field_tag 'item_id', @item.id
@@ -6,7 +6,7 @@
6
6
  %h4.dish_name
7
7
  = item.dish.name
8
8
  = item.show_price
9
- / = item.show_annotation
9
+ = item.show_annotation
10
10
 
11
11
  - if admin_signed_in?
12
12
  = link_to "Edit Dish", edit_dish_path(item.dish, section_id: item.section_id, item_id: item.id), class: "admin edit"
@@ -0,0 +1,5 @@
1
+ %li
2
+ %ul.annotation_field
3
+ = f.input :description, :label => false
4
+ = f.input :_destroy, :as => :hidden
5
+ = link_to "remove", '#', class: "remove_fields"
@@ -13,14 +13,14 @@
13
13
  = f.input :image
14
14
 
15
15
 
16
- / %fieldset.menu_notes
17
- / %p.form_tag
18
- / Menu Notes
19
- / %ul
20
- / = f.simple_fields_for :menu_annotations do |note_builder|
21
- / = render 'menu_annotation_fields', f: note_builder
22
- / %li.add_annotation
23
- / = link_to_add_fields "Add note", f, :menu_annotations
16
+ %fieldset.menu_notes
17
+ %p.form_tag
18
+ Menu Notes
19
+ %ul
20
+ = f.simple_fields_for :annotations do |note_builder|
21
+ = render 'annotation_fields', f: note_builder
22
+ %li.add_annotation
23
+ = link_to_add_fields "Add note", f, :annotations
24
24
 
25
25
 
26
26
 
@@ -0,0 +1,11 @@
1
+ class CreateChiliPepperAnnotations < ActiveRecord::Migration
2
+ def change
3
+ create_table :chili_pepper_annotations do |t|
4
+ t.integer :menu_id
5
+ t.integer :position
6
+ t.string :description
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddAnnotationIdToItems < ActiveRecord::Migration
2
+ def change
3
+ add_column :chili_pepper_items, :annotation_id, :integer
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ChiliPepper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chili_pepper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loic Seigland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -381,6 +381,7 @@ files:
381
381
  - app/helpers/chili_pepper/menus_helper.rb
382
382
  - app/helpers/chili_pepper/sections_helper.rb
383
383
  - app/models/chili_pepper/admin.rb
384
+ - app/models/chili_pepper/annotation.rb
384
385
  - app/models/chili_pepper/dish.rb
385
386
  - app/models/chili_pepper/item.rb
386
387
  - app/models/chili_pepper/menu.rb
@@ -389,6 +390,7 @@ files:
389
390
  - app/views/chili_pepper/dishes/edit.html.haml
390
391
  - app/views/chili_pepper/dishes/new.html.haml
391
392
  - app/views/chili_pepper/items/_item.html.haml
393
+ - app/views/chili_pepper/menus/_annotation_fields.haml
392
394
  - app/views/chili_pepper/menus/_form.html.haml
393
395
  - app/views/chili_pepper/menus/_navigation.html.haml
394
396
  - app/views/chili_pepper/menus/edit.html.haml
@@ -431,6 +433,8 @@ files:
431
433
  - db/migrate/20140616162854_add_pictures_to_dishes.rb
432
434
  - db/migrate/20140616163025_add_attachements_to_menus.rb
433
435
  - db/migrate/20140616163238_add_attachments_to_sections.rb
436
+ - db/migrate/20140810170249_create_chili_pepper_annotations.rb
437
+ - db/migrate/20140810170608_add_annotation_id_to_items.rb
434
438
  - lib/chili_pepper.rb
435
439
  - lib/chili_pepper/configuration.rb
436
440
  - lib/chili_pepper/engine.rb