Browse Source

chore(project): Set foundation.

jackyalcine 1 year ago
parent
commit
0fd0a94580
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D
68 changed files with 3326 additions and 0 deletions
  1. 10
    0
      .dockerignore
  2. 5
    0
      .editorconfig
  3. 1
    0
      .elixir-version
  4. 20
    0
      .gitignore
  5. 19
    0
      .stylelintrc
  6. 1
    0
      CHECKS
  7. 0
    0
      CONTRIBUTING.markdown
  8. 23
    0
      Dockerfile
  9. 661
    0
      LICENSE
  10. 1
    0
      Procfile
  11. 11
    0
      README.markdown
  12. 8
    0
      app.json
  13. 24
    0
      config/config.exs
  14. 30
    0
      config/dev.exs
  15. 12
    0
      config/prod.exs
  16. 11
    0
      config/test.exs
  17. 24
    0
      docker-compose.yml
  18. 16
    0
      docker/scripts/docker-build.sh
  19. 6
    0
      docker/scripts/docker-cleanup.sh
  20. 3
    0
      docker/scripts/docker-post-deploy.sh
  21. 12
    0
      docker/scripts/docker-pre-deploy.sh
  22. 27
    0
      docker/scripts/docker-prepare.sh
  23. 21
    0
      lib/application.ex
  24. 2
    0
      lib/jackywtf.ex
  25. 11
    0
      lib/repo.ex
  26. 18
    0
      lib/repo/entry.ex
  27. 21
    0
      lib/repo/object.ex
  28. 47
    0
      lib/web.ex
  29. 37
    0
      lib/web/channels/user_socket.ex
  30. 37
    0
      lib/web/controllers/entry_controller.ex
  31. 15
    0
      lib/web/controllers/indie/auth_api_controller.ex
  32. 17
    0
      lib/web/controllers/indie/auth_controller.ex
  33. 7
    0
      lib/web/controllers/page_controller.ex
  34. 41
    0
      lib/web/endpoint.ex
  35. 3
    0
      lib/web/gettext.ex
  36. 33
    0
      lib/web/router.ex
  37. 9
    0
      lib/web/templates/entry/index.html.eex
  38. 0
    0
      lib/web/templates/indie/auth.html.eex
  39. 18
    0
      lib/web/templates/indie/auth/authorize.html.eex
  40. 3
    0
      lib/web/templates/indie/auth/verify_authorize.json.eex
  41. 38
    0
      lib/web/templates/layout/app.html.eex
  42. 3
    0
      lib/web/templates/page/index.html.eex
  43. 7
    0
      lib/web/views/entry_view.ex
  44. 44
    0
      lib/web/views/error_helpers.ex
  45. 16
    0
      lib/web/views/error_view.ex
  46. 27
    0
      lib/web/views/indie/auth_view.ex
  47. 7
    0
      lib/web/views/layout_view.ex
  48. 7
    0
      lib/web/views/page_view.ex
  49. 54
    0
      mix.exs
  50. 40
    0
      mix.lock
  51. 97
    0
      priv/gettext/en/LC_MESSAGES/errors.po
  52. 95
    0
      priv/gettext/errors.pot
  53. 0
    0
      priv/repo/db/.gitkeep
  54. 14
    0
      priv/repo/migrations/20180923033453_create_objects.exs
  55. 12
    0
      priv/repo/migrations/20180923033807_create_entries.exs
  56. 6
    0
      priv/repo/seeds/entry.exs
  57. 1
    0
      priv/static/css/app.css
  58. BIN
      priv/static/images/phoenix.png
  59. 3
    0
      priv/static/js/app.js
  60. 1431
    0
      priv/static/js/phoenix.js
  61. 8
    0
      test/jackywtf/web/controllers/page_controller_test.exs
  62. 16
    0
      test/jackywtf/web/views/error_view_test.exs
  63. 3
    0
      test/jackywtf/web/views/layout_view_test.exs
  64. 3
    0
      test/jackywtf/web/views/page_view_test.exs
  65. 35
    0
      test/support/channel_case.ex
  66. 38
    0
      test/support/conn_case.ex
  67. 53
    0
      test/support/data_case.ex
  68. 3
    0
      test/test_helper.exs

+ 10
- 0
.dockerignore View File

@@ -0,0 +1,10 @@
1
+deps/
2
+_build/
3
+docker-compose.yml
4
+.git/*
5
+.elixir_ls/*
6
+.envrc
7
+.elixir-version
8
+.editiorconfig
9
+.stylelintrc
10
+erl_crash.dump

+ 5
- 0
.editorconfig View File

@@ -0,0 +1,5 @@
1
+root = true
2
+
3
+[*]
4
+end_of_line = lf
5
+insert_final_newline = true

+ 1
- 0
.elixir-version View File

@@ -0,0 +1 @@
1
+1.6.6

+ 20
- 0
.gitignore View File

@@ -0,0 +1,20 @@
1
+# App artifacts
2
+/_build
3
+/db
4
+/deps
5
+/*.ez
6
+
7
+# Generated on crash by the VM
8
+erl_crash.dump
9
+
10
+# Files matching config/*.secret.exs pattern contain sensitive
11
+# data and you should not commit them into version control.
12
+#
13
+# Alternatively, you may comment the line below and commit the
14
+# secrets files as long as you replace their contents by environment
15
+# variables.
16
+/config/*.secret.exs
17
+.elixir_ls
18
+priv/repo/dev.db
19
+.envrc
20
+priv/repo/db/

+ 19
- 0
.stylelintrc View File

@@ -0,0 +1,19 @@
1
+{
2
+  "rules": {
3
+    "block-no-empty": null,
4
+    "color-no-invalid-hex": true,
5
+    "comment-empty-line-before": [ "always", {
6
+      "ignore": ["stylelint-commands", "after-comment"]
7
+    } ],
8
+    "declaration-colon-space-after": "always",
9
+    "indentation": ["tab", {
10
+      "except": ["value"]
11
+    }],
12
+    "max-empty-lines": 2,
13
+    "rule-empty-line-before": [ "always", {
14
+      "except": ["first-nested"],
15
+      "ignore": ["after-comment"]
16
+    } ],
17
+    "unit-whitelist": ["em", "rem", "%", "s"]
18
+  }
19
+}

+ 1
- 0
CHECKS View File

@@ -0,0 +1 @@
1
+/ jacky.wtf

+ 0
- 0
CONTRIBUTING.markdown View File


+ 23
- 0
Dockerfile View File

@@ -0,0 +1,23 @@
1
+FROM elixir:1.6.6-alpine
2
+LABEL maintainer Jacky Alcine <yo@jacky.wtf>
3
+
4
+ARG MIX_ENV=prod
5
+ENV MIX_ENV $MIX_ENV
6
+
7
+RUN mkdir /tmp/jackywtf-docker
8
+ADD docker/scripts/ /tmp/jackywtf-docker/
9
+
10
+RUN sh /tmp/jackywtf-docker/docker-prepare.sh
11
+
12
+WORKDIR /opt/jacky-wtf
13
+USER jackywtf
14
+
15
+COPY ./ /opt/jacky-wtf/
16
+RUN sh /tmp/jackywtf-docker/docker-build.sh
17
+
18
+USER root
19
+RUN sh /tmp/jackywtf-docker/docker-cleanup.sh
20
+
21
+USER jackywtf
22
+VOLUME /opt/jacky-wtf/priv/repo/db
23
+WORKDIR /opt/jacky-wtf

+ 661
- 0
LICENSE View File

@@ -0,0 +1,661 @@
1
+                    GNU AFFERO GENERAL PUBLIC LICENSE
2
+                       Version 3, 19 November 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+                            Preamble
9
+
10
+  The GNU Affero General Public License is a free, copyleft license for
11
+software and other kinds of works, specifically designed to ensure
12
+cooperation with the community in the case of network server software.
13
+
14
+  The licenses for most software and other practical works are designed
15
+to take away your freedom to share and change the works.  By contrast,
16
+our General Public Licenses are intended to guarantee your freedom to
17
+share and change all versions of a program--to make sure it remains free
18
+software for all its users.
19
+
20
+  When we speak of free software, we are referring to freedom, not
21
+price.  Our General Public Licenses are designed to make sure that you
22
+have the freedom to distribute copies of free software (and charge for
23
+them if you wish), that you receive source code or can get it if you
24
+want it, that you can change the software or use pieces of it in new
25
+free programs, and that you know you can do these things.
26
+
27
+  Developers that use our General Public Licenses protect your rights
28
+with two steps: (1) assert copyright on the software, and (2) offer
29
+you this License which gives you legal permission to copy, distribute
30
+and/or modify the software.
31
+
32
+  A secondary benefit of defending all users' freedom is that
33
+improvements made in alternate versions of the program, if they
34
+receive widespread use, become available for other developers to
35
+incorporate.  Many developers of free software are heartened and
36
+encouraged by the resulting cooperation.  However, in the case of
37
+software used on network servers, this result may fail to come about.
38
+The GNU General Public License permits making a modified version and
39
+letting the public access it on a server without ever releasing its
40
+source code to the public.
41
+
42
+  The GNU Affero General Public License is designed specifically to
43
+ensure that, in such cases, the modified source code becomes available
44
+to the community.  It requires the operator of a network server to
45
+provide the source code of the modified version running there to the
46
+users of that server.  Therefore, public use of a modified version, on
47
+a publicly accessible server, gives the public access to the source
48
+code of the modified version.
49
+
50
+  An older license, called the Affero General Public License and
51
+published by Affero, was designed to accomplish similar goals.  This is
52
+a different license, not a version of the Affero GPL, but Affero has
53
+released a new version of the Affero GPL which permits relicensing under
54
+this license.
55
+
56
+  The precise terms and conditions for copying, distribution and
57
+modification follow.
58
+
59
+                       TERMS AND CONDITIONS
60
+
61
+  0. Definitions.
62
+
63
+  "This License" refers to version 3 of the GNU Affero General Public License.
64
+
65
+  "Copyright" also means copyright-like laws that apply to other kinds of
66
+works, such as semiconductor masks.
67
+
68
+  "The Program" refers to any copyrightable work licensed under this
69
+License.  Each licensee is addressed as "you".  "Licensees" and
70
+"recipients" may be individuals or organizations.
71
+
72
+  To "modify" a work means to copy from or adapt all or part of the work
73
+in a fashion requiring copyright permission, other than the making of an
74
+exact copy.  The resulting work is called a "modified version" of the
75
+earlier work or a work "based on" the earlier work.
76
+
77
+  A "covered work" means either the unmodified Program or a work based
78
+on the Program.
79
+
80
+  To "propagate" a work means to do anything with it that, without
81
+permission, would make you directly or secondarily liable for
82
+infringement under applicable copyright law, except executing it on a
83
+computer or modifying a private copy.  Propagation includes copying,
84
+distribution (with or without modification), making available to the
85
+public, and in some countries other activities as well.
86
+
87
+  To "convey" a work means any kind of propagation that enables other
88
+parties to make or receive copies.  Mere interaction with a user through
89
+a computer network, with no transfer of a copy, is not conveying.
90
+
91
+  An interactive user interface displays "Appropriate Legal Notices"
92
+to the extent that it includes a convenient and prominently visible
93
+feature that (1) displays an appropriate copyright notice, and (2)
94
+tells the user that there is no warranty for the work (except to the
95
+extent that warranties are provided), that licensees may convey the
96
+work under this License, and how to view a copy of this License.  If
97
+the interface presents a list of user commands or options, such as a
98
+menu, a prominent item in the list meets this criterion.
99
+
100
+  1. Source Code.
101
+
102
+  The "source code" for a work means the preferred form of the work
103
+for making modifications to it.  "Object code" means any non-source
104
+form of a work.
105
+
106
+  A "Standard Interface" means an interface that either is an official
107
+standard defined by a recognized standards body, or, in the case of
108
+interfaces specified for a particular programming language, one that
109
+is widely used among developers working in that language.
110
+
111
+  The "System Libraries" of an executable work include anything, other
112
+than the work as a whole, that (a) is included in the normal form of
113
+packaging a Major Component, but which is not part of that Major
114
+Component, and (b) serves only to enable use of the work with that
115
+Major Component, or to implement a Standard Interface for which an
116
+implementation is available to the public in source code form.  A
117
+"Major Component", in this context, means a major essential component
118
+(kernel, window system, and so on) of the specific operating system
119
+(if any) on which the executable work runs, or a compiler used to
120
+produce the work, or an object code interpreter used to run it.
121
+
122
+  The "Corresponding Source" for a work in object code form means all
123
+the source code needed to generate, install, and (for an executable
124
+work) run the object code and to modify the work, including scripts to
125
+control those activities.  However, it does not include the work's
126
+System Libraries, or general-purpose tools or generally available free
127
+programs which are used unmodified in performing those activities but
128
+which are not part of the work.  For example, Corresponding Source
129
+includes interface definition files associated with source files for
130
+the work, and the source code for shared libraries and dynamically
131
+linked subprograms that the work is specifically designed to require,
132
+such as by intimate data communication or control flow between those
133
+subprograms and other parts of the work.
134
+
135
+  The Corresponding Source need not include anything that users
136
+can regenerate automatically from other parts of the Corresponding
137
+Source.
138
+
139
+  The Corresponding Source for a work in source code form is that
140
+same work.
141
+
142
+  2. Basic Permissions.
143
+
144
+  All rights granted under this License are granted for the term of
145
+copyright on the Program, and are irrevocable provided the stated
146
+conditions are met.  This License explicitly affirms your unlimited
147
+permission to run the unmodified Program.  The output from running a
148
+covered work is covered by this License only if the output, given its
149
+content, constitutes a covered work.  This License acknowledges your
150
+rights of fair use or other equivalent, as provided by copyright law.
151
+
152
+  You may make, run and propagate covered works that you do not
153
+convey, without conditions so long as your license otherwise remains
154
+in force.  You may convey covered works to others for the sole purpose
155
+of having them make modifications exclusively for you, or provide you
156
+with facilities for running those works, provided that you comply with
157
+the terms of this License in conveying all material for which you do
158
+not control copyright.  Those thus making or running the covered works
159
+for you must do so exclusively on your behalf, under your direction
160
+and control, on terms that prohibit them from making any copies of
161
+your copyrighted material outside their relationship with you.
162
+
163
+  Conveying under any other circumstances is permitted solely under
164
+the conditions stated below.  Sublicensing is not allowed; section 10
165
+makes it unnecessary.
166
+
167
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168
+
169
+  No covered work shall be deemed part of an effective technological
170
+measure under any applicable law fulfilling obligations under article
171
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
172
+similar laws prohibiting or restricting circumvention of such
173
+measures.
174
+
175
+  When you convey a covered work, you waive any legal power to forbid
176
+circumvention of technological measures to the extent such circumvention
177
+is effected by exercising rights under this License with respect to
178
+the covered work, and you disclaim any intention to limit operation or
179
+modification of the work as a means of enforcing, against the work's
180
+users, your or third parties' legal rights to forbid circumvention of
181
+technological measures.
182
+
183
+  4. Conveying Verbatim Copies.
184
+
185
+  You may convey verbatim copies of the Program's source code as you
186
+receive it, in any medium, provided that you conspicuously and
187
+appropriately publish on each copy an appropriate copyright notice;
188
+keep intact all notices stating that this License and any
189
+non-permissive terms added in accord with section 7 apply to the code;
190
+keep intact all notices of the absence of any warranty; and give all
191
+recipients a copy of this License along with the Program.
192
+
193
+  You may charge any price or no price for each copy that you convey,
194
+and you may offer support or warranty protection for a fee.
195
+
196
+  5. Conveying Modified Source Versions.
197
+
198
+  You may convey a work based on the Program, or the modifications to
199
+produce it from the Program, in the form of source code under the
200
+terms of section 4, provided that you also meet all of these conditions:
201
+
202
+    a) The work must carry prominent notices stating that you modified
203
+    it, and giving a relevant date.
204
+
205
+    b) The work must carry prominent notices stating that it is
206
+    released under this License and any conditions added under section
207
+    7.  This requirement modifies the requirement in section 4 to
208
+    "keep intact all notices".
209
+
210
+    c) You must license the entire work, as a whole, under this
211
+    License to anyone who comes into possession of a copy.  This
212
+    License will therefore apply, along with any applicable section 7
213
+    additional terms, to the whole of the work, and all its parts,
214
+    regardless of how they are packaged.  This License gives no
215
+    permission to license the work in any other way, but it does not
216
+    invalidate such permission if you have separately received it.
217
+
218
+    d) If the work has interactive user interfaces, each must display
219
+    Appropriate Legal Notices; however, if the Program has interactive
220
+    interfaces that do not display Appropriate Legal Notices, your
221
+    work need not make them do so.
222
+
223
+  A compilation of a covered work with other separate and independent
224
+works, which are not by their nature extensions of the covered work,
225
+and which are not combined with it such as to form a larger program,
226
+in or on a volume of a storage or distribution medium, is called an
227
+"aggregate" if the compilation and its resulting copyright are not
228
+used to limit the access or legal rights of the compilation's users
229
+beyond what the individual works permit.  Inclusion of a covered work
230
+in an aggregate does not cause this License to apply to the other
231
+parts of the aggregate.
232
+
233
+  6. Conveying Non-Source Forms.
234
+
235
+  You may convey a covered work in object code form under the terms
236
+of sections 4 and 5, provided that you also convey the
237
+machine-readable Corresponding Source under the terms of this License,
238
+in one of these ways:
239
+
240
+    a) Convey the object code in, or embodied in, a physical product
241
+    (including a physical distribution medium), accompanied by the
242
+    Corresponding Source fixed on a durable physical medium
243
+    customarily used for software interchange.
244
+
245
+    b) Convey the object code in, or embodied in, a physical product
246
+    (including a physical distribution medium), accompanied by a
247
+    written offer, valid for at least three years and valid for as
248
+    long as you offer spare parts or customer support for that product
249
+    model, to give anyone who possesses the object code either (1) a
250
+    copy of the Corresponding Source for all the software in the
251
+    product that is covered by this License, on a durable physical
252
+    medium customarily used for software interchange, for a price no
253
+    more than your reasonable cost of physically performing this
254
+    conveying of source, or (2) access to copy the
255
+    Corresponding Source from a network server at no charge.
256
+
257
+    c) Convey individual copies of the object code with a copy of the
258
+    written offer to provide the Corresponding Source.  This
259
+    alternative is allowed only occasionally and noncommercially, and
260
+    only if you received the object code with such an offer, in accord
261
+    with subsection 6b.
262
+
263
+    d) Convey the object code by offering access from a designated
264
+    place (gratis or for a charge), and offer equivalent access to the
265
+    Corresponding Source in the same way through the same place at no
266
+    further charge.  You need not require recipients to copy the
267
+    Corresponding Source along with the object code.  If the place to
268
+    copy the object code is a network server, the Corresponding Source
269
+    may be on a different server (operated by you or a third party)
270
+    that supports equivalent copying facilities, provided you maintain
271
+    clear directions next to the object code saying where to find the
272
+    Corresponding Source.  Regardless of what server hosts the
273
+    Corresponding Source, you remain obligated to ensure that it is
274
+    available for as long as needed to satisfy these requirements.
275
+
276
+    e) Convey the object code using peer-to-peer transmission, provided
277
+    you inform other peers where the object code and Corresponding
278
+    Source of the work are being offered to the general public at no
279
+    charge under subsection 6d.
280
+
281
+  A separable portion of the object code, whose source code is excluded
282
+from the Corresponding Source as a System Library, need not be
283
+included in conveying the object code work.
284
+
285
+  A "User Product" is either (1) a "consumer product", which means any
286
+tangible personal property which is normally used for personal, family,
287
+or household purposes, or (2) anything designed or sold for incorporation
288
+into a dwelling.  In determining whether a product is a consumer product,
289
+doubtful cases shall be resolved in favor of coverage.  For a particular
290
+product received by a particular user, "normally used" refers to a
291
+typical or common use of that class of product, regardless of the status
292
+of the particular user or of the way in which the particular user
293
+actually uses, or expects or is expected to use, the product.  A product
294
+is a consumer product regardless of whether the product has substantial
295
+commercial, industrial or non-consumer uses, unless such uses represent
296
+the only significant mode of use of the product.
297
+
298
+  "Installation Information" for a User Product means any methods,
299
+procedures, authorization keys, or other information required to install
300
+and execute modified versions of a covered work in that User Product from
301
+a modified version of its Corresponding Source.  The information must
302
+suffice to ensure that the continued functioning of the modified object
303
+code is in no case prevented or interfered with solely because
304
+modification has been made.
305
+
306
+  If you convey an object code work under this section in, or with, or
307
+specifically for use in, a User Product, and the conveying occurs as
308
+part of a transaction in which the right of possession and use of the
309
+User Product is transferred to the recipient in perpetuity or for a
310
+fixed term (regardless of how the transaction is characterized), the
311
+Corresponding Source conveyed under this section must be accompanied
312
+by the Installation Information.  But this requirement does not apply
313
+if neither you nor any third party retains the ability to install
314
+modified object code on the User Product (for example, the work has
315
+been installed in ROM).
316
+
317
+  The requirement to provide Installation Information does not include a
318
+requirement to continue to provide support service, warranty, or updates
319
+for a work that has been modified or installed by the recipient, or for
320
+the User Product in which it has been modified or installed.  Access to a
321
+network may be denied when the modification itself materially and
322
+adversely affects the operation of the network or violates the rules and
323
+protocols for communication across the network.
324
+
325
+  Corresponding Source conveyed, and Installation Information provided,
326
+in accord with this section must be in a format that is publicly
327
+documented (and with an implementation available to the public in
328
+source code form), and must require no special password or key for
329
+unpacking, reading or copying.
330
+
331
+  7. Additional Terms.
332
+
333
+  "Additional permissions" are terms that supplement the terms of this
334
+License by making exceptions from one or more of its conditions.
335
+Additional permissions that are applicable to the entire Program shall
336
+be treated as though they were included in this License, to the extent
337
+that they are valid under applicable law.  If additional permissions
338
+apply only to part of the Program, that part may be used separately
339
+under those permissions, but the entire Program remains governed by
340
+this License without regard to the additional permissions.
341
+
342
+  When you convey a copy of a covered work, you may at your option
343
+remove any additional permissions from that copy, or from any part of
344
+it.  (Additional permissions may be written to require their own
345
+removal in certain cases when you modify the work.)  You may place
346
+additional permissions on material, added by you to a covered work,
347
+for which you have or can give appropriate copyright permission.
348
+
349
+  Notwithstanding any other provision of this License, for material you
350
+add to a covered work, you may (if authorized by the copyright holders of
351
+that material) supplement the terms of this License with terms:
352
+
353
+    a) Disclaiming warranty or limiting liability differently from the
354
+    terms of sections 15 and 16 of this License; or
355
+
356
+    b) Requiring preservation of specified reasonable legal notices or
357
+    author attributions in that material or in the Appropriate Legal
358
+    Notices displayed by works containing it; or
359
+
360
+    c) Prohibiting misrepresentation of the origin of that material, or
361
+    requiring that modified versions of such material be marked in
362
+    reasonable ways as different from the original version; or
363
+
364
+    d) Limiting the use for publicity purposes of names of licensors or
365
+    authors of the material; or
366
+
367
+    e) Declining to grant rights under trademark law for use of some
368
+    trade names, trademarks, or service marks; or
369
+
370
+    f) Requiring indemnification of licensors and authors of that
371
+    material by anyone who conveys the material (or modified versions of
372
+    it) with contractual assumptions of liability to the recipient, for
373
+    any liability that these contractual assumptions directly impose on
374
+    those licensors and authors.
375
+
376
+  All other non-permissive additional terms are considered "further
377
+restrictions" within the meaning of section 10.  If the Program as you
378
+received it, or any part of it, contains a notice stating that it is
379
+governed by this License along with a term that is a further
380
+restriction, you may remove that term.  If a license document contains
381
+a further restriction but permits relicensing or conveying under this
382
+License, you may add to a covered work material governed by the terms
383
+of that license document, provided that the further restriction does
384
+not survive such relicensing or conveying.
385
+
386
+  If you add terms to a covered work in accord with this section, you
387
+must place, in the relevant source files, a statement of the
388
+additional terms that apply to those files, or a notice indicating
389
+where to find the applicable terms.
390
+
391
+  Additional terms, permissive or non-permissive, may be stated in the
392
+form of a separately written license, or stated as exceptions;
393
+the above requirements apply either way.
394
+
395
+  8. Termination.
396
+
397
+  You may not propagate or modify a covered work except as expressly
398
+provided under this License.  Any attempt otherwise to propagate or
399
+modify it is void, and will automatically terminate your rights under
400
+this License (including any patent licenses granted under the third
401
+paragraph of section 11).
402
+
403
+  However, if you cease all violation of this License, then your
404
+license from a particular copyright holder is reinstated (a)
405
+provisionally, unless and until the copyright holder explicitly and
406
+finally terminates your license, and (b) permanently, if the copyright
407
+holder fails to notify you of the violation by some reasonable means
408
+prior to 60 days after the cessation.
409
+
410
+  Moreover, your license from a particular copyright holder is
411
+reinstated permanently if the copyright holder notifies you of the
412
+violation by some reasonable means, this is the first time you have
413
+received notice of violation of this License (for any work) from that
414
+copyright holder, and you cure the violation prior to 30 days after
415
+your receipt of the notice.
416
+
417
+  Termination of your rights under this section does not terminate the
418
+licenses of parties who have received copies or rights from you under
419
+this License.  If your rights have been terminated and not permanently
420
+reinstated, you do not qualify to receive new licenses for the same
421
+material under section 10.
422
+
423
+  9. Acceptance Not Required for Having Copies.
424
+
425
+  You are not required to accept this License in order to receive or
426
+run a copy of the Program.  Ancillary propagation of a covered work
427
+occurring solely as a consequence of using peer-to-peer transmission
428
+to receive a copy likewise does not require acceptance.  However,
429
+nothing other than this License grants you permission to propagate or
430
+modify any covered work.  These actions infringe copyright if you do
431
+not accept this License.  Therefore, by modifying or propagating a
432
+covered work, you indicate your acceptance of this License to do so.
433
+
434
+  10. Automatic Licensing of Downstream Recipients.
435
+
436
+  Each time you convey a covered work, the recipient automatically
437
+receives a license from the original licensors, to run, modify and
438
+propagate that work, subject to this License.  You are not responsible
439
+for enforcing compliance by third parties with this License.
440
+
441
+  An "entity transaction" is a transaction transferring control of an
442
+organization, or substantially all assets of one, or subdividing an
443
+organization, or merging organizations.  If propagation of a covered
444
+work results from an entity transaction, each party to that
445
+transaction who receives a copy of the work also receives whatever
446
+licenses to the work the party's predecessor in interest had or could
447
+give under the previous paragraph, plus a right to possession of the
448
+Corresponding Source of the work from the predecessor in interest, if
449
+the predecessor has it or can get it with reasonable efforts.
450
+
451
+  You may not impose any further restrictions on the exercise of the
452
+rights granted or affirmed under this License.  For example, you may
453
+not impose a license fee, royalty, or other charge for exercise of
454
+rights granted under this License, and you may not initiate litigation
455
+(including a cross-claim or counterclaim in a lawsuit) alleging that
456
+any patent claim is infringed by making, using, selling, offering for
457
+sale, or importing the Program or any portion of it.
458
+
459
+  11. Patents.
460
+
461
+  A "contributor" is a copyright holder who authorizes use under this
462
+License of the Program or a work on which the Program is based.  The
463
+work thus licensed is called the contributor's "contributor version".
464
+
465
+  A contributor's "essential patent claims" are all patent claims
466
+owned or controlled by the contributor, whether already acquired or
467
+hereafter acquired, that would be infringed by some manner, permitted
468
+by this License, of making, using, or selling its contributor version,
469
+but do not include claims that would be infringed only as a
470
+consequence of further modification of the contributor version.  For
471
+purposes of this definition, "control" includes the right to grant
472
+patent sublicenses in a manner consistent with the requirements of
473
+this License.
474
+
475
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
476
+patent license under the contributor's essential patent claims, to
477
+make, use, sell, offer for sale, import and otherwise run, modify and
478
+propagate the contents of its contributor version.
479
+
480
+  In the following three paragraphs, a "patent license" is any express
481
+agreement or commitment, however denominated, not to enforce a patent
482
+(such as an express permission to practice a patent or covenant not to
483
+sue for patent infringement).  To "grant" such a patent license to a
484
+party means to make such an agreement or commitment not to enforce a
485
+patent against the party.
486
+
487
+  If you convey a covered work, knowingly relying on a patent license,
488
+and the Corresponding Source of the work is not available for anyone
489
+to copy, free of charge and under the terms of this License, through a
490
+publicly available network server or other readily accessible means,
491
+then you must either (1) cause the Corresponding Source to be so
492
+available, or (2) arrange to deprive yourself of the benefit of the
493
+patent license for this particular work, or (3) arrange, in a manner
494
+consistent with the requirements of this License, to extend the patent
495
+license to downstream recipients.  "Knowingly relying" means you have
496
+actual knowledge that, but for the patent license, your conveying the
497
+covered work in a country, or your recipient's use of the covered work
498
+in a country, would infringe one or more identifiable patents in that
499
+country that you have reason to believe are valid.
500
+
501
+  If, pursuant to or in connection with a single transaction or
502
+arrangement, you convey, or propagate by procuring conveyance of, a
503
+covered work, and grant a patent license to some of the parties
504
+receiving the covered work authorizing them to use, propagate, modify
505
+or convey a specific copy of the covered work, then the patent license
506
+you grant is automatically extended to all recipients of the covered
507
+work and works based on it.
508
+
509
+  A patent license is "discriminatory" if it does not include within
510
+the scope of its coverage, prohibits the exercise of, or is
511
+conditioned on the non-exercise of one or more of the rights that are
512
+specifically granted under this License.  You may not convey a covered
513
+work if you are a party to an arrangement with a third party that is
514
+in the business of distributing software, under which you make payment
515
+to the third party based on the extent of your activity of conveying
516
+the work, and under which the third party grants, to any of the
517
+parties who would receive the covered work from you, a discriminatory
518
+patent license (a) in connection with copies of the covered work
519
+conveyed by you (or copies made from those copies), or (b) primarily
520
+for and in connection with specific products or compilations that
521
+contain the covered work, unless you entered into that arrangement,
522
+or that patent license was granted, prior to 28 March 2007.
523
+
524
+  Nothing in this License shall be construed as excluding or limiting
525
+any implied license or other defenses to infringement that may
526
+otherwise be available to you under applicable patent law.
527
+
528
+  12. No Surrender of Others' Freedom.
529
+
530
+  If conditions are imposed on you (whether by court order, agreement or
531
+otherwise) that contradict the conditions of this License, they do not
532
+excuse you from the conditions of this License.  If you cannot convey a
533
+covered work so as to satisfy simultaneously your obligations under this
534
+License and any other pertinent obligations, then as a consequence you may
535
+not convey it at all.  For example, if you agree to terms that obligate you
536
+to collect a royalty for further conveying from those to whom you convey
537
+the Program, the only way you could satisfy both those terms and this
538
+License would be to refrain entirely from conveying the Program.
539
+
540
+  13. Remote Network Interaction; Use with the GNU General Public License.
541
+
542
+  Notwithstanding any other provision of this License, if you modify the
543
+Program, your modified version must prominently offer all users
544
+interacting with it remotely through a computer network (if your version
545
+supports such interaction) an opportunity to receive the Corresponding
546
+Source of your version by providing access to the Corresponding Source
547
+from a network server at no charge, through some standard or customary
548
+means of facilitating copying of software.  This Corresponding Source
549
+shall include the Corresponding Source for any work covered by version 3
550
+of the GNU General Public License that is incorporated pursuant to the
551
+following paragraph.
552
+
553
+  Notwithstanding any other provision of this License, you have
554
+permission to link or combine any covered work with a work licensed
555
+under version 3 of the GNU General Public License into a single
556
+combined work, and to convey the resulting work.  The terms of this
557
+License will continue to apply to the part which is the covered work,
558
+but the work with which it is combined will remain governed by version
559
+3 of the GNU General Public License.
560
+
561
+  14. Revised Versions of this License.
562
+
563
+  The Free Software Foundation may publish revised and/or new versions of
564
+the GNU Affero General Public License from time to time.  Such new versions
565
+will be similar in spirit to the present version, but may differ in detail to
566
+address new problems or concerns.
567
+
568
+  Each version is given a distinguishing version number.  If the
569
+Program specifies that a certain numbered version of the GNU Affero General
570
+Public License "or any later version" applies to it, you have the
571
+option of following the terms and conditions either of that numbered
572
+version or of any later version published by the Free Software
573
+Foundation.  If the Program does not specify a version number of the
574
+GNU Affero General Public License, you may choose any version ever published
575
+by the Free Software Foundation.
576
+
577
+  If the Program specifies that a proxy can decide which future
578
+versions of the GNU Affero General Public License can be used, that proxy's
579
+public statement of acceptance of a version permanently authorizes you
580
+to choose that version for the Program.
581
+
582
+  Later license versions may give you additional or different
583
+permissions.  However, no additional obligations are imposed on any
584
+author or copyright holder as a result of your choosing to follow a
585
+later version.
586
+
587
+  15. Disclaimer of Warranty.
588
+
589
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597
+
598
+  16. Limitation of Liability.
599
+
600
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608
+SUCH DAMAGES.
609
+
610
+  17. Interpretation of Sections 15 and 16.
611
+
612
+  If the disclaimer of warranty and limitation of liability provided
613
+above cannot be given local legal effect according to their terms,
614
+reviewing courts shall apply local law that most closely approximates
615
+an absolute waiver of all civil liability in connection with the
616
+Program, unless a warranty or assumption of liability accompanies a
617
+copy of the Program in return for a fee.
618
+
619
+                     END OF TERMS AND CONDITIONS
620
+
621
+            How to Apply These Terms to Your New Programs
622
+
623
+  If you develop a new program, and you want it to be of the greatest
624
+possible use to the public, the best way to achieve this is to make it
625
+free software which everyone can redistribute and change under these terms.
626
+
627
+  To do so, attach the following notices to the program.  It is safest
628
+to attach them to the start of each source file to most effectively
629
+state the exclusion of warranty; and each file should have at least
630
+the "copyright" line and a pointer to where the full notice is found.
631
+
632
+    <one line to give the program's name and a brief idea of what it does.>
633
+    Copyright (C) <year>  <name of author>
634
+
635
+    This program is free software: you can redistribute it and/or modify
636
+    it under the terms of the GNU Affero General Public License as published
637
+    by the Free Software Foundation, either version 3 of the License, or
638
+    (at your option) any later version.
639
+
640
+    This program is distributed in the hope that it will be useful,
641
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
642
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
643
+    GNU Affero General Public License for more details.
644
+
645
+    You should have received a copy of the GNU Affero General Public License
646
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
647
+
648
+Also add information on how to contact you by electronic and paper mail.
649
+
650
+  If your software can interact with users remotely through a computer
651
+network, you should also make sure that it provides a way for users to
652
+get its source.  For example, if your program is a web application, its
653
+interface could display a "Source" link that leads users to an archive
654
+of the code.  There are many ways you could offer source, and different
655
+solutions will be better for different programs; see section 13 for the
656
+specific requirements.
657
+
658
+  You should also get your employer (if you work as a programmer) or school,
659
+if any, to sign a "copyright disclaimer" for the program, if necessary.
660
+For more information on this, and how to apply and follow the GNU AGPL, see
661
+<https://www.gnu.org/licenses/>.

+ 1
- 0
Procfile View File

@@ -0,0 +1 @@
1
+web: mix start

+ 11
- 0
README.markdown View File

@@ -0,0 +1,11 @@
1
+# new.jacky.wtf
2
+
3
+This represents the foundation of my next-generation website. It's written
4
+from the ground-up by hand with a plug-in design but purely for my use.
5
+I plan to run this on my host machine using Dokku.
6
+
7
+### Licensing
8
+
9
+This project's source code is licensed under the [AGPL3][1].
10
+
11
+[1]: https://choosealicense.com/licenses/agpl-3.0/

+ 8
- 0
app.json View File

@@ -0,0 +1,8 @@
1
+{
2
+  "scripts": {
3
+    "dokku": {
4
+      "predeploy": "sh /tmp/jackywtf-docker/docker-pre-deploy.sh",
5
+      "postdeploy": "sh /tmp/jackywtf-docker/docker-post-deploy.sh"
6
+    }
7
+  }
8
+}

+ 24
- 0
config/config.exs View File

@@ -0,0 +1,24 @@
1
+use Mix.Config
2
+
3
+config :sasl,
4
+  sasl_error_logger: false
5
+
6
+config :jackywtf,
7
+  namespace: JackyWtf,
8
+  ecto_repos: [JackyWtf.Repo]
9
+
10
+config :jackywtf, JackyWtf.Web.Endpoint,
11
+  url: [host: "localhost"],
12
+  secret_key_base: "JMvhrSIqvdWnUF9h/aF6sb6nV5FnZUOW284Fg58YXmo+mWWtPH7lhg5A1jNe2guG",
13
+  render_errors: [view: JackyWtf.Web.ErrorView, accepts: ~w(html json)],
14
+  pubsub: [name: JackyWtf.PubSub,
15
+           adapter: Phoenix.PubSub.PG2]
16
+
17
+config :logger, :console,
18
+  format: "$time $metadata[$level] $message\n",
19
+  metadata: [:user_id]
20
+
21
+config :seedex,
22
+  repo: JackyWtf.Repo
23
+
24
+import_config "#{Mix.env}.exs"

+ 30
- 0
config/dev.exs View File

@@ -0,0 +1,30 @@
1
+use Mix.Config
2
+
3
+config :jackywtf, JackyWtf.Web.Endpoint,
4
+  http: [port: 4000],
5
+  debug_errors: true,
6
+  code_reloader: true,
7
+  check_origin: false,
8
+  watchers: []
9
+
10
+config :jackywtf, JackyWtf.Web.Endpoint,
11
+  reloadable_compilers: [
12
+    :gettext,
13
+    :elixir
14
+  ],
15
+  live_reload: [
16
+    patterns: [
17
+      ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
18
+      ~r{priv/gettext/.*(po)$},
19
+      ~r{lib/jackywtf_web/views/.*(ex)$},
20
+      ~r{lib/jackywtf_web/templates/.*(eex)$}
21
+    ]
22
+  ]
23
+
24
+config :logger, :console, format: "[$level] $message\n"
25
+
26
+config :phoenix, :stacktrace_depth, 20
27
+
28
+config :jackywtf, JackyWtf.Repo,
29
+  adapter: Sqlite.Ecto2, 
30
+  database: "priv/repo/db/dev.db"

+ 12
- 0
config/prod.exs View File

@@ -0,0 +1,12 @@
1
+use Mix.Config
2
+
3
+config :jackywtf, JackyWtf.Web.Endpoint,
4
+  load_from_system_env: true,
5
+  url: [host: "0.0.0.0", port: 5000],
6
+  cache_static_manifest: "priv/static/cache_manifest.json"
7
+
8
+config :logger, level: :info
9
+
10
+config :jackywtf, JackyWtf.Repo,
11
+  adapter: Sqlite.Ecto2, 
12
+  database: "/opt/jacky-wtf/priv/repo/db/prod.db"

+ 11
- 0
config/test.exs View File

@@ -0,0 +1,11 @@
1
+use Mix.Config
2
+
3
+config :jackywtf, JackyWtf.Web.Endpoint,
4
+  http: [port: 4001],
5
+  server: false
6
+
7
+config :logger, level: :warn
8
+
9
+config :jackywtf, JackyWtf.Repo,
10
+  adapter: Sqlite.Ecto2, 
11
+  database: "priv/repo/db/test.db"

+ 24
- 0
docker-compose.yml View File

@@ -0,0 +1,24 @@
1
+---
2
+version: "3.2"
3
+services:
4
+  redis:
5
+    image: redis:alpine
6
+  site:
7
+    build:
8
+      context: "."
9
+      args:
10
+        MIX_ENV: dev
11
+    command: mix start
12
+    links:
13
+      - redis
14
+    environment:
15
+      MIX_ENV: dev
16
+    ports:
17
+      - "4000:4000"
18
+    volumes:
19
+      - type: bind
20
+        source: .
21
+        target: /opt/jacky-wtf
22
+      - type: bind
23
+        source: ./priv/repo/db
24
+        target: /opt/jacky-wtf/priv/repo/db

+ 16
- 0
docker/scripts/docker-build.sh View File

@@ -0,0 +1,16 @@
1
+#!/bin/sh
2
+
3
+cd /opt/jacky-wtf || exit
4
+
5
+echo "---> [mix] Preparing..."
6
+mix local.hex --force
7
+mix local.rebar --force
8
+
9
+echo "---> [mix] Fetching dependencies..."
10
+mix deps.get
11
+
12
+echo "---> [mix] Building dependencies..."
13
+mix deps.compile
14
+
15
+echo "---> [mix] Compiling application..."
16
+mix compile

+ 6
- 0
docker/scripts/docker-cleanup.sh View File

@@ -0,0 +1,6 @@
1
+#!/bin/sh
2
+
3
+apk del build
4
+
5
+cd /opt/jacky-wtf
6
+chown jackywtf . -R

+ 3
- 0
docker/scripts/docker-post-deploy.sh View File

@@ -0,0 +1,3 @@
1
+#!/bin/sh
2
+
3
+echo "---> [deploy:post] Nothing to do post-deploy (yet)."

+ 12
- 0
docker/scripts/docker-pre-deploy.sh View File

@@ -0,0 +1,12 @@
1
+#!/bin/sh
2
+
3
+cd /opt/jacky-wtf || exit 10
4
+
5
+echo "---> [deploy:pre] Creating database..."
6
+mix ecto.create || exit 20
7
+
8
+echo "---> [deploy:pre] Migrating database..."
9
+mix ecto.migrate || exit 30
10
+
11
+echo "---> [deploy:pre] Update static digests..."
12
+mix phx.digest || exit 40

+ 27
- 0
docker/scripts/docker-prepare.sh View File

@@ -0,0 +1,27 @@
1
+#!/bin/sh
2
+
3
+echo "---> [apk] Fetching baseline packages..."
4
+apk add --no-cache \
5
+  bash \
6
+  ca-certificates \
7
+  coreutils \
8
+  shadow \
9
+  tzdata \
10
+  sqlite-libs \
11
+  inotify-tools
12
+
13
+echo "---> [apk] Fetching development packages..."
14
+apk add --no-cache --virtual=build \
15
+  gcc \
16
+  build-base \
17
+  binutils-dev \
18
+  libelf-dev \
19
+  sqlite-dev
20
+
21
+adduser jackywtf jackywtf \
22
+  -h /var/lib/jackywtf \
23
+  -D
24
+
25
+mkdir -p /opt/jacky-wtf/priv/repo/db
26
+chmod u+rw,g+rw -Rc /opt/jacky-wtf
27
+chown jackywtf:jackywtf -Rc /opt/jacky-wtf

+ 21
- 0
lib/application.ex View File

@@ -0,0 +1,21 @@
1
+defmodule JackyWtf.Application do
2
+  use Application
3
+
4
+  def start(_type, _args) do
5
+    import Supervisor.Spec
6
+
7
+    children = [
8
+      supervisor(JackyWtf.Repo, []),
9
+      supervisor(JackyWtf.Web.Endpoint, []),
10
+    ]
11
+
12
+    opts = [strategy: :one_for_one, name: JackyWtf.Supervisor]
13
+    Supervisor.start_link(children, opts)
14
+  end
15
+
16
+  def config_change(changed, _new, removed) do
17
+    JackyWtf.Web.Endpoint.config_change(changed, removed)
18
+
19
+    :ok
20
+  end
21
+end

+ 2
- 0
lib/jackywtf.ex View File

@@ -0,0 +1,2 @@
1
+defmodule JackyWtf do
2
+end

+ 11
- 0
lib/repo.ex View File

@@ -0,0 +1,11 @@
1
+defmodule JackyWtf.Repo do
2
+  use Ecto.Repo, otp_app: :jackywtf
3
+
4
+  @doc """
5
+  Dynamically loads the repository url from the
6
+  DATABASE_URL environment variable.
7
+  """
8
+  def init(_, opts) do
9
+    {:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
10
+  end
11
+end

+ 18
- 0
lib/repo/entry.ex View File

@@ -0,0 +1,18 @@
1
+defmodule JackyWtf.Repo.Entry do
2
+  use Ecto.Schema
3
+  import Ecto.Changeset
4
+
5
+
6
+  schema "entries" do
7
+    field :slug, :string
8
+
9
+    timestamps()
10
+  end
11
+
12
+  @doc false
13
+  def changeset(entry, attrs) do
14
+    entry
15
+    |> cast(attrs, [:slug])
16
+    |> validate_required([:slug])
17
+  end
18
+end

+ 21
- 0
lib/repo/object.ex View File

@@ -0,0 +1,21 @@
1
+defmodule JackyWtf.Repo.Object do
2
+  use Ecto.Schema
3
+  import Ecto.Changeset
4
+
5
+
6
+  @primary_key {:id, :binary_id, autogenerate: true}
7
+  @foreign_key_type :binary_id
8
+  schema "objects" do
9
+    field :storage, :string
10
+    field :uri, :string
11
+
12
+    timestamps()
13
+  end
14
+
15
+  @doc false
16
+  def changeset(object, attrs) do
17
+    object
18
+    |> cast(attrs, [:storage, :uri])
19
+    |> validate_required([:storage, :uri])
20
+  end
21
+end

+ 47
- 0
lib/web.ex View File

@@ -0,0 +1,47 @@
1
+defmodule JackyWtf.Web do
2
+  def controller do
3
+    quote do
4
+      use Phoenix.Controller, namespace: JackyWtf.Web
5
+
6
+      import Plug.Conn
7
+      import JackyWtf.Web.Router.Helpers
8
+      import JackyWtf.Web.Gettext
9
+    end
10
+  end
11
+
12
+  def view do
13
+    quote do
14
+      use Phoenix.View, root: "lib/web/templates", namespace: JackyWtf.Web
15
+      use Phoenix.HTML
16
+
17
+      import Phoenix.Controller, only: [get_flash: 2, view_module: 1]
18
+      import JackyWtf.Web.Router.Helpers
19
+      import JackyWtf.Web.ErrorHelpers
20
+      import JackyWtf.Web.Gettext
21
+    end
22
+  end
23
+
24
+  def router do
25
+    quote do
26
+      use Phoenix.Router
27
+
28
+      import Plug.Conn
29
+      import Phoenix.Controller
30
+    end
31
+  end
32
+
33
+  def channel do
34
+    quote do
35
+      use Phoenix.Channel
36
+
37
+      import JackyWtf.Web.Gettext
38
+    end
39
+  end
40
+
41
+  @doc """
42
+  When used, dispatch to the appropriate controller/view/etc.
43
+  """
44
+  defmacro __using__(which) when is_atom(which) do
45
+    apply(__MODULE__, which, [])
46
+  end
47
+end

+ 37
- 0
lib/web/channels/user_socket.ex View File

@@ -0,0 +1,37 @@
1
+defmodule JackyWtf.Web.UserSocket do
2
+  use Phoenix.Socket
3
+
4
+  ## Channels
5
+  # channel "room:*", JackyWtf.Web.RoomChannel
6
+
7
+  ## Transports
8
+  transport :websocket, Phoenix.Transports.WebSocket
9
+  # transport :longpoll, Phoenix.Transports.LongPoll
10
+
11
+  # Socket params are passed from the client and can
12
+  # be used to verify and authenticate a user. After
13
+  # verification, you can put default assigns into
14
+  # the socket that will be set for all channels, ie
15
+  #
16
+  #     {:ok, assign(socket, :user_id, verified_user_id)}
17
+  #
18
+  # To deny connection, return `:error`.
19
+  #
20
+  # See `Phoenix.Token` documentation for examples in
21
+  # performing token verification on connect.
22
+  def connect(_params, socket) do
23
+    {:ok, socket}
24
+  end
25
+
26
+  # Socket id's are topics that allow you to identify all sockets for a given user:
27
+  #
28
+  #     def id(socket), do: "user_socket:#{socket.assigns.user_id}"
29
+  #
30
+  # Would allow you to broadcast a "disconnect" event and terminate
31
+  # all active sockets and channels for a given user:
32
+  #
33
+  #     JackyWtf.Web.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
34
+  #
35
+  # Returning `nil` makes this socket anonymous.
36
+  def id(_socket), do: nil
37
+end

+ 37
- 0
lib/web/controllers/entry_controller.ex View File

@@ -0,0 +1,37 @@
1
+defmodule JackyWtf.Web.EntryController do
2
+  use JackyWtf.Web, :controller
3
+  alias JackyWtf.Repo
4
+  alias JackyWtf.Repo.Entry
5
+
6
+  def index(conn, params) do
7
+    entries = Repo.all Entry
8
+    render conn, "index.html", %{entries: entries}
9
+  end
10
+
11
+  def show(conn, params) do
12
+    id = params["id"]
13
+    entry = Repo.get! Entry, id
14
+    json(conn, %{
15
+      id: entry.id,
16
+      slug: entry.slug,
17
+      createdAt: entry.inserted_at,
18
+      updatedAt: entry.updated_at
19
+    })
20
+  end
21
+
22
+  def insert(conn, params) do
23
+    new_entry = %Entry{slug: params["slug"]}
24
+
25
+    case Repo.insert new_entry do
26
+      {:ok, entry} ->
27
+        json(conn, %{
28
+          id: entry.id,
29
+          slug: entry.slug,
30
+          createdAt: entry.inserted_at,
31
+          updatedAt: entry.updated_at
32
+        })
33
+      {:error, changeset} ->
34
+        Apex.ap(changeset)
35
+    end
36
+  end
37
+end

+ 15
- 0
lib/web/controllers/indie/auth_api_controller.ex View File

@@ -0,0 +1,15 @@
1
+defmodule JackyWtf.Web.Indie.AuthApiController do
2
+  use JackyWtf.Web, :controller
3
+
4
+  def authorize(conn, _params) do
5
+    params = %{
6
+      code: "dfjdlkfjdslkfsdlkfkldfjkl",
7
+      state: "asdsdasdasd"
8
+    }
9
+
10
+    encoded_params = URI.encode_query(params)
11
+    client_uri = "http://localhost:4000?#{encoded_params}"
12
+
13
+    redirect conn, external: client_uri
14
+  end
15
+end

+ 17
- 0
lib/web/controllers/indie/auth_controller.ex View File

@@ -0,0 +1,17 @@
1
+defmodule JackyWtf.Web.Indie.AuthController do
2
+  use JackyWtf.Web, :controller
3
+
4
+  def authorize(conn, _params) do
5
+    params = conn.params
6
+    Apex.ap params
7
+
8
+    render conn, "authorize.html", params
9
+  end
10
+
11
+  def verify_authorize(conn, _params) do
12
+    params = conn.params
13
+    Apex.ap params
14
+
15
+    render conn, "verify_authorize.json", params
16
+  end
17
+end

+ 7
- 0
lib/web/controllers/page_controller.ex View File

@@ -0,0 +1,7 @@
1
+defmodule JackyWtf.Web.PageController do
2
+  use JackyWtf.Web, :controller
3
+
4
+  def index(conn, _params) do
5
+    render conn, "index.html"
6
+  end
7
+end

+ 41
- 0
lib/web/endpoint.ex View File

@@ -0,0 +1,41 @@
1
+defmodule JackyWtf.Web.Endpoint do
2
+  use Phoenix.Endpoint, otp_app: :jackywtf
3
+
4
+  socket "/socket", JackyWtf.Web.UserSocket
5
+
6
+  plug Plug.Static,
7
+    at: "/", from: :jackywtf, gzip: false,
8
+    only: ~w(css fonts images js favicon.ico robots.txt)
9
+
10
+  if code_reloading? do
11
+    socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
12
+    plug Phoenix.LiveReloader
13
+    plug Phoenix.CodeReloader
14
+  end
15
+
16
+  plug Plug.Logger
17
+
18
+  plug Plug.Parsers,
19
+    parsers: [:urlencoded, :multipart, :json],
20
+    pass: ["*/*"],
21
+    json_decoder: Poison
22
+
23
+  plug Plug.MethodOverride
24
+  plug Plug.Head
25
+
26
+  plug Plug.Session,
27
+    store: :cookie,
28
+    key: "_jackywtf_key",
29
+    signing_salt: "iTHwV/C8"
30
+
31
+  plug JackyWtf.Web.Router
32
+
33
+  def init(_key, config) do
34
+    if config[:load_from_system_env] do
35
+      port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
36
+      {:ok, Keyword.put(config, :http, [:inet6, port: port])}
37
+    else
38
+      {:ok, config}
39
+    end
40
+  end
41
+end

+ 3
- 0
lib/web/gettext.ex View File

@@ -0,0 +1,3 @@
1
+defmodule JackyWtf.Web.Gettext do
2
+  use Gettext, otp_app: :jackywtf
3
+end

+ 33
- 0
lib/web/router.ex View File

@@ -0,0 +1,33 @@
1
+defmodule JackyWtf.Web.Router do
2
+  use JackyWtf.Web, :router
3
+
4
+  pipeline :browser do
5
+    plug :accepts, ["html"]
6
+    plug :fetch_session
7
+    plug :fetch_flash
8
+    plug :protect_from_forgery
9
+    plug :put_secure_browser_headers
10
+  end
11
+
12
+  pipeline :api do
13
+    plug :accepts, ["json"]
14
+  end
15
+
16
+  scope "/", JackyWtf.Web do
17
+    pipe_through :browser
18
+
19
+    get "/", PageController, :index
20
+
21
+    resources "/entries", EntryController, only: [:index, :show]
22
+
23
+    get "/indie/auth", Indie.AuthController, :authorize
24
+    post "/indie/auth", Indie.AuthController, :verify_authorize
25
+  end
26
+
27
+  scope "/api", JackyWtf.Web do
28
+    pipe_through :api
29
+
30
+    post "/indie/auth", Indie.AuthApiController, :authorize
31
+    resources "/entries", EntryController, only: [:index, :show]
32
+  end
33
+end

+ 9
- 0
lib/web/templates/entry/index.html.eex View File

@@ -0,0 +1,9 @@
1
+<ul class="list">
2
+  <%= for entry <- entries(@conn) do %>
3
+    <li>
4
+      <a href="<%= entry_path(@conn, :show, entry.id) %>"><%= entry.slug %></a>
5
+      &mdash;
6
+      <a href="/api/<%= entry_path(@conn, :show, entry.id) %>"><%= entry.slug %></a>
7
+    </li>
8
+  <% end %>
9
+</uldf

+ 0
- 0
lib/web/templates/indie/auth.html.eex View File


+ 18
- 0
lib/web/templates/indie/auth/authorize.html.eex View File

@@ -0,0 +1,18 @@
1
+<form class="measure center" method="post" action="/api/indie/auth">
2
+  <fieldset class="ba b--transparent ph0 mh0">
3
+    <legend class="f4 fw6 ph0 mh0 system-sans-serif">Sign In</legend>
4
+    <p class="lh-copy f4">
5
+      D
6
+    </p>
7
+    <div class="mv3">
8
+      <label class="dib fw6 lh-copy f6 system-sans-serif" for="me">Site URI</label>
9
+      <span class="dib code"><%= client_id(@conn) %></span>
10
+    </div>
11
+
12
+    <input type=hidden name=client_id value="<%= client_id(@conn) %>" />
13
+    <input type=hidden name=redirect_uri value="<%= redirect_uri(@conn) %>" />
14
+    <input type=hidden name=state value="<%= state(@conn) %>" />
15
+    <input type=hidden name=response_type value="<%= response_type(@conn) %>" />
16
+    <button class="ba b--black pa2 bg-near-black near-white system-sans-serif" type="submit">Approve</button>
17
+  </fieldset>
18
+</form>

+ 3
- 0
lib/web/templates/indie/auth/verify_authorize.json.eex View File

@@ -0,0 +1,3 @@
1
+{
2
+  "me": "<%= me(@conn) %>"
3
+}

+ 38
- 0
lib/web/templates/layout/app.html.eex View File

@@ -0,0 +1,38 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+  <head>
4
+    <meta charset="utf-8">
5
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+    <meta name="viewport" content="width=device-width, initial-scale=1">
7
+    <meta name="description" content="">
8
+    <meta name="author" content="">
9
+    <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+    <title>jacky.wtf</title>
12
+    <link rel="authorization_endpoint" href="https://nextgen.jacky.wtf/indie/auth">
13
+    <link rel="token_endpoint" href="https://tokens.indieauth.com/token">
14
+    <link rel="stylesheet" href="https://unpkg.com/tachyons@4.10.0/css/tachyons.min.css"/>
15
+    <link rel="icon" type="image/png" href="https://jacky.wtf/assets/16x16-9bbbdcee28e8dd81db7a8208916f96b5e13d0f1092003786fbe4ce799aa93cba.png" sizes="16x16" />
16
+  </head>
17
+
18
+  <body class="pa2">
19
+    <header></header>
20
+    <section>
21
+      <p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
22
+      <p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
23
+    </section>
24
+    <main role="main">
25
+      <%= render @view_module, @view_template, assigns %>
26
+    </main>
27
+    <footer></footer>
28
+    <script src="<%= static_path(@conn, "/js/app.js") %>"></script>
29
+    <script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
30
+    <script>
31
+      WebFont.load({
32
+        google: {
33
+          families: ['Droid Sans', 'Droid Serif']
34
+        }
35
+      });
36
+    </script>
37
+  </body>
38
+</html>

+ 3
- 0
lib/web/templates/page/index.html.eex View File

@@ -0,0 +1,3 @@
1
+<h1 class="lh-title f1 tc sans-serif"><%= gettext "%{name}!", name: "jacky.wtf" %></h1>
2
+
3
+<a href="<%= entry_path(@conn, :index) %>">All Posts</a>

+ 7
- 0
lib/web/views/entry_view.ex View File

@@ -0,0 +1,7 @@
1
+defmodule JackyWtf.Web.EntryView do
2
+  use JackyWtf.Web, :view
3
+
4
+  def entries(conn) do
5
+    conn.assigns.entries
6
+  end
7
+end

+ 44
- 0
lib/web/views/error_helpers.ex View File

@@ -0,0 +1,44 @@
1
+defmodule JackyWtf.Web.ErrorHelpers do
2
+  @moduledoc """
3
+  Conveniences for translating and building error messages.
4
+  """
5
+
6
+  use Phoenix.HTML
7
+
8
+  @doc """
9
+  Generates tag for inlined form input errors.
10
+  """
11
+  def error_tag(form, field) do
12
+    Enum.map(Keyword.get_values(form.errors, field), fn (error) ->
13
+      content_tag :span, translate_error(error), class: "help-block"
14
+    end)
15
+  end
16
+
17
+  @doc """
18
+  Translates an error message using gettext.
19
+  """
20
+  def translate_error({msg, opts}) do
21
+    # When using gettext, we typically pass the strings we want
22
+    # to translate as a static argument:
23
+    #
24
+    #     # Translate "is invalid" in the "errors" domain
25
+    #     dgettext "errors", "is invalid"
26
+    #
27
+    #     # Translate the number of files with plural rules
28
+    #     dngettext "errors", "1 file", "%{count} files", count
29
+    #
30
+    # Because the error messages we show in our forms and APIs
31
+    # are defined inside Ecto, we need to translate them dynamically.
32
+    # This requires us to call the Gettext module passing our gettext
33
+    # backend as first argument.
34
+    #
35
+    # Note we use the "errors" domain, which means translations
36
+    # should be written to the errors.po file. The :count option is
37
+    # set by Ecto and indicates we should also apply plural rules.
38
+    if count = opts[:count] do
39
+      Gettext.dngettext(JackyWtf.Web.Gettext, "errors", msg, msg, count, opts)
40
+    else
41
+      Gettext.dgettext(JackyWtf.Web.Gettext, "errors", msg, opts)
42
+    end
43
+  end
44
+end

+ 16
- 0
lib/web/views/error_view.ex View File

@@ -0,0 +1,16 @@
1
+defmodule JackyWtf.Web.ErrorView do
2
+  use JackyWtf.Web, :view
3
+
4
+  # If you want to customize a particular status code
5
+  # for a certain format, you may uncomment below.
6
+  # def render("500.html", _assigns) do
7
+  #   "Internal Server Error"
8
+  # end
9
+
10
+  # By default, Phoenix returns the status message from
11
+  # the template name. For example, "404.html" becomes
12
+  # "Not Found".
13
+  def template_not_found(template, _assigns) do
14
+    Phoenix.Controller.status_message_from_template(template)
15
+  end
16
+end

+ 27
- 0
lib/web/views/indie/auth_view.ex View File

@@ -0,0 +1,27 @@
1
+defmodule JackyWtf.Web.Indie.AuthView do
2
+  use JackyWtf.Web, :view
3
+
4
+  def title do
5
+    "view: indie/auth"
6
+  end
7
+
8
+  def me(conn) do
9
+    conn.params["me"]
10
+  end
11
+
12
+  def client_id(conn) do
13
+    conn.params["client_id"]
14
+  end
15
+
16
+  def redirect_uri(conn) do
17
+    conn.params["redirect_uri"]
18
+  end
19
+
20
+  def state(conn) do
21
+    conn.params["state"]
22
+  end
23
+
24
+  def response_type(conn) do
25
+    conn.params["response_type"]
26
+  end
27
+end

+ 7
- 0
lib/web/views/layout_view.ex View File

@@ -0,0 +1,7 @@
1
+defmodule JackyWtf.Web.LayoutView do
2
+  use JackyWtf.Web, :view
3
+
4
+  def title do
5
+    "jacky.wtf"
6
+  end
7
+end

+ 7
- 0
lib/web/views/page_view.ex View File

@@ -0,0 +1,7 @@
1
+defmodule JackyWtf.Web.PageView do
2
+  use JackyWtf.Web, :view
3
+
4
+  def title do
5
+    "jacky.wtf"
6
+  end
7
+end

+ 54
- 0
mix.exs View File

@@ -0,0 +1,54 @@
1
+defmodule JackyWtf.Mixfile do
2
+  use Mix.Project
3
+
4
+  def project do
5
+    [
6
+      app: :jackywtf,
7
+      version: "0.0.1",
8
+      elixir: "~> 1.6",
9
+      elixirc_paths: elixirc_paths(Mix.env),
10
+      compilers: [:phoenix, :gettext] ++ Mix.compilers,
11
+      start_permanent: Mix.env == :prod,
12
+      aliases: aliases(),
13
+      deps: deps()
14
+    ]
15
+  end
16
+
17
+  def application do
18
+    [
19
+      mod: {JackyWtf.Application, []},
20
+      extra_applications: [:logger, :runtime_tools]
21
+    ]
22
+  end
23
+
24
+  defp elixirc_paths(:test), do: ["lib", "test/support"]
25
+  defp elixirc_paths(_),     do: ["lib"]
26
+
27
+  defp deps do
28
+    [
29
+      {:phoenix, "~> 1.3.4"},
30
+      {:ecto, "~> 2.2"},
31
+      {:phoenix_pubsub, "~> 1.0"},
32
+      {:phoenix_ecto, "~> 3.2"},
33
+      {:sqlite_ecto2, "~> 2.2.5"},
34
+      {:phoenix_html, "~> 2.10"},
35
+      {:phoenix_live_reload, "~> 1.0", only: :dev},
36
+      {:gettext, "~> 0.11"},
37
+      {:cowboy, "~> 1.0"},
38
+      {:apex, "~> 1.2.1"},
39
+      {:seedex, "~> 0.1.2"},
40
+      {:httpoison, "~> 1.3"},
41
+      {:httpoison_retry, "~> 1.0.0"},
42
+      {:floki, "~> 0.20.0"}
43
+    ]
44
+  end
45
+
46
+  defp aliases do
47
+    [
48
+      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
49
+      "ecto.reset": ["ecto.drop", "ecto.setup"],
50
+      test: ["ecto.create --quiet", "ecto.migrate", "test"],
51
+      start: ["phx.server"]
52
+    ]
53
+  end
54
+end

+ 40
- 0
mix.lock View File

@@ -0,0 +1,40 @@
1
+%{
2
+  "apex": {:hex, :apex, "1.2.1", "297f5dac23fa2a32648b890a0838fce2772114010e0b9ec975cae6021cc5a092", [:mix], [], "hexpm"},
3
+  "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
4
+  "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
5
+  "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
6
+  "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
7
+  "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
8
+  "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
9
+  "ecto": {:hex, :ecto, "2.2.9", "031d55df9bb430cb118e6f3026a87408d9ce9638737bda3871e5d727a3594aae", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
10
+  "esqlite": {:hex, :esqlite, "0.2.4", "3a8a352c190afe2d6b828b252a6fbff65b5cc1124647f38b15bdab3bf6fd4b3e", [:rebar3], [], "hexpm"},
11
+  "file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
12
+  "floki": {:hex, :floki, "0.20.4", "be42ac911fece24b4c72f3b5846774b6e61b83fe685c2fc9d62093277fb3bc86", [:mix], [{:html_entities, "~> 0.4.0", [hex: :html_entities, repo: "hexpm", optional: false]}, {:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm"},
13
+  "gettext": {:hex, :gettext, "0.16.0", "4a7e90408cef5f1bf57c5a39e2db8c372a906031cc9b1466e963101cb927dafc", [:mix], [], "hexpm"},
14
+  "hackney": {:hex, :hackney, "1.14.0", "66e29e78feba52176c3a4213d42b29bdc4baff93a18cfe480f73b04677139dee", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
15
+  "html_entities": {:hex, :html_entities, "0.4.0", "f2fee876858cf6aaa9db608820a3209e45a087c5177332799592142b50e89a6b", [:mix], [], "hexpm"},
16
+  "httpoison": {:hex, :httpoison, "1.3.1", "7ac607311f5f706b44e8b3fab736d0737f2f62a31910ccd9afe7227b43edb7f0", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
17
+  "httpoison_retry": {:hex, :httpoison_retry, "1.0.1", "1dd7d8f39079ae43a74bc787e3b86cc925e97b2e32fb9279420060b4a25cec30", [:mix], [{:httpoison, "~> 0.13 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}], "hexpm"},
18
+  "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
19
+  "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
20
+  "mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
21
+  "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
22
+  "mochiweb": {:hex, :mochiweb, "2.18.0", "eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e", [:rebar3], [], "hexpm"},
23
+  "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
24
+  "phoenix": {:hex, :phoenix, "1.3.4", "aaa1b55e5523083a877bcbe9886d9ee180bf2c8754905323493c2ac325903dc5", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
25
+  "phoenix_ecto": {:hex, :phoenix_ecto, "3.4.0", "91cd39427006fe4b5588d69f0941b9c3d3d8f5e6477c563a08379de7de2b0c58", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
26
+  "phoenix_html": {:hex, :phoenix_html, "2.12.0", "1fb3c2e48b4b66d75564d8d63df6d53655469216d6b553e7e14ced2b46f97622", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
27
+  "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.5", "8d4c9b1ef9ca82deee6deb5a038d6d8d7b34b9bb909d99784a49332e0d15b3dc", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
28
+  "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.0", "d55e25ff1ff8ea2f9964638366dfd6e361c52dedfd50019353598d11d4441d14", [:mix], [], "hexpm"},
29
+  "plug": {:hex, :plug, "1.6.3", "43088304337b9e8b8bd22a0383ca2f633519697e4c11889285538148f42cbc5e", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
30
+  "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
31
+  "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
32
+  "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
33
+  "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
34
+  "sbroker": {:hex, :sbroker, "1.0.0", "28ff1b5e58887c5098539f236307b36fe1d3edaa2acff9d6a3d17c2dcafebbd0", [:rebar3], [], "hexpm"},
35
+  "seedex": {:hex, :seedex, "0.1.4", "29ec6518964689dd6da2d285b622cfdcbe950954539e9bbcac9ee653f49d7b68", [:mix], [{:ecto, "~> 1.1 or ~> 2.1", [hex: :ecto, repo: "hexpm", optional: false]}], "hexpm"},
36
+  "sqlite_ecto2": {:hex, :sqlite_ecto2, "2.2.5", "f111a48188b0640effb7f2952071c4cf285501d3ce090820a7c2fc20af3867e9", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "2.2.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: false]}, {:sqlitex, "~> 1.4", [hex: :sqlitex, repo: "hexpm", optional: false]}], "hexpm"},
37
+  "sqlitex": {:hex, :sqlitex, "1.4.3", "a50f12d6aeb25f4ebb128453386c09bbba8f5abd3c7713dc5eaa92f359926ac5", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:esqlite, "~> 0.2.4", [hex: :esqlite, repo: "hexpm", optional: false]}], "hexpm"},
38
+  "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
39
+  "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
40
+}

+ 97
- 0
priv/gettext/en/LC_MESSAGES/errors.po View File

@@ -0,0 +1,97 @@
1
+## `msgid`s in this file come from POT (.pot) files.
2
+##
3
+## Do not add, change, or remove `msgid`s manually here as
4
+## they're tied to the ones in the corresponding POT file
5
+## (with the same domain).
6
+##
7
+## Use `mix gettext.extract --merge` or `mix gettext.merge`
8
+## to merge POT files into PO files.
9
+msgid ""
10
+msgstr ""
11
+"Language: en\n"
12
+
13
+## From Ecto.Changeset.cast/4
14
+msgid "can't be blank"
15
+msgstr ""
16
+
17
+## From Ecto.Changeset.unique_constraint/3
18
+msgid "has already been taken"
19
+msgstr ""
20
+
21
+## From Ecto.Changeset.put_change/3
22
+msgid "is invalid"
23
+msgstr ""
24
+
25
+## From Ecto.Changeset.validate_acceptance/3
26
+msgid "must be accepted"
27
+msgstr ""
28
+
29
+## From Ecto.Changeset.validate_format/3
30
+msgid "has invalid format"
31
+msgstr ""
32
+
33
+## From Ecto.Changeset.validate_subset/3
34
+msgid "has an invalid entry"
35
+msgstr ""
36
+
37
+## From Ecto.Changeset.validate_exclusion/3
38
+msgid "is reserved"
39
+msgstr ""
40
+
41
+## From Ecto.Changeset.validate_confirmation/3
42
+msgid "does not match confirmation"
43
+msgstr ""
44
+
45
+## From Ecto.Changeset.no_assoc_constraint/3
46
+msgid "is still associated with this entry"
47
+msgstr ""
48
+
49
+msgid "are still associated with this entry"
50
+msgstr ""
51
+
52
+## From Ecto.Changeset.validate_length/3
53
+msgid "should be %{count} character(s)"
54
+msgid_plural "should be %{count} character(s)"
55
+msgstr[0] ""
56
+msgstr[1] ""
57
+
58
+msgid "should have %{count} item(s)"
59
+msgid_plural "should have %{count} item(s)"
60
+msgstr[0] ""
61
+msgstr[1] ""
62
+
63
+msgid "should be at least %{count} character(s)"
64
+msgid_plural "should be at least %{count} character(s)"
65
+msgstr[0] ""
66
+msgstr[1] ""
67
+
68
+msgid "should have at least %{count} item(s)"
69
+msgid_plural "should have at least %{count} item(s)"
70
+msgstr[0] ""
71
+msgstr[1] ""
72
+
73
+msgid "should be at most %{count} character(s)"
74
+msgid_plural "should be at most %{count} character(s)"
75
+msgstr[0] ""
76
+msgstr[1] ""
77
+
78
+msgid "should have at most %{count} item(s)"
79
+msgid_plural "should have at most %{count} item(s)"
80
+msgstr[0] ""
81
+msgstr[1] ""
82
+
83
+## From Ecto.Changeset.validate_number/3
84
+msgid "must be less than %{number}"
85
+msgstr ""
86
+
87
+msgid "must be greater than %{number}"
88
+msgstr ""
89
+
90
+msgid "must be less than or equal to %{number}"
91
+msgstr ""
92
+
93
+msgid "must be greater than or equal to %{number}"
94
+msgstr ""
95
+
96
+msgid "must be equal to %{number}"
97
+msgstr ""

+ 95
- 0
priv/gettext/errors.pot View File

@@ -0,0 +1,95 @@
1
+## This file is a PO Template file.
2
+##
3
+## `msgid`s here are often extracted from source code.
4
+## Add new translations manually only if they're dynamic
5
+## translations that can't be statically extracted.
6
+##
7
+## Run `mix gettext.extract` to bring this file up to
8
+## date. Leave `msgstr`s empty as changing them here as no
9
+## effect: edit them in PO (`.po`) files instead.
10
+
11
+## From Ecto.Changeset.cast/4
12
+msgid "can't be blank"
13
+msgstr ""
14
+
15
+## From Ecto.Changeset.unique_constraint/3
16
+msgid "has already been taken"
17
+msgstr ""
18
+
19
+## From Ecto.Changeset.put_change/3
20
+msgid "is invalid"
21
+msgstr ""
22
+
23
+## From Ecto.Changeset.validate_acceptance/3
24
+msgid "must be accepted"
25
+msgstr ""
26
+
27
+## From Ecto.Changeset.validate_format/3
28
+msgid "has invalid format"
29
+msgstr ""
30
+
31
+## From Ecto.Changeset.validate_subset/3
32
+msgid "has an invalid entry"
33
+msgstr ""
34
+
35
+## From Ecto.Changeset.validate_exclusion/3
36
+msgid "is reserved"
37
+msgstr ""
38
+
39
+## From Ecto.Changeset.validate_confirmation/3
40
+msgid "does not match confirmation"
41
+msgstr ""
42
+
43
+## From Ecto.Changeset.no_assoc_constraint/3
44
+msgid "is still associated with this entry"
45
+msgstr ""
46
+
47
+msgid "are still associated with this entry"
48
+msgstr ""
49
+
50
+## From Ecto.Changeset.validate_length/3
51
+msgid "should be %{count} character(s)"
52
+msgid_plural "should be %{count} character(s)"
53
+msgstr[0] ""
54
+msgstr[1] ""
55
+
56
+msgid "should have %{count} item(s)"
57
+msgid_plural "should have %{count} item(s)"
58
+msgstr[0] ""
59
+msgstr[1] ""
60
+
61
+msgid "should be at least %{count} character(s)"
62
+msgid_plural "should be at least %{count} character(s)"
63
+msgstr[0] ""
64
+msgstr[1] ""
65
+
66
+msgid "should have at least %{count} item(s)"
67
+msgid_plural "should have at least %{count} item(s)"
68
+msgstr[0] ""
69
+msgstr[1] ""
70
+
71
+msgid "should be at most %{count} character(s)"
72
+msgid_plural "should be at most %{count} character(s)"
73
+msgstr[0] ""
74
+msgstr[1] ""
75
+
76
+msgid "should have at most %{count} item(s)"
77
+msgid_plural "should have at most %{count} item(s)"
78
+msgstr[0] ""
79
+msgstr[1] ""
80
+
81
+## From Ecto.Changeset.validate_number/3
82
+msgid "must be less than %{number}"
83
+msgstr ""
84
+
85
+msgid "must be greater than %{number}"
86
+msgstr ""
87
+
88
+msgid "must be less than or equal to %{number}"
89
+msgstr ""
90
+
91
+msgid "must be greater than or equal to %{number}"
92
+msgstr ""
93
+
94
+msgid "must be equal to %{number}"
95
+msgstr ""

+ 0
- 0
priv/repo/db/.gitkeep View File


+ 14
- 0
priv/repo/migrations/20180923033453_create_objects.exs View File

@@ -0,0 +1,14 @@
1
+defmodule JackyWtf.Repo.Migrations.CreateObjects do
2
+  use Ecto.Migration
3
+
4
+  def change do
5
+    create table(:objects, primary_key: false) do
6
+      add :id, :binary_id, primary_key: true
7
+      add :storage, :string
8
+      add :uri, :string
9
+
10
+      timestamps()
11
+    end
12
+
13
+  end
14
+end

+ 12
- 0
priv/repo/migrations/20180923033807_create_entries.exs View File

@@ -0,0 +1,12 @@
1
+defmodule JackyWtf.Repo.Migrations.CreateEntries do
2
+  use Ecto.Migration
3
+
4
+  def change do
5
+    create table(:entries) do
6
+      add :slug, :string
7
+
8
+      timestamps()
9
+    end
10
+
11
+  end
12
+end

+ 6
- 0
priv/repo/seeds/entry.exs View File

@@ -0,0 +1,6 @@
1
+import Seedex
2
+
3
+seed JackyWtf.Repo.Entry, fn entry ->
4
+  entry
5
+  |> Map.put(:slug, "this is it")
6
+end

+ 1
- 0
priv/static/css/app.css View File

@@ -0,0 +1 @@
1
+

BIN
priv/static/images/phoenix.png View File


+ 3
- 0
priv/static/js/app.js View File

@@ -0,0 +1,3 @@
1
+// for phoenix_html support, including form and button helpers
2
+// copy the following scripts into your javascript bundle:
3
+// * https://raw.githubusercontent.com/phoenixframework/phoenix_html/v2.10.0/priv/static/phoenix_html.js

+ 1431
- 0
priv/static/js/phoenix.js
File diff suppressed because it is too large
View File


+ 8
- 0
test/jackywtf/web/controllers/page_controller_test.exs View File

@@ -0,0 +1,8 @@
1
+defmodule JackyWtf.Web.PageControllerTest do
2
+  use JackyWtf.Web.ConnCase
3
+
4
+  test "GET /", %{conn: conn} do
5
+    conn = get conn, "/"
6
+    assert html_response(conn, 200) =~ "Welcome to Phoenix!"
7
+  end
8
+end

+ 16
- 0
test/jackywtf/web/views/error_view_test.exs View File

@@ -0,0 +1,16 @@
1
+defmodule JackyWtf.Web.ErrorViewTest do
2
+  use JackyWtf.Web.ConnCase, async: true
3
+
4
+  # Bring render/3 and render_to_string/3 for testing custom views
5
+  import Phoenix.View
6
+
7
+  test "renders 404.html" do
8
+    assert render_to_string(JackyWtf.Web.ErrorView, "404.html", []) ==
9
+           "Not Found"
10
+  end
11
+
12
+  test "renders 500.html" do
13
+    assert render_to_string(JackyWtf.Web.ErrorView, "500.html", []) ==
14
+           "Internal Server Error"
15
+  end
16
+end

+ 3
- 0
test/jackywtf/web/views/layout_view_test.exs View File

@@ -0,0 +1,3 @@
1
+defmodule JackyWtf.Web.LayoutViewTest do
2
+  use JackyWtf.Web.ConnCase, async: true
3
+end

+ 3
- 0
test/jackywtf/web/views/page_view_test.exs View File

@@ -0,0 +1,3 @@
1
+defmodule JackyWtf.Web.PageViewTest do
2
+  use JackyWtf.Web.ConnCase, async: true
3
+end

+ 35
- 0
test/support/channel_case.ex View File

@@ -0,0 +1,35 @@
1
+defmodule JackyWtf.Web.ChannelCase do
2
+  @moduledoc """
3
+  This module defines the test case to be used by
4
+  channel tests.
5
+
6
+  Such tests rely on `Phoenix.ChannelTest` and also
7
+  import other functionality to make it easier
8
+  to build common datastructures and query the data layer.
9
+
10
+  Finally, if the test case interacts with the database,
11
+  it cannot be async. For this reason, every test runs
12
+  inside a transaction which is reset at the beginning
13
+  of the test unless the test case is marked as async.
14
+  """
15
+
16
+  use ExUnit.CaseTemplate
17
+
18
+  using do
19
+    quote do
20
+      # Import conveniences for testing with channels
21
+      use Phoenix.ChannelTest
22
+
23
+      # The default endpoint for testing
24
+      @endpoint JackyWtf.Web.Endpoint
25
+    end
26
+  end
27
+
28
+  setup tags do
29
+    :ok = Ecto.Adapters.SQL.Sandbox.checkout(JackyWtf.Repo)
30
+    unless tags[:async] do
31
+      Ecto.Adapters.SQL.Sandbox.mode(JackyWtf.Repo, {:shared, self()})
32
+    end
33
+    :ok
34
+  end
35
+end

+ 38
- 0
test/support/conn_case.ex View File

@@ -0,0 +1,38 @@
1
+defmodule JackyWtf.Web.ConnCase do
2
+  @moduledoc """
3
+  This module defines the test case to be used by
4
+  tests that require setting up a connection.
5
+
6
+  Such tests rely on `Phoenix.ConnTest` and also
7
+  import other functionality to make it easier
8
+  to build common datastructures and query the data layer.
9
+
10
+  Finally, if the test case interacts with the database,
11
+  it cannot be async. For this reason, every test runs
12
+  inside a transaction which is reset at the beginning
13
+  of the test unless the test case is marked as async.
14
+  """
15
+
16
+  use ExUnit.CaseTemplate
17
+
18
+  using do
19
+    quote do
20
+      # Import conveniences for testing with connections
21
+      use Phoenix.ConnTest
22
+      import JackyWtf.Web.Router.Helpers
23
+
24
+      # The default endpoint for testing
25
+      @endpoint JackyWtf.Web.Endpoint
26
+    end
27
+  end
28
+
29
+
30
+  setup tags do
31
+    :ok = Ecto.Adapters.SQL.Sandbox.checkout(JackyWtf.Repo)
32
+    unless tags[:async] do
33
+      Ecto.Adapters.SQL.Sandbox.mode(JackyWtf.Repo, {:shared, self()})
34
+    end
35
+    {:ok, conn: Phoenix.ConnTest.build_conn()}
36
+  end
37
+
38
+end

+ 53
- 0
test/support/data_case.ex View File

@@ -0,0 +1,53 @@
1
+defmodule JackyWtf.DataCase do
2
+  @moduledoc """
3
+  This module defines the setup for tests requiring
4
+  access to the application's data layer.
5
+
6
+  You may define functions here to be used as helpers in
7
+  your tests.
8
+
9
+  Finally, if the test case interacts with the database,
10
+  it cannot be async. For this reason, every test runs
11
+  inside a transaction which is reset at the beginning
12
+  of the test unless the test case is marked as async.
13
+  """
14
+
15
+  use ExUnit.CaseTemplate
16
+
17
+  using do
18
+    quote do
19
+      alias JackyWtf.Repo
20
+
21
+      import Ecto
22
+      import Ecto.Changeset
23
+      import Ecto.Query
24
+      import JackyWtf.DataCase
25
+    end
26
+  end
27
+
28
+  setup tags do
29
+    :ok = Ecto.Adapters.SQL.Sandbox.checkout(JackyWtf.Repo)
30
+
31
+    unless tags[:async] do
32
+      Ecto.Adapters.SQL.Sandbox.mode(JackyWtf.Repo, {:shared, self()})
33
+    end
34
+
35
+    :ok
36
+  end
37
+
38
+  @doc """
39
+  A helper that transform changeset errors to a map of messages.
40
+
41
+      assert {:error, changeset} = Accounts.create_user(%{password: "short"})
42
+      assert "password is too short" in errors_on(changeset).password
43
+      assert %{password: ["password is too short"]} = errors_on(changeset)
44
+
45
+  """
46
+  def errors_on(changeset) do
47
+    Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
48
+      Enum.reduce(opts, message, fn {key, value}, acc ->
49
+        String.replace(acc, "%{#{key}}", to_string(value))
50
+      end)
51
+    end)
52
+  end
53
+end

+ 3
- 0
test/test_helper.exs View File

@@ -0,0 +1,3 @@
1
+ExUnit.start()
2
+
3
+Ecto.Adapters.SQL.Sandbox.mode(JackyWtf.Repo, :manual)

Loading…
Cancel
Save