├── test ├── test_helper.exs └── ex_form_test.exs ├── .gitignore ├── mix.lock ├── README.md ├── mix.exs ├── config └── config.exs └── lib └── ex_form.ex /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | Pavlov.start 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | erl_crash.dump 4 | *.ez 5 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{"meck": {:hex, :meck, "0.8.2"}, 2 | "pavlov": {:hex, :pavlov, "0.1.2"}} 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ExForm 2 | ====== 3 | 4 | This is a prototype that will be replaced. It will not be supported 5 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule ExForm.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [app: :ex_form, 6 | version: "0.0.1", 7 | elixir: "~> 1.0", 8 | deps: deps] 9 | end 10 | 11 | # Configuration for the OTP application 12 | # 13 | # Type `mix help compile.app` for more information 14 | def application do 15 | [applications: [:logger]] 16 | end 17 | 18 | # Dependencies can be Hex packages: 19 | # 20 | # {:mydep, "~> 0.3.0"} 21 | # 22 | # Or git/path repositories: 23 | # 24 | # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} 25 | # 26 | # Type `mix help deps` for more examples and options 27 | defp deps do 28 | [ 29 | {:xain, github: "smpallen99/xain"}, 30 | {:pavlov, "~> 0.1.2", only: :test}, 31 | ] 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for third- 9 | # party users, it should be done in your mix.exs file. 10 | 11 | # Sample configuration: 12 | # 13 | # config :logger, :console, 14 | # level: :info, 15 | # format: "$date $time [$level] $metadata$message\n", 16 | # metadata: [:user_id] 17 | 18 | # It is also possible to import configuration files, relative to this 19 | # directory. For example, you can emulate configuration per environment 20 | # by uncommenting the line below and defining dev.exs, test.exs and such. 21 | # Configuration from the imported file will override the ones defined 22 | # here (which is why it is important to import them last). 23 | # 24 | # import_config "#{Mix.env}.exs" 25 | -------------------------------------------------------------------------------- /test/ex_form_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ExFormTest do 2 | require Logger 3 | use Pavlov.Case 4 | import Pavlov.Syntax.Expect 5 | use Xain 6 | 7 | defmodule SampleStruct do 8 | defstruct name: "", id: 1, private: "" 9 | end 10 | 11 | def to_eq_s(left, right) do 12 | expect Regex.replace(~r/(^\s*)|(\s+$)|(\n)/m, left, "") |> 13 | to_eq Regex.replace(~r/(^\s*)|(\s+$)|(\n)/m, right, "") 14 | end 15 | 16 | def to_include_list(left, right) do 17 | for item <- right do 18 | expect left |> to_include item 19 | end 20 | end 21 | 22 | it "underscores the module" do 23 | 24 | expect ExForm.underscore(%SampleStruct{}.__struct__) |> to_eq "sample_struct" 25 | end 26 | 27 | it "handles hidden_field" do 28 | sample = %SampleStruct{name: "sample", private: "secret"} 29 | 30 | result = ExForm.form_for(:sample_struct, [url: "/"], fn(f) -> 31 | f |> ExForm.hidden_field(:private, sample.private) 32 | end) 33 | 34 | expect result |> to_include_list ["id=\"new_sample_struct\"", "method=\"post\"", "action=\"/\"", 35 | "type=\"hidden\"", "id=\"sample_struct_private\"", 36 | "name=\"sample_struct[private]\"", "value=\"secret\""] 37 | end 38 | 39 | it "handles hidden_field with model" do 40 | sample = %SampleStruct{name: "sample", private: "secret"} 41 | 42 | result = ExForm.form_for(sample, [url: "/"], fn(f) -> 43 | f |> ExForm.hidden_field(:private) 44 | end) 45 | 46 | expect result |> to_include_list [" 55 | ExForm.input_field(f, :name) 56 | ExForm.submit_field f 57 | end) 58 | 59 | expect result 60 | |> to_include_list [" 70 | ExForm.inputs(f, "Section 1", fn -> 71 | ExForm.input_field(f, :name) 72 | end) 73 | ExForm.inputs(f, fn -> 74 | f |> ExForm.submit_field 75 | end) 76 | end) 77 | expect result 78 | |> to_include_list ["