Namdak Tonpa 5 years ago
parent
commit
b6d61fe2fe
5 changed files with 22 additions and 5 deletions
  1. 1 1
      .formatter.exs
  2. 2 1
      lib/NITRO.ex
  3. 7 1
      mix.exs
  4. 2 2
      src/nitro.app.src
  5. 10 0
      src/nitro.erl

+ 1 - 1
.formatter.exs

@@ -1,5 +1,5 @@
 # Used by "mix format"
 [
   inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
-  line_length: 133
+  line_length: 80
 ]

+ 2 - 1
lib/NITRO.ex

@@ -1,7 +1,8 @@
 defmodule NITRO do
   require Record
 
-  Enum.each(Record.extract_all(from_lib: "nitro/include/nitro.hrl"), fn {name, definition} ->
+  Enum.each(Record.extract_all(from_lib: "nitro/include/nitro.hrl"), fn {name,
+                                                                         definition} ->
     Record.defrecord(name, definition)
   end)
 end

+ 7 - 1
mix.exs

@@ -2,7 +2,13 @@ defmodule NITRO.Mixfile do
   use Mix.Project
 
   def project do
-    [app: :nitro, version: "4.7.2", description: "NITRO Web Framework and HTML5 DSL", package: package(), deps: deps()]
+    [
+      app: :nitro,
+      version: "4.7.3",
+      description: "NITRO Web Framework",
+      package: package(),
+      deps: deps()
+    ]
   end
 
   def application do

+ 2 - 2
src/nitro.app.src

@@ -1,6 +1,6 @@
 {application, nitro, [
-    {description,  "NITRO Web Framework and HTML5 DSL"},
-    {vsn,          "4.7.2"},
+    {description,  "NITRO Web Framework"},
+    {vsn,          "4.7.3"},
     {applications, [kernel, stdlib]},
     {modules, []},
     {registered,   []},

+ 10 - 0
src/nitro.erl

@@ -205,3 +205,13 @@ num(S) -> case rev(S) of
                [$M|M] -> list_to_integer(rev(M)) * 1000 * 1000;
                [$G|G] -> list_to_integer(rev(G)) * 1000 * 1000 * 1000;
                [$T|T] -> list_to_integer(rev(T)) * 1000 * 1000 * 1000 * 1000 end.
+
+cookie_expire(SecondsToLive) ->
+    Seconds = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
+    DateTime = calendar:gregorian_seconds_to_datetime(Seconds + SecondsToLive),
+    cow_date:rfc2109(DateTime).
+
+cookie(Id, Value) -> cookie(Id, Value, 2147483647). % expire never
+cookie(Id, Value, Expire) ->
+    Format = "document.cookie='~s=~s; path=/; expires=~s';",
+    nitro:wire(nitro:f(Format,[nitro:to_list(Id),nitro:to_list(Value), cookie_expire(Expire)])).