wacky 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,6 +28,8 @@ Copy the migrations and run them:
28
28
  rake wacky:install:migrations
29
29
  rake db:migrate
30
30
 
31
+ NOTE: Wacky will set an instance variable, `@wacky_title`, that has the title of the page you're on. It extracts this by finding the first heading element (h1, h2, h3, h4, h5, h6) on the page. If you want to include that in your layout title, you're welcome to.
32
+
31
33
  ### Development
32
34
 
33
35
  To run the tests:
@@ -1,4 +1,5 @@
1
1
  module Wacky
2
2
  class ApplicationController < ::ApplicationController
3
+ helper :all
3
4
  end
4
5
  end
@@ -51,6 +51,13 @@ module Wacky
51
51
  def load_page
52
52
  @page = Page.find_by_slug(params[:id])
53
53
  redirect_to new_page_path(id: params[:id]) unless @page
54
+ @wacky_title = extracted_title
55
+ end
56
+
57
+ def extracted_title
58
+ if(@page)
59
+ ExtractsTitle.new(@page.body).title
60
+ end
54
61
  end
55
62
  end
56
63
  end
@@ -1,4 +1,9 @@
1
1
  module Wacky
2
2
  module ApplicationHelper
3
+ def wacky_title
4
+ title = "Wacky"
5
+ additional_title = @title
6
+ [additional_title, title].compact.join(' - ')
7
+ end
3
8
  end
4
9
  end
@@ -0,0 +1,36 @@
1
+ require 'nokogiri'
2
+
3
+ module Wacky
4
+ class ExtractsTitle
5
+ attr_reader :doc
6
+
7
+ def initialize(doc)
8
+ @doc = doc
9
+ end
10
+
11
+ def title
12
+ matching_title ? matching_title.text : nil
13
+ end
14
+
15
+ private
16
+ def potential_title_selector_parts
17
+ %w(h1 h2 h3 h4 h5 h6)
18
+ end
19
+
20
+ def potential_title_selector
21
+ potential_title_selector_parts.join(',')
22
+ end
23
+
24
+ def nokogiri_doc
25
+ Nokogiri::HTML(doc)
26
+ end
27
+
28
+ def potential_titles
29
+ nokogiri_doc.css(potential_title_selector)
30
+ end
31
+
32
+ def matching_title
33
+ potential_titles.first
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,7 @@
1
1
  module Wacky
2
2
  class Page < ActiveRecord::Base
3
3
  validates_presence_of :slug
4
+ validates :slug, format: { with: /^[a-zA-Z0-9_-]*$/ }, uniqueness: true
4
5
  has_paper_trail
5
6
 
6
7
  def to_html
@@ -18,7 +19,7 @@ module Wacky
18
19
 
19
20
  def markdown_parser
20
21
  Redcarpet::Markdown.new(Redcarpet::Render::HTML,
21
- :autolink => true, :space_after_headers => true)
22
+ autolink: true, space_after_headers: true)
22
23
  end
23
24
  end
24
25
  end
@@ -1,7 +1,7 @@
1
1
  doctype html
2
2
  html
3
3
  head
4
- title Wacky
4
+ title= @wacky_title
5
5
  = stylesheet_link_tag "wacky/application", :media => "all"
6
6
  = javascript_include_tag "wacky/application"
7
7
  = csrf_meta_tags
data/lib/wacky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wacky
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/wacky.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rails'
2
- require 'wikitop'
3
2
  require "wacky/engine"
4
3
  require 'action_view'
5
4
  require 'active_record'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wacky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-26 00:00:00.000000000 Z
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.2.11
30
30
  - !ruby/object:Gem::Dependency
31
- name: wikitop
31
+ name: slim
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: slim
47
+ name: redcarpet
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: redcarpet
63
+ name: jquery-rails
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: jquery-rails
79
+ name: ace-rails-ap
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -92,7 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: ace-rails-ap
95
+ name: paper_trail
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -108,7 +108,7 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
- name: paper_trail
111
+ name: showdown-rails
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -124,7 +124,7 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: showdown-rails
127
+ name: nokogiri
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -331,6 +331,22 @@ dependencies:
331
331
  - - ! '>='
332
332
  - !ruby/object:Gem::Version
333
333
  version: '0'
334
+ - !ruby/object:Gem::Dependency
335
+ name: mocha
336
+ requirement: !ruby/object:Gem::Requirement
337
+ none: false
338
+ requirements:
339
+ - - ! '>='
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ type: :development
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ none: false
346
+ requirements:
347
+ - - ! '>='
348
+ - !ruby/object:Gem::Version
349
+ version: '0'
334
350
  description: A wiki engine for rails
335
351
  email:
336
352
  - josh@isotope11.com
@@ -346,6 +362,7 @@ files:
346
362
  - app/views/wacky/pages/show.html.slim
347
363
  - app/views/wacky/pages/edit.html.slim
348
364
  - app/models/wacky/page.rb
365
+ - app/models/wacky/extracts_title.rb
349
366
  - app/assets/javascripts/wacky/ace.js
350
367
  - app/assets/javascripts/wacky/showdown.js
351
368
  - app/assets/javascripts/wacky/application.js