picky-generators 4.12.1 → 4.12.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,22 +18,20 @@ module Picky
18
18
  #
19
19
  #
20
20
  def generate
21
- exclaim "Setting up Picky Sinatra Client/Server \"#{name}\"."
22
- create_target_directory
23
- copy_all_files
24
- copy_all_files expand_prototype_path('shared/server')
25
- copy_all_files expand_prototype_path('shared/both')
26
- copy_all_files expand_prototype_path('shared/client')
27
- exclaim "\"#{name}\" is a great project name! Have fun :)\n"
28
- exclaim ""
29
- exclaim "Next steps:"
30
- exclaim "1. cd #{name}"
31
- exclaim "2. bundle install"
32
- exclaim "3. rake index"
33
- exclaim "4. unicorn -c unicorn.rb"
34
- exclaim "5. open http://localhost:8080/"
35
- exclaim "6. rake todo # (optional) shows you where Picky needs input from you"
36
- exclaim " # if you want to define your own search."
21
+ generate_for "Sinatra Client/Server",
22
+ [
23
+ 'shared/server',
24
+ 'shared/both',
25
+ 'shared/client'
26
+ ],
27
+ [
28
+ "cd #{name}",
29
+ "bundle install",
30
+ "rake index",
31
+ "unicorn -c unicorn.rb",
32
+ "open http://localhost:8080/",
33
+ "rake todo # (optional) Shows you where Picky needs input from you."
34
+ ]
37
35
  end
38
36
 
39
37
  end
@@ -117,6 +117,25 @@ module Picky
117
117
  puts something
118
118
  end
119
119
 
120
+ def generate_for type, prototype_paths, steps
121
+ exclaim "Setting up Picky #{type} \"#{name}\"."
122
+
123
+ create_target_directory
124
+ copy_all_files
125
+
126
+ prototype_paths.each do |path|
127
+ copy_all_files expand_prototype_path(path)
128
+ end
129
+
130
+ exclaim "\"#{name}\" is a great project name! Have fun :)\n"
131
+ exclaim ""
132
+ exclaim "Next steps:"
133
+
134
+ steps.each.with_index do |step, i|
135
+ exclaim "#{i+1}. #{step}"
136
+ end
137
+ end
138
+
120
139
  end
121
140
 
122
141
  end
@@ -18,19 +18,19 @@ module Picky
18
18
  #
19
19
  #
20
20
  def generate
21
- exclaim "Setting up Picky Sinatra Client \"#{name}\"."
22
- create_target_directory
23
- copy_all_files
24
- copy_all_files expand_prototype_path('shared/both')
25
- copy_all_files expand_prototype_path('shared/client')
26
- exclaim "\"#{name}\" is a great project name! Have fun :)\n"
27
- exclaim ""
28
- exclaim "Next steps:"
29
- exclaim "1. cd #{name}"
30
- exclaim "2. bundle install"
31
- exclaim "3. unicorn -p 3000 # (optional) Or use your favorite web server."
32
- exclaim "4. open http://localhost:3000"
33
- exclaim ""
21
+ generate_for "Sinatra Client",
22
+ [
23
+ 'shared/both',
24
+ 'shared/client'
25
+ ],
26
+ [
27
+ "cd #{name}",
28
+ "bundle install",
29
+ "rake index",
30
+ "unicorn -p 3000 # (optional) Or use your favorite web server.",
31
+ "open http://localhost:3000/",
32
+ "rake todo # (optional) Shows you where Picky needs input from you."
33
+ ]
34
34
  end
35
35
 
36
36
  end
@@ -18,19 +18,19 @@ module Picky
18
18
  #
19
19
  #
20
20
  def generate
21
- exclaim "Setting up Picky Sinatra Server \"#{name}\"."
22
- create_target_directory
23
- copy_all_files
24
- copy_all_files expand_prototype_path('shared/server')
25
- copy_all_files expand_prototype_path('shared/both')
26
- exclaim "\"#{name}\" is a great project name! Have fun :)\n"
27
- exclaim ""
28
- exclaim "Next steps:"
29
- exclaim "1. cd #{name}"
30
- exclaim "2. rake index"
31
- exclaim "3. unicorn -c unicorn.rb"
32
- exclaim "4. rake todo # (optional) shows you where Picky needs input from you"
33
- exclaim " # if you want to define your own search."
21
+ generate_for "Sinatra Server",
22
+ [
23
+ 'shared/server',
24
+ 'shared/both'
25
+ ],
26
+ [
27
+ "cd #{name}",
28
+ "bundle install",
29
+ "rake index",
30
+ "unicorn -c unicorn.rb",
31
+ "curl http://localhost:8080/books?query=turing",
32
+ "rake todo # (optional) Shows you where Picky needs input from you."
33
+ ]
34
34
  end
35
35
 
36
36
  end
@@ -6,9 +6,10 @@ require 'haml'
6
6
  require 'csv'
7
7
  require 'picky'
8
8
  require 'picky-client'
9
-
10
- require File.expand_path '../book', __FILE__
11
- require File.expand_path '../logging', __FILE__
9
+ require_relative 'book'
10
+ require_relative 'logging'
11
+ require_relative 'books_index'
12
+ require_relative 'books_search'
12
13
 
13
14
  # This app shows how to integrate the Picky server directly
14
15
  # inside a web app. However, if you really need performance
@@ -16,68 +17,6 @@ require File.expand_path '../logging', __FILE__
16
17
  #
17
18
  class BookSearch < Sinatra::Application
18
19
 
19
- # We do this so we don't have to type
20
- # Picky:: in front of everything.
21
- #
22
- include Picky
23
-
24
-
25
- # Server.
26
- #
27
-
28
- # Data source.
29
- #
30
- class Books
31
-
32
- def initialize
33
- @csv = CSV.new File.open(File.expand_path("../data/#{PICKY_ENVIRONMENT}/library.csv", __FILE__))
34
- end
35
-
36
- def each
37
- instance = Struct.new :id, :title, :author, :year
38
- @csv.each do |row|
39
- yield instance.new *row[0..3]
40
- end
41
- end
42
-
43
- end
44
-
45
- # Define an index.
46
- #
47
- books_index = Index.new :books do
48
- source { Books.new }
49
- indexing removes_characters: /[^a-z0-9\s\/\-\_\:\"\&\.]/i,
50
- stopwords: /\b(and|the|of|it|in|for)\b/i,
51
- splits_text_on: /[\s\/\-\_\:\"\&\.]/
52
- category :title,
53
- similarity: Similarity::DoubleMetaphone.new(3),
54
- partial: Partial::Substring.new(from: 1) # Default is from: -3.
55
- category :author, partial: Partial::Substring.new(from: 1)
56
- category :year, partial: Partial::None.new
57
- end
58
-
59
- # Index and load on USR1 signal.
60
- #
61
- Signal.trap('USR1') do
62
- books_index.reindex # kill -USR1 <pid>
63
- end
64
-
65
- # Define a search over the books index.
66
- #
67
- books = Search.new books_index do
68
- searching substitutes_characters_with: CharacterSubstituters::WestEuropean.new, # Normalizes special user input, Ä -> Ae, ñ -> n etc.
69
- removes_characters: /[^\p{L}\p{N}\s\/\-\_\&\.\"\~\*\:\,]/i, # Picky needs control chars *"~:, to pass through.
70
- stopwords: /\b(and|the|of|it|in|for)\b/i,
71
- splits_text_on: /[\s\/\-\&]+/
72
-
73
- boost [:title, :author] => +3,
74
- [:title] => +1
75
- end
76
-
77
-
78
- # Client.
79
- #
80
-
81
20
  set :static, true
82
21
  set :public_folder, File.dirname(__FILE__)
83
22
  set :views, File.expand_path('../views', __FILE__)
@@ -97,7 +36,7 @@ class BookSearch < Sinatra::Application
97
36
  # populate the result hash with rendered models.
98
37
  #
99
38
  get '/search/full' do
100
- results = books.search params[:query], params[:ids] || 20, params[:offset] || 0
39
+ results = BooksSearch.search params[:query], params[:ids] || 20, params[:offset] || 0
101
40
  Picky.logger.info results
102
41
  results = results.to_hash
103
42
  results.extend Picky::Convenience
@@ -119,16 +58,8 @@ class BookSearch < Sinatra::Application
119
58
  # Updates the search count while the user is typing.
120
59
  #
121
60
  get '/search/live' do
122
- results = books.search params[:query], params[:ids] || 20, params[:offset] || 0
61
+ results = BooksSearch.search params[:query], params[:ids] || 20, params[:offset] || 0
123
62
  results.to_json
124
63
  end
125
64
 
126
- helpers do
127
-
128
- def js path
129
- "<script src='javascripts/#{path}.js' type='text/javascript'></script>"
130
- end
131
-
132
- end
133
-
134
65
  end
@@ -1,13 +1,12 @@
1
1
  !!!
2
2
  %html{ :lang => 'en' }
3
3
  %head
4
- %link{:href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
5
- %link{:href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
6
- = js 'jquery-1.5.0.min'
7
- = js 'history.min'
8
- = js 'history.adapter.jquery.min'
9
- = js 'picky.min'
10
-
4
+ %link{ :href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css" }/
5
+ %link{ :href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css" }/
6
+ %script{ :src => 'javascripts/jquery-1.5.0.min.js', :type => 'text/javascript' }
7
+ %script{ :src => 'javascripts/history.min.js', :type => 'text/javascript' }
8
+ %script{ :src => 'javascripts/history.adapter.jquery.min.js', :type => 'text/javascript' }
9
+ %script{ :src => 'javascripts/picky.min.js', :type => 'text/javascript' }
11
10
  %body
12
11
  %hgroup
13
12
  / Replace these headers with your code
@@ -49,12 +49,4 @@ end
49
49
  #
50
50
  get '/search/live' do
51
51
  BooksSearch.search_unparsed params[:query], :offset => params[:offset]
52
- end
53
-
54
- helpers do
55
-
56
- def js path
57
- "<script src='javascripts/#{path}.js' type='text/javascript'></script>"
58
- end
59
-
60
52
  end
@@ -1,13 +1,12 @@
1
1
  !!!
2
2
  %html{ :lang => 'en' }
3
3
  %head
4
- %link{:href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
5
- %link{:href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
6
- = js 'jquery-1.5.0.min'
7
- = js 'history.min'
8
- = js 'history.adapter.jquery.min'
9
- = js 'picky.min'
10
-
4
+ %link{ :href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css" }/
5
+ %link{ :href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css" }/
6
+ %script{ :src => 'javascripts/jquery-1.5.0.min.js', :type => 'text/javascript' }
7
+ %script{ :src => 'javascripts/history.min.js', :type => 'text/javascript' }
8
+ %script{ :src => 'javascripts/history.adapter.jquery.min.js', :type => 'text/javascript' }
9
+ %script{ :src => 'javascripts/picky.min.js', :type => 'text/javascript' }
11
10
  %body
12
11
  %hgroup
13
12
  / Replace these headers with your code
@@ -3,67 +3,16 @@
3
3
  require 'sinatra/base'
4
4
  require 'csv'
5
5
  require 'picky'
6
- require File.expand_path '../logging', __FILE__
6
+ require_relative 'logging'
7
+ require_relative 'books_index'
8
+ require_relative 'books_search'
7
9
 
8
10
  class BookSearch < Sinatra::Application
9
11
 
10
- # We do this so we don't have to type
11
- # Picky:: in front of everything.
12
- #
13
- include Picky
14
-
15
- # Data source.
16
- #
17
- class Books
18
-
19
- def initialize
20
- @csv = CSV.new File.open(File.expand_path("../data/#{PICKY_ENVIRONMENT}/library.csv", __FILE__))
21
- end
22
-
23
- def each
24
- instance = Struct.new :id, :title, :author, :year
25
- @csv.each do |row|
26
- yield instance.new *row[0..3]
27
- end
28
- end
29
-
30
- end
31
-
32
- # Define an index.
33
- #
34
- books_index = Index.new :books do
35
- source { Books.new }
36
- indexing removes_characters: /[^a-z0-9\s\/\-\_\:\"\&\.]/i,
37
- stopwords: /\b(and|the|of|it|in|for)\b/i,
38
- splits_text_on: /[\s\/\-\_\:\"\&\.]/
39
- category :title,
40
- similarity: Similarity::DoubleMetaphone.new(3),
41
- partial: Partial::Substring.new(from: 1) # Default is from: -3.
42
- category :author, partial: Partial::Substring.new(from: 1)
43
- category :year, partial: Partial::None.new
44
- end
45
-
46
- # Index and load on USR1 signal.
47
- #
48
- Signal.trap('USR1') do
49
- books_index.reindex # kill -USR1 <pid>
50
- end
51
-
52
- # Define a search over the books index.
53
- #
54
- books = Search.new books_index do
55
- searching substitutes_characters_with: CharacterSubstituters::WestEuropean.new, # Normalizes special user input, Ä -> Ae, ñ -> n etc.
56
- removes_characters: /[^\p{L}\p{N}\s\/\-\_\&\.\"\~\*\:\,]/i, # Picky needs control chars *"~:, to pass through.
57
- stopwords: /\b(and|the|of|it|in|for)\b/i,
58
- splits_text_on: /[\s\/\-\&]+/
59
- boost [:title, :author] => +3,
60
- [:title] => +1
61
- end
62
-
63
12
  # Route /books to the books search and log when searching.
64
13
  #
65
14
  get '/books' do
66
- results = books.search params[:query], params[:ids] || 20, params[:offset] || 0
15
+ results = BooksSearch.search params[:query], params[:ids] || 20, params[:offset] || 0
67
16
  Picky.logger.info results
68
17
  results.to_json
69
18
  end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ #
3
+
4
+ # Data source.
5
+ #
6
+ class Books
7
+
8
+ def initialize
9
+ @csv = CSV.new File.open(File.expand_path("../data/#{PICKY_ENVIRONMENT}/library.csv", __FILE__))
10
+ end
11
+
12
+ def each
13
+ instance = Struct.new :id, :title, :author, :year
14
+ @csv.each do |row|
15
+ yield instance.new *row[0..3]
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ # Define an index.
22
+ #
23
+ BooksIndex = Picky::Index.new :books do
24
+ source { Books.new }
25
+ indexing removes_characters: /[^a-z0-9\s\/\-\_\:\"\&\.]/i,
26
+ stopwords: /\b(and|the|of|it|in|for)\b/i,
27
+ splits_text_on: /[\s\/\-\_\:\"\&\.]/
28
+ category :title,
29
+ similarity: Picky::Similarity::DoubleMetaphone.new(3),
30
+ partial: Picky::Partial::Substring.new(from: 1) # Default is from: -3.
31
+ category :author, partial: Picky::Partial::Substring.new(from: 1)
32
+ category :year, partial: Picky::Partial::None.new
33
+ end
34
+
35
+ # Index and load on USR1 signal.
36
+ #
37
+ Signal.trap('USR1') do
38
+ BooksIndex.reindex # kill -USR1 <pid>
39
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ #
3
+
4
+ # Define a search over the books index.
5
+ #
6
+ BooksSearch = Picky::Search.new BooksIndex do
7
+ # Normalizes special user input, Ä -> Ae, ñ -> n etc.
8
+ searching substitutes_characters_with: Picky::CharacterSubstituters::WestEuropean.new,
9
+ # Picky needs control chars *"~:, to pass through.
10
+ removes_characters: /[^\p{L}\p{N}\s\/\-\_\&\.\"\~\*\:\,]/i,
11
+ stopwords: /\b(and|the|of|it|in|for)\b/i,
12
+ splits_text_on: /[\s\/\-\&]+/
13
+
14
+ boost [:title, :author] => +3,
15
+ [:title] => +1
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.1
4
+ version: 4.12.2
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: 2012-11-26 00:00:00.000000000 Z
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 4.12.1
37
+ version: 4.12.2
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 4.12.1
45
+ version: 4.12.2
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: picky-client
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 4.12.1
53
+ version: 4.12.2
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 4.12.1
61
+ version: 4.12.2
62
62
  description: Generators for Picky.
63
63
  email: florian.hanke+picky-generators@gmail.com
64
64
  executables:
@@ -110,6 +110,8 @@ files:
110
110
  - prototypes/shared/both/data/production/library.csv
111
111
  - prototypes/shared/both/data/test/library.csv
112
112
  - prototypes/shared/client/book.rb
113
+ - prototypes/shared/server/books_index.rb
114
+ - prototypes/shared/server/books_search.rb
113
115
  - prototypes/shared/server/config.ru
114
116
  - prototypes/shared/server/logging.rb
115
117
  - prototypes/shared/server/spec/spec_helper.rb