octodmin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/.bowerrc +3 -0
  3. data/.gitignore +24 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +4 -0
  7. data/Gemfile +17 -0
  8. data/LICENSE.md +22 -0
  9. data/README.md +117 -0
  10. data/Rakefile +38 -0
  11. data/_config.yml +27 -0
  12. data/_deploy.yml +13 -0
  13. data/app/.DS_Store +0 -0
  14. data/app/assets/.DS_Store +0 -0
  15. data/app/assets/javascripts/.DS_Store +0 -0
  16. data/app/assets/javascripts/app.js.coffee +13 -0
  17. data/app/assets/javascripts/components/header.js.cjsx +69 -0
  18. data/app/assets/javascripts/components/posts.js.cjsx +309 -0
  19. data/app/assets/javascripts/components/router.js.cjsx +56 -0
  20. data/app/assets/stylesheets/.DS_Store +0 -0
  21. data/app/assets/stylesheets/app.scss +75 -0
  22. data/app/config/environment.rb +7 -0
  23. data/app/config/routes.rb +19 -0
  24. data/app/config/sprockets.rb +36 -0
  25. data/app/controllers/deploys/create.rb +20 -0
  26. data/app/controllers/frontend/index.rb +8 -0
  27. data/app/controllers/posts/create.rb +18 -0
  28. data/app/controllers/posts/destroy.rb +14 -0
  29. data/app/controllers/posts/index.rb +13 -0
  30. data/app/controllers/posts/restore.rb +14 -0
  31. data/app/controllers/posts/revert.rb +14 -0
  32. data/app/controllers/posts/show.rb +13 -0
  33. data/app/controllers/posts/update.rb +23 -0
  34. data/app/controllers/site/show.rb +12 -0
  35. data/app/controllers/syncs/create.rb +62 -0
  36. data/app/controllers/version/show.rb +12 -0
  37. data/app/octodmin.rb +56 -0
  38. data/app/public/.DS_Store +0 -0
  39. data/app/public/assets/app.css +7960 -0
  40. data/app/public/assets/app.css.gz +7960 -0
  41. data/app/public/assets/app.js +39181 -0
  42. data/app/public/assets/app.js.gz +39181 -0
  43. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  44. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  45. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +288 -0
  46. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.svg.gz +288 -0
  47. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  48. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  49. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  50. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  51. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
  52. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2.gz +0 -0
  53. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  54. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  55. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
  56. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.svg.gz +288 -0
  57. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  58. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  59. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  60. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  61. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  62. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff2.gz +0 -0
  63. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot +0 -0
  64. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot.gz +0 -0
  65. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.svg +288 -0
  66. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.svg.gz +288 -0
  67. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  68. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf.gz +0 -0
  69. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff +0 -0
  70. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff.gz +0 -0
  71. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 +0 -0
  72. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2.gz +0 -0
  73. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.eot +0 -0
  74. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  75. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.svg +288 -0
  76. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.svg.gz +288 -0
  77. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.ttf +0 -0
  78. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  79. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff +0 -0
  80. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  81. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff2 +0 -0
  82. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff2.gz +0 -0
  83. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.eot +0 -0
  84. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  85. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.svg +229 -0
  86. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.svg.gz +229 -0
  87. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  88. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  89. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.woff +0 -0
  90. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  91. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.eot +0 -0
  92. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.eot.gz +0 -0
  93. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.svg +565 -0
  94. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.svg.gz +565 -0
  95. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.ttf +0 -0
  96. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.ttf.gz +0 -0
  97. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff +0 -0
  98. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff.gz +0 -0
  99. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff2 +0 -0
  100. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff2.gz +0 -0
  101. data/app/public/assets/manifest.json +1 -0
  102. data/app/templates/application.html.erb +13 -0
  103. data/app/templates/frontend/index.html.erb +1 -0
  104. data/app/views/application_layout.rb +5 -0
  105. data/app/views/deploys/create.rb +10 -0
  106. data/app/views/frontend/index.rb +5 -0
  107. data/app/views/posts/create.rb +10 -0
  108. data/app/views/posts/destroy.rb +10 -0
  109. data/app/views/posts/index.rb +10 -0
  110. data/app/views/posts/restore.rb +10 -0
  111. data/app/views/posts/revert.rb +10 -0
  112. data/app/views/posts/show.rb +10 -0
  113. data/app/views/posts/update.rb +10 -0
  114. data/app/views/site/show.rb +10 -0
  115. data/app/views/syncs/create.rb +10 -0
  116. data/app/views/version/show.rb +10 -0
  117. data/bower.json +16 -0
  118. data/config.ru +5 -0
  119. data/lib/octodmin/app.rb +2 -0
  120. data/lib/octodmin/post.rb +161 -0
  121. data/lib/octodmin/site.rb +61 -0
  122. data/lib/octodmin/version.rb +3 -0
  123. data/lib/octodmin.rb +7 -0
  124. data/octodmin.gemspec +24 -0
  125. data/sample/.gitignore +2 -0
  126. data/sample/_includes/footer.html +55 -0
  127. data/sample/_includes/head.html +12 -0
  128. data/sample/_includes/header.html +27 -0
  129. data/sample/_layouts/default.html +20 -0
  130. data/sample/_layouts/page.html +14 -0
  131. data/sample/_layouts/post.html +15 -0
  132. data/sample/_posts/2015-01-29-welcome-to-jekyll.markdown +25 -0
  133. data/sample/_posts/2015-01-30-test.markdown +10 -0
  134. data/sample/_sass/_base.scss +204 -0
  135. data/sample/_sass/_layout.scss +236 -0
  136. data/sample/_sass/_syntax-highlighting.scss +67 -0
  137. data/sample/_templates/draft +4 -0
  138. data/sample/_templates/page +4 -0
  139. data/sample/_templates/post +8 -0
  140. data/sample/about.md +11 -0
  141. data/sample/css/main.scss +52 -0
  142. data/sample/feed.xml +30 -0
  143. data/sample/index.html +23 -0
  144. data/spec/api/deploys_spec.rb +36 -0
  145. data/spec/api/posts_spec.rb +411 -0
  146. data/spec/api/site_spec.rb +18 -0
  147. data/spec/api/syncs_spec.rb +81 -0
  148. data/spec/api/version_spec.rb +14 -0
  149. data/spec/frontend/assets_spec.rb +23 -0
  150. data/spec/frontend/home_spec.rb +16 -0
  151. data/spec/spec_helper.rb +31 -0
  152. data/tmp/.keep +0 -0
  153. metadata +259 -0
@@ -0,0 +1,62 @@
1
+ module Octodmin::Controllers::Syncs
2
+ class Create
3
+ include Octodmin::Action
4
+ expose :message
5
+
6
+ def call(params)
7
+ self.format = :json
8
+
9
+ site = Octodmin::Site.new
10
+ git = Git.open(Octodmin::App.dir)
11
+
12
+ # Add posts only to commit stage
13
+ stage(site, git)
14
+
15
+ # Compute staged paths
16
+ staged = paths(site, git)
17
+
18
+ # Pull changes
19
+ git.pull
20
+
21
+ # Commit and push changes if any
22
+ if staged.any?
23
+ @message = "Octodmin sync for #{staged.count} file#{"s" if staged.count > 1}"
24
+ @message += "\n\n#{staged.join("\n")}"
25
+
26
+ git.commit(@message)
27
+ git.push
28
+ else
29
+ @message = "Everything is up-to-date"
30
+ end
31
+ rescue Git::GitExecuteError => e
32
+ halt 400, JSON.dump(errors: [e.message])
33
+ ensure
34
+ git.reset(".")
35
+ end
36
+
37
+ private
38
+
39
+ def stage(site, git)
40
+ deleted = site.status.deleted.keys.map { |path| File.join(Octodmin::App.dir, path) }
41
+
42
+ site.posts.each do |post|
43
+ path = File.join(site.source, post.path)
44
+ git.add(path) unless deleted.include?(path)
45
+ end
46
+ end
47
+
48
+ def paths(site, git)
49
+ status = site.reset.status
50
+
51
+ paths = (
52
+ status.changed.keys +
53
+ status.added.keys +
54
+ status.deleted.keys
55
+ ).map { |path| File.join(Octodmin::App.dir, path) }
56
+
57
+ site.posts.select do |post|
58
+ paths.any? { |path| path.end_with?(post.path) }
59
+ end.map(&:path)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ module Octodmin::Controllers::Version
2
+ class Show
3
+ include Octodmin::Action
4
+ expose :version
5
+
6
+ def call(params)
7
+ self.format = :json
8
+
9
+ @version = Octodmin::VERSION
10
+ end
11
+ end
12
+ end
data/app/octodmin.rb ADDED
@@ -0,0 +1,56 @@
1
+ ENV["RACK_ENV"] = ENV["LOTUS_ENV"] ||= "production"
2
+
3
+ require "octodmin"
4
+ require "lotus"
5
+ require "git"
6
+ require "json"
7
+ require "octopress-deploy"
8
+
9
+ begin
10
+ require_relative "./config/sprockets"
11
+ rescue LoadError
12
+ end
13
+
14
+ module Octodmin
15
+ class App < Lotus::Application
16
+ class << self
17
+ attr_accessor :dir
18
+ end
19
+
20
+ configure do
21
+ root __dir__
22
+
23
+ routes "config/routes"
24
+ load_paths << [
25
+ "controllers",
26
+ "views",
27
+ ]
28
+
29
+ layout :application
30
+ end
31
+
32
+ # :nocov:
33
+ configure :production do
34
+ assets << ["public"]
35
+ serve_assets true
36
+ handle_exceptions false
37
+ end
38
+
39
+ configure :development do
40
+ handle_exceptions false
41
+ end
42
+ # :nocov:
43
+
44
+ configure :test do
45
+ handle_exceptions false
46
+ end
47
+
48
+ def initialize(dir = nil)
49
+ raise "Please specify root dir" unless dir
50
+ raise "Attempt to change root dir" if !self.class.dir.nil? && self.class.dir != dir
51
+
52
+ self.class.dir = dir
53
+ super()
54
+ end
55
+ end
56
+ end
Binary file