Module: Cloudpress

Defined in:
lib/cloudpress.rb,
lib/cloudpress/engine.rb,
lib/cloudpress/version.rb,
app/models/cloudpress/post.rb,
lib/cloudpress/dropbox/file.rb,
lib/cloudpress/renderers/tag.rb,
app/models/cloudpress/archive.rb,
lib/cloudpress/dropbox/client.rb,
lib/cloudpress/renderers/post.rb,
lib/cloudpress/renderers/tags.rb,
lib/cloudpress/dropbox/cleaner.rb,
lib/cloudpress/renderers/flash.rb,
lib/cloudpress/renderers/posts.rb,
lib/cloudpress/dropbox/connector.rb,
lib/cloudpress/dropbox/directory.rb,
lib/cloudpress/renderers/archive.rb,
lib/cloudpress/renderers/archives.rb,
app/jobs/cloudpress/update_posts_job.rb,
app/helpers/cloudpress/renderer_helper.rb,
app/controllers/cloudpress/tags_controller.rb,
app/controllers/cloudpress/posts_controller.rb,
app/controllers/cloudpress/archives_controller.rb,
app/controllers/cloudpress/application_controller.rb,
app/controllers/cloudpress/drafts/posts_controller.rb,
lib/generators/cloudpress/initializer/initializer_generator.rb

Defined Under Namespace

Modules: Drafts, Dropbox, RendererHelper, Renderers Classes: ApplicationController, Archive, ArchivesController, Engine, InitializerGenerator, Post, PostsController, TagsController, UpdatePostsJob

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Class Method Details

.base_pathObject



52
53
54
# File 'lib/cloudpress.rb', line 52

def base_path
  "/#{config.base_path}"
end

.clientObject



100
101
102
# File 'lib/cloudpress.rb', line 100

def client
  @client ||= Cloudpress::Dropbox::Client.new(config.app_token)
end

.configObject



33
34
35
# File 'lib/cloudpress.rb', line 33

def config
  @config ? @config : configure
end

.configure {|@config| ... } ⇒ Object

Yields:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cloudpress.rb', line 37

def configure &block
  @config = ActiveSupport::OrderedOptions.new
  @config.app_key        = nil
  @config.app_secret     = nil
  @config.app_token      = nil
  @config.base_path      = 'cloudpress'
  @config.live_path      = 'live'
  @config.draft_path     = 'draft'
  @config.draft_user     = nil
  @config.draft_password = nil
  @config.markdown_renderer = Redcarpet::Markdown.new(Formatters::HTMLWithPygments, fenced_code_blocks: true)
  yield(@config) if block_given?
  @config
end

.draft_auth_credentialsObject



93
94
95
96
97
98
# File 'lib/cloudpress.rb', line 93

def draft_auth_credentials
  @draft_auth_credentials ||= {
    name:     config.draft_user,
    password: config.draft_password
  }
end

.draft_pathObject



64
65
66
# File 'lib/cloudpress.rb', line 64

def draft_path
  [base_path, config.draft_path].join('/')
end

.file_indexObject



82
83
84
85
86
87
# File 'lib/cloudpress.rb', line 82

def file_index
  @file_index ||= {
    live: Cloudpress::Dropbox::Directory.new(client, live_path, :live),
    draft: Cloudpress::Dropbox::Directory.new(client, draft_path, :draft)
  }
end

.import!Object



74
75
76
# File 'lib/cloudpress.rb', line 74

def import!
  file_index.values.each {|x| x.import!}
end

.live_pathObject



60
61
62
# File 'lib/cloudpress.rb', line 60

def live_path
  [base_path, config.live_path].join('/')
end

.local_pathsObject



116
117
118
# File 'lib/cloudpress.rb', line 116

def local_paths
  Cloudpress::Post.pluck(:file_path)
end

.protect_drafts?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/cloudpress.rb', line 89

def protect_drafts?
  draft_auth_credentials.keys.compact.any?
end

.purge!Object



78
79
80
# File 'lib/cloudpress.rb', line 78

def purge!
  Cloudpress::Dropbox::Cleaner.new(remote_paths, local_paths).clean!
end

.reload!Object



56
57
58
# File 'lib/cloudpress.rb', line 56

def reload!
  @file_index = nil
end

.remote_pathsObject



112
113
114
# File 'lib/cloudpress.rb', line 112

def remote_paths
  file_index.values.map {|x| x.paths }.flatten
end

.unauthorized?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/cloudpress.rb', line 108

def unauthorized?
  config.app_token.blank?
end

.unconfigured?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/cloudpress.rb', line 104

def unconfigured?
  config.app_key.blank? || config.app_secret.blank?
end

.update!Object



68
69
70
71
72
# File 'lib/cloudpress.rb', line 68

def update!
  reload!
  import!
  purge!
end