cloudpress 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +39 -0
  7. data/Rakefile +30 -0
  8. data/app/assets/cloudpress/cloudpress.css.sass +1 -0
  9. data/app/assets/cloudpress/code/railscasts.css +70 -0
  10. data/app/controllers/cloudpress/application_controller.rb +12 -0
  11. data/app/controllers/cloudpress/archives_controller.rb +34 -0
  12. data/app/controllers/cloudpress/posts_controller.rb +23 -0
  13. data/app/controllers/cloudpress/tags_controller.rb +20 -0
  14. data/app/helpers/cloudpress/renderer_helper.rb +23 -0
  15. data/app/jobs/cloudpress/update_posts_job.rb +9 -0
  16. data/app/models/cloudpress/archive.rb +50 -0
  17. data/app/models/cloudpress/post.rb +65 -0
  18. data/app/views/cloudpress/archives/_archive.html.slim +3 -0
  19. data/app/views/cloudpress/archives/_archives.html.slim +2 -0
  20. data/app/views/cloudpress/archives/_month.html.slim +2 -0
  21. data/app/views/cloudpress/archives/show.html.slim +1 -0
  22. data/app/views/cloudpress/posts/_intro.html.slim +9 -0
  23. data/app/views/cloudpress/posts/_post.html.slim +8 -0
  24. data/app/views/cloudpress/posts/index.html.slim +1 -0
  25. data/app/views/cloudpress/posts/show.html.slim +1 -0
  26. data/app/views/cloudpress/tags/_tag.html.slim +2 -0
  27. data/app/views/cloudpress/tags/_tags.html.slim +2 -0
  28. data/app/views/cloudpress/tags/show.html.slim +1 -0
  29. data/bin/console +14 -0
  30. data/bin/rails +12 -0
  31. data/bin/setup +7 -0
  32. data/cloudpress.gemspec +35 -0
  33. data/config/initializers/tag_extensions.rb +4 -0
  34. data/config/routes.rb +9 -0
  35. data/db/migrate/20150309115639_create_cloudpress_posts.rb +19 -0
  36. data/db/migrate/20150315192521_create_tags_table.rb +30 -0
  37. data/db/migrate/20150315193206_create_friendly_id_slugs.rb +15 -0
  38. data/db/migrate/20150317121651_add_slug_to_tags.rb +6 -0
  39. data/db/migrate/20150317122608_add_taggings_counter_cache.rb +14 -0
  40. data/lib/cloudpress.rb +105 -0
  41. data/lib/cloudpress/dropbox/cleaner.rb +20 -0
  42. data/lib/cloudpress/dropbox/client.rb +15 -0
  43. data/lib/cloudpress/dropbox/connector.rb +24 -0
  44. data/lib/cloudpress/dropbox/directory.rb +57 -0
  45. data/lib/cloudpress/dropbox/file.rb +57 -0
  46. data/lib/cloudpress/engine.rb +10 -0
  47. data/lib/cloudpress/formatters/html_with_pygments.rb +7 -0
  48. data/lib/cloudpress/renderers/archive.rb +18 -0
  49. data/lib/cloudpress/renderers/archives.rb +24 -0
  50. data/lib/cloudpress/renderers/post.rb +39 -0
  51. data/lib/cloudpress/renderers/posts.rb +38 -0
  52. data/lib/cloudpress/renderers/tag.rb +18 -0
  53. data/lib/cloudpress/renderers/tags.rb +24 -0
  54. data/lib/cloudpress/version.rb +3 -0
  55. data/lib/generators/cloudpress/initializer/USAGE +8 -0
  56. data/lib/generators/cloudpress/initializer/initializer_generator.rb +32 -0
  57. metadata +283 -0
@@ -0,0 +1,57 @@
1
+ module Cloudpress
2
+ module Dropbox
3
+ class File
4
+
5
+ attr_reader :path, :revision, :state
6
+
7
+ def initialize(path, revision, state)
8
+ @path = path
9
+ @revision = revision
10
+ @state = state
11
+ end
12
+
13
+ def import!
14
+ local_copy.update_from_dropbox(self) if changed?
15
+ end
16
+
17
+ def remote_file
18
+ @remote_file ||= Cloudpress.client.connection.get_file(@path)
19
+ end
20
+
21
+ def local_copy
22
+ @local_copy ||= Cloudpress::Post.where(file_path: @path).first_or_initialize
23
+ end
24
+
25
+ def metadata
26
+ @metadata ||= metadown.metadata
27
+ end
28
+
29
+ def body
30
+ @body ||= metadown.output
31
+ end
32
+
33
+ def title
34
+ metadata['title'] || @path.split('/').last.split('.').first.titleize
35
+ end
36
+
37
+ def changed?
38
+ !persisted? || revision_changed?
39
+ end
40
+
41
+ private
42
+
43
+ def persisted?
44
+ local_copy.persisted?
45
+ end
46
+
47
+ def revision_changed?
48
+ local_copy.revision != @revision
49
+ end
50
+
51
+ def metadown
52
+ @metadown ||= Metadown.render(remote_file, Cloudpress.config.markdown_renderer)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+ module Cloudpress
2
+ class Engine < Rails::Engine
3
+ engine_name 'cloudpress'
4
+ isolate_namespace Cloudpress
5
+
6
+ config.to_prepare do
7
+ ApplicationController.helper Cloudpress::RendererHelper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Formatters
2
+ class HTMLWithPygments < Metadown::Renderer
3
+ def block_code(code, language)
4
+ Pygments.highlight(code, :lexer => language)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module Cloudpress
2
+ module Renderers
3
+ class Archive
4
+
5
+ attr_reader :archive
6
+
7
+ def initialize(context, archive)
8
+ @context = context
9
+ @archive = archive
10
+ end
11
+
12
+ def render
13
+ @context.render(partial: 'cloudpress/archives/archive', locals: {renderer: self})
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module Cloudpress
2
+ module Renderers
3
+ class Archives
4
+
5
+ attr_reader :archives
6
+
7
+ def initialize(context, archives)
8
+ @context = context
9
+ @archives = archives
10
+ end
11
+
12
+ def wrapped_archives
13
+ @wrapped_archives ||= archives.map {|archive| Cloudpress::Renderers::Archive.new(@context, archive)}
14
+ end
15
+
16
+ def render
17
+ @context.render(layout: 'cloudpress/archives/archives', locals: {renderer: self}) do
18
+ wrapped_archives.map(&:render).join("\n").html_safe
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ module Cloudpress
2
+ module Renderers
3
+ class Post
4
+
5
+ attr_reader :post, :options
6
+ attr_accessor :content
7
+
8
+ def initialize(context, post, options={})
9
+ @context = context
10
+ @post = post
11
+ @options = options.reverse_merge default_options
12
+ end
13
+
14
+ def render(&block)
15
+ @context.render layout: template, locals: {renderer: self} do
16
+ content
17
+ end.html_safe
18
+ end
19
+
20
+ def tags?
21
+ options[:tags]
22
+ end
23
+
24
+ private
25
+
26
+ def template
27
+ "/cloudpress/posts/#{options[:template]}"
28
+ end
29
+
30
+ def default_options
31
+ {
32
+ template: :post,
33
+ tags: true
34
+ }
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ module Cloudpress
2
+ module Renderers
3
+ class Posts
4
+
5
+ attr_reader :posts, :options
6
+
7
+ def initialize(context, posts, options={})
8
+ @context = context
9
+ @posts = posts
10
+ @options = options.reverse_merge default_options
11
+ end
12
+
13
+ def wrapped_posts
14
+ @wrapped_posts ||= posts.map {|post| Cloudpress::Renderers::Post.new(@context, post, options)}
15
+ end
16
+
17
+ def render
18
+ @context.content_tag(:div, id: 'post-list') do
19
+ wrapped_posts.map(&:render).join("\n").html_safe
20
+ end
21
+ end
22
+
23
+ def tags?
24
+ options[:tags]
25
+ end
26
+
27
+ private
28
+
29
+ def default_options
30
+ {
31
+ template: :intro,
32
+ tags: true
33
+ }
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ module Cloudpress
2
+ module Renderers
3
+ class Tag
4
+
5
+ attr_reader :tag
6
+
7
+ def initialize(context, tag)
8
+ @context = context
9
+ @tag = tag
10
+ end
11
+
12
+ def render
13
+ @context.render(partial: 'cloudpress/tags/tag', locals: {renderer: self})
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module Cloudpress
2
+ module Renderers
3
+ class Tags
4
+
5
+ attr_reader :tags
6
+
7
+ def initialize(context, tags)
8
+ @context = context
9
+ @tags = [tags].flatten.compact
10
+ end
11
+
12
+ def render
13
+ @context.render layout: 'cloudpress/tags/tags', locals: {renderer: self} do
14
+ wrapped_tags.map(&:render).join("\n").html_safe
15
+ end
16
+ end
17
+
18
+ def wrapped_tags
19
+ @wrapped_tags ||= tags.map {|tag| Cloudpress::Renderers::Tag.new(@context, tag)}
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Cloudpress
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ This will install cloudpresses initializer, it will require you to visit the dropbox app console
6
+
7
+ This will create:
8
+ config/cloudpress.rb
@@ -0,0 +1,32 @@
1
+ module Cloudpress
2
+ class InitializerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_initializer_file
6
+ if Cloudpress.unconfigured?
7
+ say "Cloudpress is unconfigured, please enter the following:"
8
+ app_key = ask "Application Key:"
9
+ app_secret = ask "Application Secret:"
10
+ else
11
+ app_key = Cloudpress.config.app_key
12
+ app_secret = Cloudpress.config.app_secret
13
+ end
14
+
15
+ connector = Cloudpress::Dropbox::Connector.new(app_key, app_secret)
16
+
17
+ say "Please visit the following URL: #{connector.authorize_url}"
18
+ code = ask("Enter the code:")
19
+ token, _uid = connector.authorize!(code)
20
+
21
+ initializer 'cloudpress.rb' do
22
+ <<-EOF
23
+ Cloudpress.configure do |config|
24
+ config.app_id = "#{app_key}"
25
+ config.app_secret = "#{app_secret}"
26
+ config.app_token = "#{token}"
27
+ end
28
+ EOF
29
+ end
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,283 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudpress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Carlile
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dropbox-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: metadown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pygments.rb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: kaminari
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: builder
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: groupdate
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: slim
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: acts-as-taggable-on
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: friendly_id
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 4.2.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 4.2.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: bundler
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.8'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.8'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '10.0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '10.0'
195
+ description:
196
+ email:
197
+ - adam@benchmedia.co.uk
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".gitignore"
203
+ - ".travis.yml"
204
+ - Gemfile
205
+ - LICENSE.txt
206
+ - README.md
207
+ - Rakefile
208
+ - app/.DS_Store
209
+ - app/assets/cloudpress/cloudpress.css.sass
210
+ - app/assets/cloudpress/code/railscasts.css
211
+ - app/controllers/cloudpress/application_controller.rb
212
+ - app/controllers/cloudpress/archives_controller.rb
213
+ - app/controllers/cloudpress/posts_controller.rb
214
+ - app/controllers/cloudpress/tags_controller.rb
215
+ - app/helpers/cloudpress/renderer_helper.rb
216
+ - app/jobs/cloudpress/update_posts_job.rb
217
+ - app/models/cloudpress/archive.rb
218
+ - app/models/cloudpress/post.rb
219
+ - app/views/cloudpress/archives/_archive.html.slim
220
+ - app/views/cloudpress/archives/_archives.html.slim
221
+ - app/views/cloudpress/archives/_month.html.slim
222
+ - app/views/cloudpress/archives/show.html.slim
223
+ - app/views/cloudpress/posts/_intro.html.slim
224
+ - app/views/cloudpress/posts/_post.html.slim
225
+ - app/views/cloudpress/posts/index.html.slim
226
+ - app/views/cloudpress/posts/show.html.slim
227
+ - app/views/cloudpress/tags/_tag.html.slim
228
+ - app/views/cloudpress/tags/_tags.html.slim
229
+ - app/views/cloudpress/tags/show.html.slim
230
+ - bin/console
231
+ - bin/rails
232
+ - bin/setup
233
+ - cloudpress.gemspec
234
+ - config/initializers/tag_extensions.rb
235
+ - config/routes.rb
236
+ - db/migrate/20150309115639_create_cloudpress_posts.rb
237
+ - db/migrate/20150315192521_create_tags_table.rb
238
+ - db/migrate/20150315193206_create_friendly_id_slugs.rb
239
+ - db/migrate/20150317121651_add_slug_to_tags.rb
240
+ - db/migrate/20150317122608_add_taggings_counter_cache.rb
241
+ - lib/cloudpress.rb
242
+ - lib/cloudpress/dropbox/cleaner.rb
243
+ - lib/cloudpress/dropbox/client.rb
244
+ - lib/cloudpress/dropbox/connector.rb
245
+ - lib/cloudpress/dropbox/directory.rb
246
+ - lib/cloudpress/dropbox/file.rb
247
+ - lib/cloudpress/engine.rb
248
+ - lib/cloudpress/formatters/html_with_pygments.rb
249
+ - lib/cloudpress/renderers/archive.rb
250
+ - lib/cloudpress/renderers/archives.rb
251
+ - lib/cloudpress/renderers/post.rb
252
+ - lib/cloudpress/renderers/posts.rb
253
+ - lib/cloudpress/renderers/tag.rb
254
+ - lib/cloudpress/renderers/tags.rb
255
+ - lib/cloudpress/version.rb
256
+ - lib/generators/.DS_Store
257
+ - lib/generators/cloudpress/initializer/USAGE
258
+ - lib/generators/cloudpress/initializer/initializer_generator.rb
259
+ homepage: http://github.com/adamcarlile/cloudpress
260
+ licenses:
261
+ - MIT
262
+ metadata: {}
263
+ post_install_message:
264
+ rdoc_options: []
265
+ require_paths:
266
+ - lib
267
+ required_ruby_version: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ required_rubygems_version: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - ">="
275
+ - !ruby/object:Gem::Version
276
+ version: '0'
277
+ requirements: []
278
+ rubyforge_project:
279
+ rubygems_version: 2.4.5
280
+ signing_key:
281
+ specification_version: 4
282
+ summary: A blogging framework that uses dropbox as it's storage engine
283
+ test_files: []