Skip to content

Commit

Permalink
Merge pull request #203 from elixir-web/0.14.1_compatibility
Browse files Browse the repository at this point in the history
Fix Compatibility with Elixir 0.14.2
  • Loading branch information
rcdilorenzo committed Jul 5, 2014
2 parents 928e237 + 51576e3 commit a909146
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 59 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ otp_release:
notifications:
recipients:
- [email protected]
- [email protected]
before_install:
- git clone https://github.com/elixir-lang/elixir
- cd elixir && make && cd ..
- cd elixir && git checkout v0.14.2 && make && cd ..
before_script:
- export PATH=`pwd`/elixir/bin:$PATH
- mix local.hex --force
- MIX_ENV=test mix do deps.get, compile
script:
- mix test --no-start
Expand Down
2 changes: 1 addition & 1 deletion examples/SimpleChat/lib/helpers/Room.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Room do
use GenServer.Behaviour
use GenServer

import Weber.Session

Expand Down
4 changes: 2 additions & 2 deletions lib/weber.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Weber do

use Application.Behaviour
use Application

require Weber.Templates.ViewsLoader

Expand Down Expand Up @@ -66,4 +66,4 @@ defmodule Weber do
:ok
end

end
end
8 changes: 4 additions & 4 deletions lib/weber/handler/weber_req_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ defmodule Handler.WeberReqHandler do
l -> String.replace(l, "-", "_")
end
# check 'lang' process
locale_process = Process.whereis(binary_to_atom(lang <> ".json"))
locale_process = Process.whereis(String.to_atom(lang <> ".json"))
case locale_process do
nil ->
case File.read(Weber.Path.__root__ <> "/deps/weber/lib/weber/i18n/localization/locale/" <> lang <> ".json") do
{:ok, locale_data} -> Weber.Localization.Locale.start_link(binary_to_atom(lang <> ".json"), locale_data)
{:ok, locale_data} -> Weber.Localization.Locale.start_link(String.to_atom(lang <> ".json"), locale_data)
_ -> :ok
end
_ -> :ok
Expand Down Expand Up @@ -116,13 +116,13 @@ defmodule Handler.WeberReqHandler do
end
end

result = state.handler.handle_result(result, conn, controller, Weber.Utils.capitalize(atom_to_binary(action)))
result = state.handler.handle_result(result, conn, controller, Weber.Utils.capitalize(Atom.to_string(action)))
# check for action/controller redirect
case result do
{:render_other_controller, _, _} ->
[controller, action] = result |> elem(1) |> String.split("#")
{controller, _} = Code.eval_string(controller)
get_response(controller, binary_to_atom(action), result |> elem(2), conn, req, state)
get_response(controller, String.to_atom(action), result |> elem(2), conn, req, state)
_ ->
handle_request(result, req, state, {controller, action, conn})
end
Expand Down
10 changes: 6 additions & 4 deletions lib/weber/handler/weber_req_handler_default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ defmodule Handler.WeberReqHandler.Default do
end

def request({:json, data, headers}, _app) do
{:json, 200, ExJSON.generate(data), :lists.append([{"Content-Type", "application/json"}], headers)}
{:ok, json} = JSEX.encode(data)
{:json, 200, json, :lists.append([{"Content-Type", "application/json"}], headers)}
end

def request({:json, status, data, headers}, _app) do
{:json, status, ExJSON.generate(data), :lists.append([{"Content-Type", "application/json"}], headers)}
{:ok, json} = JSEX.encode(data)
{:json, status, json, :lists.append([{"Content-Type", "application/json"}], headers)}
end

def request({:not_found, data, _headers}, _app) do
{:not_found, 404, data, [{"Content-Type", "text/html"}]}
end

def request({:render_other_action, action, data}, app) do
complete_action = (atom_to_binary(app.controller) <> "#" <> atom_to_binary(action)) |> String.slice(7..-1)
complete_action = (Atom.to_string(app.controller) <> "#" <> Atom.to_string(action)) |> String.slice(7..-1)
request({:render_other_controller, complete_action, data}, app)
end

Expand All @@ -59,7 +61,7 @@ defmodule Handler.WeberReqHandler.Default do
end

def request({:render_other_controller, controller, action, data}, app) when is_atom(controller) and is_atom(action) do
{:render_other_controller, atom_to_binary(controller) <> "#" <> atom_to_binary(action), data}
{:render_other_controller, Atom.to_string(controller) <> "#" <> Atom.to_string(action), data}
end

end
2 changes: 1 addition & 1 deletion lib/weber/http/url.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ defmodule Weber.Http.Url do
end)

Enum.map(filterBindings, fn({{_key1, val1}, {_key2, val2}}) ->
{:erlang.binary_to_atom(val2, :utf8), val1}
{String.to_atom(val2, :utf8), val1}
end)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/weber/i18n/i18n.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ defmodule Weber.I18n do
[] -> "en_US.json"
l -> l <> ".json"
end
date_time_format = :gen_server.call(binary_to_atom(pid), :get_date_time_format)
{date_time_format, binary_to_atom(pid)}
date_time_format = :gen_server.call(String.to_atom(pid), :get_date_time_format)
{date_time_format, String.to_atom(pid)}
end

@doc """
Expand All @@ -37,4 +37,4 @@ defmodule Weber.I18n do
end
end

end
end
7 changes: 4 additions & 3 deletions lib/weber/i18n/localization/locale.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Weber.Localization.Locale do
use GenServer.Behaviour
use GenServer

defmodule Locale do
defstruct locale: nil
Expand All @@ -10,7 +10,8 @@ defmodule Weber.Localization.Locale do
end

def init([locale]) do
{ :ok, %Locale{locale: ExJSON.parse locale}}
{:ok, parsed_locale} = JSEX.decode locale
{ :ok, %Locale{locale: parsed_locale}}
end

def handle_call(:get_abbr_day_names, _from, state) do
Expand Down Expand Up @@ -39,4 +40,4 @@ defmodule Weber.Localization.Locale do
param
end

end
end
8 changes: 4 additions & 4 deletions lib/weber/i18n/localization_manager.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Weber.Localization.LocalizationManager do

use GenServer.Behaviour
use GenServer

defmodule LocalizationConfig do
defstruct config: nil,
Expand All @@ -25,18 +25,18 @@ defmodule Weber.Localization.LocalizationManager do

default_locale = Keyword.fetch!(localization_config, :default_locale)
use_locales = Keyword.fetch!(localization_config, :use_locales)
|> Enum.map(fn(l) -> atom_to_binary(l) <> ".json" end)
|> Enum.map(fn(l) -> Atom.to_string(l) <> ".json" end)

on_files_in_path(
Path.join([project_path, "/deps/weber/lib/weber/i18n/localization/locale"]),
&( :lists.member(&1, use_locales) ),
&( Weber.Localization.Locale.start_link(binary_to_atom(&1), &2) )
&( Weber.Localization.Locale.start_link(String.to_atom(&1), &2) )
)

on_files_in_path(
Path.join([project_path, "/lang"]),
fn (_) -> true end,
&( Weber.Translation.Translate.start_link(binary_to_atom(&1), &2) )
&( Weber.Translation.Translate.start_link(String.to_atom(&1), &2) )
)

{:noreply, %LocalizationConfig{config: state.config, default_locale: default_locale}}
Expand Down
7 changes: 4 additions & 3 deletions lib/weber/i18n/translation/Translate.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Weber.Translation.Translate do

use GenServer.Behaviour
use GenServer

defmodule Translate do
defstruct t: nil
Expand All @@ -11,7 +11,8 @@ defmodule Weber.Translation.Translate do
end

def init([lang]) do
{ :ok, %Translate{t: ExJSON.parse(lang)}}
{:ok, parsed_lang} = JSEX.decode(lang)
{ :ok, %Translate{t: parsed_lang}}
end

def handle_call({:translate, key}, _from, state) do
Expand All @@ -29,4 +30,4 @@ defmodule Weber.Translation.Translate do
end
end

end
end
4 changes: 2 additions & 2 deletions lib/weber/reload.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Weber.Reload do
use GenServer.Behaviour
use GenServer

defmodule Config do
defstruct root_path: nil, load_modules: [], load_time: { { 1970, 1, 1 }, { 0, 0, 0 } }
Expand Down Expand Up @@ -79,4 +79,4 @@ defmodule Weber.Reload do
end
end

end
end
10 changes: 5 additions & 5 deletions lib/weber/route.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Weber.Route do
fn({type, value}, acc) ->
case type do
:segment -> acc <> "/" <> value
:binding -> acc <> "/" <> to_bin(Keyword.get(bindings, binary_to_atom(value)))
:binding -> acc <> "/" <> to_bin(Keyword.get(bindings, String.to_atom(value)))
end
end)
end
Expand All @@ -51,12 +51,12 @@ defmodule Weber.Route do
"""
def on(method, path, controllerAndAction) when is_binary(controllerAndAction) do
[controller, action] = split(controllerAndAction, "#")
[[method: method, path: path, controller: binary_to_atom(controller), action: binary_to_atom(action)]]
[[method: method, path: path, controller: String.to_atom(controller), action: String.to_atom(action)]]
end

def on(routesList, method, path, controllerAndAction) when is_binary(controllerAndAction) do
[controller, action] = split(controllerAndAction, "#")
:lists.append(routesList, [[method: method, path: path, controller: binary_to_atom(controller), action: binary_to_atom(action)]])
:lists.append(routesList, [[method: method, path: path, controller: String.to_atom(controller), action: String.to_atom(action)]])
end

@doc """
Expand Down Expand Up @@ -160,7 +160,7 @@ defmodule Weber.Route do
end

defp resources_routes(controller) do
url = List.foldl(String.split(atom_to_binary(controller),"."), "",
url = List.foldl(String.split(Atom.to_string(controller),"."), "",
fn (x, acc) ->
case x do
"Elixir" -> acc <> ""
Expand All @@ -185,4 +185,4 @@ defmodule Weber.Route do
list
end

end
end
2 changes: 1 addition & 1 deletion lib/weber/session/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Weber.Session do
Weber session handler. Every process handle one use session.
"""

use GenServer.Behaviour
use GenServer

import Weber.Http.Params

Expand Down
4 changes: 2 additions & 2 deletions lib/weber/session/session_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Weber.Session.SessionManager do
manages all sessions.
"""

use GenServer.Behaviour
use GenServer

defmodule SessionManager do
defstruct config: nil
Expand Down Expand Up @@ -58,4 +58,4 @@ defmodule Weber.Session.SessionManager do
{:noreply, state}
end

end
end
20 changes: 10 additions & 10 deletions lib/weber/utils/time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ defmodule Weber.Time do

# Y
def format_time(<<89, rest :: binary>>, locale_pid, result, datetime = {{year, _, _}, _}) do
format_time(rest, locale_pid, result <> integer_to_binary(year), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(year), datetime)
end

# y
def format_time(<<121, rest :: binary>>, locale_pid, result, datetime = {{year, _, _}, _}) do
format_time(rest, locale_pid, result <> integer_to_binary(year - 2000), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(year - 2000), datetime)
end

# C
def format_time(<<67, rest :: binary>>, locale_pid, result, datetime = {{year, _, _}, _}) do
format_time(rest, locale_pid, result <> integer_to_binary(trunc (year / 100) + 1), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(trunc (year / 100) + 1), datetime)
end

# B
Expand All @@ -72,7 +72,7 @@ defmodule Weber.Time do

# m
def format_time(<<109, rest :: binary>>, locale_pid, result, datetime = {{_, month, _}, _}) do
format_time(rest, locale_pid, result <> integer_to_binary(month), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(month), datetime)
end

# A
Expand All @@ -91,28 +91,28 @@ defmodule Weber.Time do

# d
def format_time(<<100, rest :: binary>>, locale_pid, result, datetime = {{_, _, day}, _}) do
format_time(rest, locale_pid, result <> integer_to_binary(day), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(day), datetime)
end

# w
def format_time(<<119, rest :: binary>>, locale_pid, result, datetime = {date, _}) do
day_num = :calendar.day_of_the_week(date)
format_time(rest, locale_pid, result <> integer_to_binary(day_num), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(day_num), datetime)
end

# H
def format_time(<<72, rest :: binary>>, locale_pid, result, datetime = {_, {hour, _, _}}) do
format_time(rest, locale_pid, result <> integer_to_binary(hour), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(hour), datetime)
end

# M
def format_time(<<77, rest :: binary>>, locale_pid, result, datetime = {_, {_, minute, _}}) do
format_time(rest, locale_pid, result <> integer_to_binary(minute), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(minute), datetime)
end

# S
def format_time(<<83, rest :: binary>>, locale_pid, result, datetime = {_, {_, second, _}}) do
format_time(rest, locale_pid, result <> integer_to_binary(second), datetime)
format_time(rest, locale_pid, result <> Integer.to_string(second), datetime)
end

# '
Expand All @@ -125,4 +125,4 @@ defmodule Weber.Time do
format_time(rest, locale_pid, result <> s, datetime)
end

end
end
11 changes: 5 additions & 6 deletions lib/weber/utils/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ defmodule Weber.Utils do
"""
def get_time() do
{{year, month, day}, {hours, minutes, seconds}} = :calendar.local_time()
integer_to_binary(year) <> "." <> integer_to_binary(month) <> "." <> integer_to_binary(day) <> " " <>
integer_to_binary(hours) <> ":" <> integer_to_binary(minutes) <> ":" <> integer_to_binary(seconds) <> " "
Integer.to_string(year) <> "." <> Integer.to_string(month) <> "." <> Integer.to_string(day) <> " " <>
Integer.to_string(hours) <> ":" <> Integer.to_string(minutes) <> ":" <> Integer.to_string(seconds) <> " "
end

@doc """
Expand All @@ -38,7 +38,7 @@ defmodule Weber.Utils do
end

def find_static_file_path(abs_filenames, filename) do
filter(abs_filenames, &( Path.basename(&1) == String.from_char_data!(filename) ) )
filter(abs_filenames, &( Path.basename(&1) == List.to_string(filename) ) )
end

@doc """
Expand Down Expand Up @@ -79,12 +79,11 @@ defmodule Weber.Utils do
end

def capitalize(str) do
<<c, rest :: binary>> = str
String.capitalize(String.from_char_data([c]) |> elem(1)) <> rest
(str |> String.at(0) |> String.capitalize) <> String.slice(str, 1..-1)
end

def to_bin(val) do
to_string(val)
end

end
end
Loading

0 comments on commit a909146

Please sign in to comment.