bunto-admin 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ module BuntoAdmin
2
+ class Server < Sinatra::Base
3
+ namespace "/pages" do
4
+ get "/*?/?:path.:ext" do
5
+ ensure_requested_file
6
+ json requested_file.to_api(:include_content => true)
7
+ end
8
+
9
+ get "/?*" do
10
+ ensure_directory
11
+ json entries.map(&:to_api)
12
+ end
13
+
14
+ put "/*?/?:path.:ext" do
15
+ ensure_html_content
16
+
17
+ if renamed?
18
+ ensure_requested_file
19
+ delete_file path
20
+ end
21
+
22
+ write_file write_path, page_body
23
+
24
+ json written_file.to_api(:include_content => true)
25
+ end
26
+
27
+ delete "/*?/?:path.:ext" do
28
+ ensure_requested_file
29
+ delete_file path
30
+ content_type :json
31
+ status 200
32
+ halt
33
+ end
34
+
35
+ private
36
+
37
+ def ensure_html_content
38
+ return if html_content?
39
+ content_type :json
40
+ halt 422, json("error_message" => "Invalid file extension for pages")
41
+ end
42
+
43
+ def html_content?
44
+ page = BuntoAdmin::PageWithoutAFile.new(
45
+ site,
46
+ site.source,
47
+ "",
48
+ request_payload["path"] || filename
49
+ )
50
+ page.data = request_payload["front_matter"]
51
+ page.html?
52
+ end
53
+
54
+ def pages
55
+ site.pages.select(&:html?)
56
+ end
57
+
58
+ def directory_pages
59
+ pages.find_all do |p|
60
+ sanitized_path(File.dirname(p.path)) == directory_path
61
+ end
62
+ end
63
+
64
+ # returns relative path of root level directories that contain pages
65
+ def directory_paths
66
+ pages.map { |p| File.dirname(p.path).split("/")[0] }.uniq
67
+ end
68
+
69
+ def entries
70
+ args = {
71
+ :base => site.source,
72
+ :content_type => "pages",
73
+ :splat => params["splat"].first,
74
+ }
75
+ # get all directories inside the requested directory
76
+ directory = BuntoAdmin::Directory.new(directory_path, args)
77
+ directories = directory.directories
78
+
79
+ # exclude root level directories which do not have pages
80
+ if params["splat"].first.empty?
81
+ directories = directories.select do |d|
82
+ directory_paths.include? d.name.to_s
83
+ end
84
+ end
85
+ # merge directories with the pages at the same level
86
+ directories.concat(directory_pages)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,61 @@
1
+ module BuntoAdmin
2
+ class Server < Sinatra::Base
3
+ namespace "/static_files" do
4
+ get do
5
+ json static_files.map(&:to_api)
6
+ end
7
+
8
+ get "/*" do
9
+ if requested_file
10
+ json requested_file.to_api(:include_content => true)
11
+ elsif !static_files_for_path.empty?
12
+ json static_files_for_path.map(&:to_api)
13
+ else
14
+ render_404
15
+ end
16
+ end
17
+
18
+ put "/*" do
19
+ if renamed?
20
+ ensure_requested_file
21
+ delete_file path
22
+ end
23
+
24
+ write_file(write_path, static_file_body)
25
+ json written_file.to_api(:include_content => true)
26
+ end
27
+
28
+ delete "/*" do
29
+ ensure_requested_file
30
+ delete_file path
31
+ content_type :json
32
+ status 200
33
+ halt
34
+ end
35
+
36
+ private
37
+
38
+ def static_file_body
39
+ if !request_payload["raw_content"].to_s.empty?
40
+ request_payload["raw_content"].to_s
41
+ else
42
+ Base64.decode64 request_payload["encoded_content"].to_s
43
+ end
44
+ end
45
+
46
+ def static_files
47
+ site.static_files
48
+ end
49
+
50
+ def file_list_dir(path) end
51
+
52
+ def static_files_for_path
53
+ # Joined with / to ensure user can't do partial paths
54
+ base_path = File.join(path, "/")
55
+ static_files.select do |f|
56
+ f.path.start_with? base_path
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ module BuntoAdmin
2
+ class StaticServer < Sinatra::Base
3
+ set :public_dir, File.expand_path("./public", File.dirname(__FILE__))
4
+
5
+ MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build.".freeze
6
+
7
+ # Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
8
+ get "/*" do
9
+ send_file index_path
10
+ end
11
+
12
+ # Provide a descriptive error message in dev. if frontend is not build
13
+ not_found do
14
+ status 404
15
+ MUST_BUILD_MESSAGE if settings.development? || settings.test?
16
+ end
17
+
18
+ private
19
+
20
+ def index_path
21
+ @index_path ||= File.join(settings.public_folder, "index.html")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ module BuntoAdmin
2
+ # Abstract module to be included in Convertible and Document to provide
3
+ # additional, URL-specific functionality without duplicating logic
4
+ module URLable
5
+
6
+ # Absolute URL to the HTTP(S) rendered/served representation of this resource
7
+ def http_url
8
+ return if is_a?(Bunto::Collection) || is_a?(BuntoAdmin::DataFile)
9
+ return if is_a?(Bunto::Document) && !collection.write?
10
+ @http_url ||= Addressable::URI.new(
11
+ :scheme => scheme, :host => host, :port => port,
12
+ :path => path_with_base(BuntoAdmin.site.config["baseurl"], url)
13
+ ).normalize.to_s
14
+ end
15
+
16
+ # Absolute URL to the API representation of this resource
17
+ def api_url
18
+ @api_url ||= Addressable::URI.new(
19
+ :scheme => scheme, :host => host, :port => port,
20
+ :path => path_with_base("/_api", resource_path)
21
+ ).normalize.to_s
22
+ end
23
+
24
+ def entries_url
25
+ return unless is_a?(Bunto::Collection)
26
+ "#{api_url}/entries"
27
+ end
28
+
29
+ private
30
+
31
+ # URL path relative to `_api/` to retreive the given resource via the API
32
+ # Note: we can't use a case statement here, because === doesn't like includes
33
+ def resource_path
34
+ if is_a?(Bunto::Document)
35
+ "/collections/#{relative_path.sub(%r!\A_!, "")}"
36
+ elsif is_a?(Bunto::Collection)
37
+ "/collections/#{label}"
38
+ elsif is_a?(BuntoAdmin::DataFile)
39
+ "/data/#{relative_path}"
40
+ elsif is_a?(Bunto::StaticFile)
41
+ "/static_files/#{relative_path}"
42
+ elsif is_a?(Bunto::Page)
43
+ "/pages/#{relative_path}"
44
+ end
45
+ end
46
+
47
+ # URI.join doesn't like joining two relative paths, and File.join may join
48
+ # with `\` rather than with `/` on windows
49
+ def path_with_base(base, path)
50
+ [base, path].join("/").squeeze("/")
51
+ end
52
+
53
+ def scheme
54
+ BuntoAdmin.site.config["scheme"] || "http"
55
+ end
56
+
57
+ def host
58
+ BuntoAdmin.site.config["host"].sub("127.0.0.1", "localhost")
59
+ end
60
+
61
+ def port
62
+ BuntoAdmin.site.config["port"]
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module BuntoAdmin
2
+ VERSION = "0.6.0".freeze
3
+ end
@@ -0,0 +1,14 @@
1
+ module Bunto
2
+ module Commands
3
+ class Build < Command
4
+ class << self
5
+ alias_method :original_build, :build
6
+
7
+ def build(site, options)
8
+ options["watch"] = false
9
+ original_build(site, options)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module Bunto
2
+ module Commands
3
+ class Serve < Command
4
+ class << self
5
+ def start_up_webrick(opts, destination)
6
+ server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
7
+ server.mount(opts["baseurl"], Servlet, destination, file_handler_opts)
8
+
9
+ bunto_admin_monkey_patch(server)
10
+
11
+ Bunto.logger.info "Server address:", server_address(server, opts)
12
+ launch_browser server, opts if opts["open_url"]
13
+ boot_or_detach server, opts
14
+ end
15
+
16
+ def bunto_admin_monkey_patch(server)
17
+ server.mount "/admin", Rack::Handler::WEBrick, BuntoAdmin::StaticServer
18
+ server.mount "/_api", Rack::Handler::WEBrick, BuntoAdmin::Server
19
+ Bunto.logger.warn "Auto-regeneration:", "disabled by BuntoAdmin."
20
+ Bunto.logger.warn "", "The site will regenerate only via the Admin interface."
21
+ Bunto.logger.info "BuntoAdmin mode:", ENV["RACK_ENV"] || "production"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunto-admin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Mert Kahyaoğlu
8
+ - GitHub Open Source
9
+ - Suriyaaa Kudo
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2017-07-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bunto
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.4.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 3.4.5
29
+ - !ruby/object:Gem::Dependency
30
+ name: sinatra
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.4'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.4'
43
+ - !ruby/object:Gem::Dependency
44
+ name: sinatra-contrib
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.4'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.4'
57
+ - !ruby/object:Gem::Dependency
58
+ name: addressable
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.4'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '2.4'
71
+ - !ruby/object:Gem::Dependency
72
+ name: bundler
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.7'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.7'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rake
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '10.0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '10.0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rspec
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.4'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '3.4'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rubocop
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: 0.48.1
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: 0.48.1
127
+ - !ruby/object:Gem::Dependency
128
+ name: sinatra-cross_origin
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '0.3'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '0.3'
141
+ - !ruby/object:Gem::Dependency
142
+ name: gem-release
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '0.7'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: '0.7'
155
+ description: Bunto::Admin is a drop in administrative framework for Bunto sites.
156
+ email:
157
+ - mertkahyaoglu93@gmail.com
158
+ - opensource@github.com
159
+ - github@suriyaa.tk
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - LICENSE
165
+ - README.md
166
+ - lib/bunto-admin.rb
167
+ - lib/bunto-admin/apiable.rb
168
+ - lib/bunto-admin/data_file.rb
169
+ - lib/bunto-admin/directory.rb
170
+ - lib/bunto-admin/file_helper.rb
171
+ - lib/bunto-admin/page_without_a_file.rb
172
+ - lib/bunto-admin/path_helper.rb
173
+ - lib/bunto-admin/server.rb
174
+ - lib/bunto-admin/server/collection.rb
175
+ - lib/bunto-admin/server/configuration.rb
176
+ - lib/bunto-admin/server/data.rb
177
+ - lib/bunto-admin/server/page.rb
178
+ - lib/bunto-admin/server/static_file.rb
179
+ - lib/bunto-admin/static_server.rb
180
+ - lib/bunto-admin/urlable.rb
181
+ - lib/bunto-admin/version.rb
182
+ - lib/bunto/commands/build.rb
183
+ - lib/bunto/commands/serve.rb
184
+ homepage: https://github.com/bunto/bunto-admin
185
+ licenses:
186
+ - MIT
187
+ metadata:
188
+ allowed_push_host: https://rubygems.org
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 2.6.12
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: wp-admin for Bunto, but better
209
+ test_files: []